https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121080
Bug ID: 121080 Summary: GCC seems to bypass the alias template CTAD deduction guides if the template-id is simple enough Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: zyn7109 at gmail dot com Target Milestone: --- (The example comes from Clang's bug reports, for which GCC seems to behave different with the other 3 compilers https://godbolt.org/z/64Me6T4dn and hence the bug report) Consider the following example ``` template <class T> struct traits { using type = T; }; template <class Key1, class U1 = Key1> class unordered_set { public: template <class T> unordered_set(T) {} }; template <class Undeduced, class U = Undeduced> unordered_set(Undeduced, U = U()) -> unordered_set<typename traits<Undeduced>::type, U>; // #2 template <class Key2, class U2 = Key2> using my_unordered_set = unordered_set<Key2, U2>; // #1 my_unordered_set s(0); // #3 ``` To deduce the type of s, one should synthesize a CTAD guide from #1; and one of the deduction guide that is synthesized against #2 is formed in ways like 1. We deduce #2's <Undeduced, U> against <typename traits<Undeduced>::type, U> using #1's <Key2, U2> 2. U can be deduced as U2, Undeduced cannot be deduced because of non-deduced context, and since U2 has a default argument, the synthesized deduction guide ends up like template <class Key2, class U2 = Key2, class Undeduced> // is_deducible constriant is omitted unordered_set(Undeduced, U2 = U2()) -> unordered_set<typename traits<Undeduced>::type, U2>; >From which we could see that Key2 cannot be deduced, so at least this deduction guide shouldn't help us compile #3. However, GCC seems to compile #3 without going through such transform, as can be seen at https://godbolt.org/z/esP7K4fP1 If we somehow make #1 a bit complicated, e.g. if we write template <class Key2, class U2 = Key2> using my_unordered_set = unordered_set<typename traits<Key2>::type, U2>; then GCC rejects such as well, in the way I wrote above. Is the behavior conforming?