In the following program there are
- struct
A<int>
template, and - function template
f<I>
havingconst int&
template argument, andA<I>
function argument:
template<int>
struct A {};
template<const int & I>
void f(A<I>) {}
int main() {
const static int a = 0;
f<a>(A<a>{}); // ok in GCC and Clang
f(A<a>{}); // ok in GCC
}
The function can be called explicitly specifying template argument <a>
in GCC and Clang.
But auto-deduction of template argument works only in GCC, while Clang complains:
error: no matching function for call to 'f'
note: candidate template ignored: could not match 'const int' against 'int'
Demo: https://gcc.godbolt.org/z/G86dxh9jo
Which compiler is right here?