Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure to match alias template against template template parameter #65843

Open
ecatmur opened this issue Sep 9, 2023 · 5 comments
Open

Failure to match alias template against template template parameter #65843

ecatmur opened this issue Sep 9, 2023 · 5 comments
Labels
c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid

Comments

@ecatmur
Copy link

ecatmur commented Sep 9, 2023

template<template<class T> class> struct A {};
template<class T> struct Q {};
template<class T> using R = Q<T>;
int f(A<R>);
int g(A<Q> a) { return f(a); }

GCC accepts (since 4.9.0), Clang rejects with:

<source>:5:24: error: no matching function for call to 'f'
int g(A<Q> a) { return f(a); }
                       ^
<source>:4:5: note: candidate function not viable: no known conversion from 'A<template Q>' to 'A<template R>' for 1st argument
int f(A<R>);
    ^

-frelaxed-template-template-args doesn't seem to help in any recent major.

@cor3ntin cor3ntin added c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid and removed new issue labels Sep 9, 2023
@llvmbot
Copy link
Member

llvmbot commented Sep 9, 2023

@llvm/issue-subscribers-c-1

@llvmbot
Copy link
Member

llvmbot commented Sep 9, 2023

@llvm/issue-subscribers-clang-frontend

@shafik
Copy link
Collaborator

shafik commented Sep 9, 2023

gcc is the only implementation that accepts it: https://godbolt.org/z/v9Trvovza

Can you explain why you expect this to be valid?

@ecatmur
Copy link
Author

ecatmur commented Sep 11, 2023

I think this is CWG 1286. It looks like we haven't got a resolution in yet, but the intent seems clear that it should be accepted.

@jakub-homola
Copy link

Stumbled upon the same issue today.

For anyone looking for a workaround, this is one of the ways that worked for me (assuming that Q does not have weird specializations, testing only for one, char):

#include <type_traits>

template<template<class T> class> struct A {};
template<class T> struct Q {};
template<class T> using R = Q<T>;

template<template<class> class U>
int f(A<U>)
{
    static_assert(std::is_same_v<U<char>,R<char>>);
    return 42;
}

int g(A<Q> a) { return f(a); }

or a series of if constexprs if f needs to be "overloaded" for multiple Us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid
Projects
None yet
Development

No branches or pull requests

5 participants