CTAD is not working for class that didn’t declare any constructor

Dear Clang Team,


It seems that CTAD is not working for class that didn’t declare any constructor.
(For your information, please see this PDF on CTAD:

Please correct me if I am wrong.

As per ‘Implicitly generated deduction guides’ if a template class, say C, that does not declare any constructors, an additional fictional function template is added, derived, as mentioned below, from a hypothetical constructor C()
When, in a function-style cast or in a variable’s declaration, the type specifier consists solely of the name of a primary class template C (i.e., there is no accompanying template argument list), candidates for deduction are formed as follows:
 If C is defined, for each constructor (or constructor template) Ci declared in the named primary template, a fictional function template Fi, is constructed, such that
 template parameters of Fi are the template parameters of C followed (if Ci is a constructor template) by the template parameters of Ci (default template arguments are included too)
 the function parameters of Fi are the constructor parameters
 the return type of Fi is C followed by the template parameters of the class template enclosed in <>

Here is an example of ‘CTAD’ that is failing in out codebase: (example simplified for our discussion)
Say file ‘Init.cpp’ has following template class declaration and its invocation!

struct Point {
T x;
T y;

int main()
Point xy1 {1, 2};

    return 0;

When we compile above ‘Init.cpp’ file using clang++ with -std=c++20, it fails:

clang++ -std=c++20 Init.cpp
Init.cpp:43:8: error: no viable constructor or deduction guide for deduction of template arguments of ‘Point’
Point xy1 {1, 2};
Init.cpp:17:8: note: candidate function template not viable: requires 1 argument, but 2 were provided
struct Point {
Init.cpp:17:8: note: candidate function template not viable: requires 0 arguments, but 2 were provided
1 error generated.

Please note, this case is specific to template class that does not declare any constructors.

Please comment. And please let us know when this feature will be available, if not already.
Here is the clang version information that we are using:
clang++ --version
Ubuntu clang version 15.0.4-++20221102053248+5c68a1cb1231-1~exp1~20221102053256.89
Target: x86_64-pc-linux-gnu
Thread model: posix

Thank you in anticipation.

Best Regards,

CTAD for aggregates is a c++20 feature that hasn’t been implemented yet

1 Like

Any idea when this will be implemented. Soon c++23 will be in released (as per schedule it should already be)

That’s the tickets - Clang C++20 Feature: P2082R1 - Fixing CTAD for aggregates · Issue #54050 · llvm/llvm-project · GitHub, Clang C++20 Feature: P1814R0 - Wording for Class Template Argument Deduction for Alias Templates · Issue #54051 · llvm/llvm-project · GitHub

I don’t know if there’s been progress since the comments there.