https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108788
Bug ID: 108788 Summary: Lookup of injected class name should be type-dependent Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: m.cencora at gmail dot com Target Milestone: --- 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{});