Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregate CTAD of parenthesized prvalue fails #64347

Closed
JohelEGP opened this issue Aug 2, 2023 · 3 comments · Fixed by #75779
Closed

Aggregate CTAD of parenthesized prvalue fails #64347

JohelEGP opened this issue Aug 2, 2023 · 3 comments · Fixed by #75779
Assignees
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party

Comments

@JohelEGP
Copy link

JohelEGP commented Aug 2, 2023

See https://compiler-explorer.com/z/xjxWbKTs7.

template<class T> struct X { T x; };
auto x = X(0);
<source>:2:10: error: no viable constructor or deduction guide for deduction of template arguments of 'X'
    2 | auto x = X(0);
      |          ^
<source>:1:26: note: candidate template ignored: could not match 'X<T>' against 'int'
    1 | template<class T> struct X { T x; };
      |                          ^
<source>:1:26: note: candidate function template not viable: requires 0 arguments, but 1 was provided
1 error generated.
Compiler returned: 1
@JohelEGP JohelEGP changed the title Prvalue of parenthesized aggregate CTAD fails Aggregate CTAD of parenthesized prvalue fails Aug 2, 2023
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Aug 2, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Aug 2, 2023

@llvm/issue-subscribers-clang-frontend

@cor3ntin
Copy link
Contributor

cor3ntin commented Aug 3, 2023

@ayzhao @yuanfang-chen

@hokein
Copy link
Collaborator

hokein commented Dec 18, 2023

The CTAD doesn't work for the functional-annotation explicit type conversion, e.g. A(1, 2):

template<typename X, typename Y> struct A { X x; Y y;};

void test() {
   A(1, 2); // clang fails
   new A(1, 2); // clang fails
}

@hokein hokein self-assigned this Dec 18, 2023
@shafik shafik added the confirmed Verified by a second party label Dec 18, 2023
hokein added a commit to hokein/llvm-project that referenced this issue Dec 19, 2023
hokein added a commit that referenced this issue Dec 19, 2023
…l annotation). (#75779)

This fixes #64347.

The CTAD for an aggregate class is missing to handle the explicit type
conversion case, e.g. `TemplateFooClass(1, 2);`. Per C++ expr.type.conv
p1, the deduced type is the return type of the deduction guide selected
by the CTAD for the reminder.

In the deduction implementation
`DeduceTemplateSpecializationFromInitializer`, the parenthesized
express-list case relies on the `ParenListExpr` parameter (default is
nullptr), the AST `ParenListExpr` node is not built for all variant
initializer cases (`BuildCXXTypeConstructorExpr`, `BuildCXXNew` etc),
thus the deduction doesn't perform for these cases. This patch fixes it
by removing the `ParenListExpr` and using the `Inits` instead (which
also simplifies the interface and implementation).
qihangkong pushed a commit to rvgpu/rvgpu-llvm that referenced this issue Apr 23, 2024
…l annotation). (#75779)

This fixes llvm/llvm-project#64347.

The CTAD for an aggregate class is missing to handle the explicit type
conversion case, e.g. `TemplateFooClass(1, 2);`. Per C++ expr.type.conv
p1, the deduced type is the return type of the deduction guide selected
by the CTAD for the reminder.

In the deduction implementation
`DeduceTemplateSpecializationFromInitializer`, the parenthesized
express-list case relies on the `ParenListExpr` parameter (default is
nullptr), the AST `ParenListExpr` node is not built for all variant
initializer cases (`BuildCXXTypeConstructorExpr`, `BuildCXXNew` etc),
thus the deduction doesn't perform for these cases. This patch fixes it
by removing the `ParenListExpr` and using the `Inits` instead (which
also simplifies the interface and implementation).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party
Projects
None yet
6 participants