llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Clang] Missing default template argument in synthesized guides during CTAD for alias template

Open MagentaTreehouse opened this issue 1 year ago • 2 comments

template <class T, auto = 0>
struct A {
    A(T) {}
};

template <class T, class U>
using Foo = A<T, U{}>;

template <class T, class U = int>
using Bar = Foo<T, U>;

Bar a{0};

Output:

<source>:12:5: error: no viable constructor or deduction guide for deduction of template arguments of 'Bar'
   12 | Bar a{0};
      |     ^
<source>:10:1: note: candidate template ignored: couldn't infer template argument 'U'
   10 | using Bar = Foo<T, U>;
      | ^
<source>:10:1: note: implicit deduction guide declared as 'template <class T, class U> requires __is_deducible(Foo, A<T, U{}>) && __is_deducible(Bar, A<T, U{}>) Bar(T) -> A<T, U{}>'
<source>:10:1: note: candidate template ignored: could not match 'A<T, U{}>' against 'int'
<source>:10:1: note: implicit deduction guide declared as 'template <class T, class U> requires __is_deducible(Foo, A<T, U{}>) && __is_deducible(Bar, A<T, U{}>) Bar(A<T, U{}>) -> A<T, U{}>'

See https://compiler-explorer.com/z/vcjc1qEfv. See also #133132.

MagentaTreehouse avatar Oct 20 '25 14:10 MagentaTreehouse

@llvm/issue-subscribers-clang-frontend

Author: None (MagentaTreehouse)

```c++ template <class T, auto = 0> struct A { A(T) {} };

template <class T, class U> using Foo = A<T, U{}>;

template <class T, class U = int> using Bar = Foo<T, U>;

Bar a{0};

Output:
```console
&lt;source&gt;:12:5: error: no viable constructor or deduction guide for deduction of template arguments of 'Bar'
   12 | Bar a{0};
      |     ^
&lt;source&gt;:10:1: note: candidate template ignored: couldn't infer template argument 'U'
   10 | using Bar = Foo&lt;T, U&gt;;
      | ^
&lt;source&gt;:10:1: note: implicit deduction guide declared as 'template &lt;class T, class U&gt; requires __is_deducible(Foo, A&lt;T, U{}&gt;) &amp;&amp; __is_deducible(Bar, A&lt;T, U{}&gt;) Bar(T) -&gt; A&lt;T, U{}&gt;'
&lt;source&gt;:10:1: note: candidate template ignored: could not match 'A&lt;T, U{}&gt;' against 'int'
&lt;source&gt;:10:1: note: implicit deduction guide declared as 'template &lt;class T, class U&gt; requires __is_deducible(Foo, A&lt;T, U{}&gt;) &amp;&amp; __is_deducible(Bar, A&lt;T, U{}&gt;) Bar(A&lt;T, U{}&gt;) -&gt; A&lt;T, U{}&gt;'

See https://compiler-explorer.com/z/vcjc1qEfv. See also #133132.

llvmbot avatar Oct 20 '25 14:10 llvmbot

Reduced a bit:

template <auto>
struct A {};

template <class U>
using Foo = A<U{}>;

template <class U = int>
using Bar = Foo<U>;

Bar a{};

Output:

<source>:10:5: error: no viable constructor or deduction guide for deduction of template arguments of 'Bar'
   10 | Bar a{};
      |     ^
<source>:8:1: note: candidate template ignored: couldn't infer template argument 'U'
    8 | using Bar = Foo<U>;
      | ^
<source>:8:1: note: implicit deduction guide declared as 'template <class U> requires __is_deducible(Foo, A<U{}>) && __is_deducible(Bar, A<U{}>) Bar() -> A<U{}>'
<source>:8:1: note: candidate function template not viable: requires 1 argument, but 0 were provided
    2 | struct A {};
      |        ~
    3 | 
    4 | template <class U>
    5 | using Foo = A<U{}>;
    6 | 
    7 | template <class U = int>
    8 | using Bar = Foo<U>;
      | ^
<source>:8:1: note: implicit deduction guide declared as 'template <class U> requires __is_deducible(Foo, A<U{}>) && __is_deducible(Bar, A<U{}>) Bar(A<U{}>) -> A<U{}>'
1 error generated.

MagentaTreehouse avatar Mar 19 '26 15:03 MagentaTreehouse