https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111423
Bug ID: 111423 Summary: bogus Wsubobject-linkage when using CRTP with an invisible base, template template parameters, and concepts Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: brunopitrus at hotmail dot com Target Milestone: --- header.h: ``` template <typename T> concept bar = requires(const T& t) { { t.GetA() }; }; template <template<typename> typename T> struct Derived : T<Derived<T>>{}; ``` main.cpp: ``` #include "header.h" namespace { template<typename Derived> struct Base2 { void GetA() const {} }; using B2 = Derived<Base2>; static_assert(bar<B2>); } ``` This code makes GCC complain with ``` In file included from /app/main.cpp:1: header.h: In instantiation of 'struct Derived<{anonymous}::Base2>': /app/header.h:3:7: required from here /app/header.h:7:8: error: 'Derived<{anonymous}::Base2>' has a base '{anonymous}::Base2<Derived<{anonymous}::Base2> >' which uses the anonymous namespace [-Werror=subobject-linkage] 7 | struct Derived : T<Derived<T>>{}; | ^~~~~~~ ``` which is incorrect — `Derived<{anonymous}::Base2>` should have internal linkage due to it being dependent on the internal-linkage `{anonymous}::Base2` — therefore it should not matter what linkage its bases have. See it on Godbolt: https://godbolt.org/z/q7jb5bGb6