Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First example in [basic.lookup.unqual]/3

Tags:

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 habove, 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?

like image 356
WaldB Avatar asked Feb 10 '19 18:02

WaldB


1 Answers

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.

like image 168
rustyx Avatar answered Sep 22 '22 08:09

rustyx