I have following C++ code:
template <typename Type, typename T>
class zz
{
};
class foo
{
template <typename T>
using zz = ::zz<foo, T>;
struct own_type : zz<double>
{
own_type():
zz<foo, double>{} {} // ERROR: needs foo arg !!
};
template <typename T>
struct zz_type_gen : zz<T>
{
zz_type_gen():
zz<T>() {}
};
zz<int> _oi;
zz_type_gen<char> _od;
};
Compiling with g++ 11, clang++ 12 and cl.exe with -std=c++20 works fine but if foo template argument is removed in line with // ERROR comment compilation fails.
This seems to indicate that zz
name is looked up first in global namespace inside nested class in case nested class (own_type
) is not template. However zz
name is looked up first in class foo
in case nested class is template (zz_type_gen
).
I could not find clear explanation on how C++ names lookup works, but intuitively this seems inconsistent.