Following code fails to compile on any gcc version. Works on all clang versions. It looks like inside template function get_templ_base the lookup of v.templ_base::a is done eagerly, and finds templ_base at the global scope, and hence errors out because the template parameters are missing. But at this point qualified name "templ_base::a" should be type-dependent, so lookup should be delayed until template instantiation, where 'templ_base' is an injected class name, so template paremeters shouldn't be required. g++ -std=c++11 struct base { int a = 1; }; template <typename T> struct templ_base { int a = 2; }; namespace bar { struct base2 { int a = 3; }; template <typename T> struct templ_base2 { int a = 4; }; } struct foo : base, bar::templ_base2<char>, templ_base<int>, bar::base2 { int base = 5; int templ_base = 6; int base2 = 7; int templ_base2 = 8; int a = 9; }; static_assert(foo{}.base::a == 1, ""); static_assert(foo{}.templ_base::a == 2, ""); static_assert(foo{}.base2::a == 3, ""); static_assert(foo{}.templ_base2::a == 4, ""); template <typename T> int get_base(T&& v) { return v.base::a; } template <typename T> int get_templ_base(T&& v) { return v.templ_base::a; // fails in all gcc versions } template <typename T> int get_base2(T&& v) { return v.base2::a; // fails for gcc <= 11 } template <typename T> int get_templ_base2(T&& v) { return v.templ_base2::a; // fails for gcc <= 11 } int a = get_base(foo{}); int b = get_templ_base(foo{}); int c = get_base2(foo{}); int d = get_templ_base2(foo{});
I suspect this is related to the C++ paper: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1787r6.html
Partially fixed by r12-3643-g18b57c1d4a8777. Reduced version of what we still reject: template <typename T> struct templ_base { }; template <typename T> int get_templ_base(T&& v) { return v.templ_base::a; // fails in all gcc versions } <stdin>: In function ‘int get_templ_base(T&&)’: <stdin>:7:14: error: ‘template<class T> struct templ_base’ used without template arguments