First example in [basic.lookup.unqual]/3:
int h;
void g();
namespace N {
struct A {};
template <class T> int f(T);
template <class T> int g(T);
template <class T> int h(T);
}
int x = f<N::A>(N::A()); // OK: lookup of f finds nothing, f treated as template name
int y = g<N::A>(N::A()); // OK: lookup of g finds a function, g treated as template name
int z = h<N::A>(N::A()); // error: h< does not begin a template-id
The comments above seem to indicate that the compiler should treat differently the lookups for the names g
and h
above, as if a template-id would not be considered for the name h
. I can't see this difference when I compile this snippet with clang or GCC. What is exactly the difference that the example is trying to convey?
You're looking at the C++20 draft, but testing with a C++17 compiler.
Unqualified template name lookup is a new ADL feature introduced by P0846R0 and adopted into the C++20 draft.
So to try it out, use GCC trunk with -std=c++2a
(link):
error: expected primary-expression before '>' token
12 | int z = h<N::A>(N::A()); // error: h< does not begin a template-id
Granted the exact error message isn't yet perfect, the end result is that the first two lookups succeed.
To compare, notice that the C++17 version of [basic.lookup.unqual]/3 doesn't contain the example you mentioned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With