https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121265

            Bug ID: 121265
           Summary: CTAD for alias templates
           Product: gcc
           Version: 15.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rohamamini at gmail dot com
  Target Milestone: ---

#include <type_traits>

template <typename T, typename U = double>
struct Q1
{
    T dm1;
    U dm2;
};

template <typename T, typename U>
Q1(T, U) -> Q1<T, U>;           // f

template <typename X>
using Q1Alias = Q1<X>;          // A = B<Arglist>

/*
1) deduce 'Q1<T, U>' from 'Q1<X>'. T = X, U = not deduced

2) Q1(X, U) -> Q1<X, U>;        // g

3) template <typename X, typename U>
   requires(__is_deducible<Q1<X, U>>)
   Q1Alias(X, U) -> Q1<X, U>;   // f'

template <typename X>
class AA;

template <typename X>
class AA<Q1Alias<X>> {};    // equivalent to class AA<Q1<X, double>>

template <typename T>
concept __is_deducible = requires { sizeof(AA<T>); };
*/

int main()
{
    [[maybe_unused]]auto q1 = Q1Alias(1, 'x');  // i believe should be error

    [[maybe_unused]]auto q2 = Q1Alias(1, 2.0);  // ok
}

This code compiles with x86‑64 GCC trunk and 15.1 using -std=c++20/23 -Wall
-Wextra, but it fails to compile with x86‑64 Clang trunk. I believe Clang is
correct to reject it, because—as cppreference.com states—“the associated
constraints of f' are the conjunction of the associated constraints of g and a
constraint that is satisfied if and only if the arguments of A are deducible
from the result type,” and in this case those constraints are not met (the
template arguments of the specialization AA<Q1<int, char>> do not match the
template arguments of the partial specialization AA<Q1<X, double>>).

link to godbolt: https://godbolt.org/z/9KqY39bPd

Reply via email to