'Auto-deduction of reference template argument from not-reference type in C++
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?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
