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

improve the AST for the synthesized deduction guide #79798

Closed
hokein opened this issue Jan 29, 2024 · 1 comment · Fixed by #99840
Closed

improve the AST for the synthesized deduction guide #79798

hokein opened this issue Jan 29, 2024 · 1 comment · Fixed by #99840
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@hokein
Copy link
Collaborator

hokein commented Jan 29, 2024

Given the following CTAD code:

template <typename T>
struct C {
    template <typename U>
    C(U);
};
C c(1);

The synthesized deduction guide from the constructor is:

|-FunctionTemplateDecl  implicit <deduction guide for C>
| |-TemplateTypeParmDecl <line:1:11, col:20> col:20 typename depth 0 index 0 T
| |-TemplateTypeParmDecl <line:3:15, col:24> col:24 typename depth 0 index 1 U
| `-CXXDeductionGuideDecl <line:4:5, col:8> col:5 implicit <deduction guide for C> 'auto (type-parameter-0-1) -> C<T>'
|   `-ParmVarDecl 0x555d18fe4638 <col:7> col:8 'type-parameter-0-1'

Note that the function parameter type is canonicalized to type-parameter-0-1, this is suboptimal. I think it is better to show a normal U.

@hokein hokein added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Jan 29, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 29, 2024

@llvm/issue-subscribers-clang-frontend

Author: Haojian Wu (hokein)

Given the following CTAD code:
template &lt;typename T&gt;
struct C {
    template &lt;typename U&gt;
    C(U);
};
C c(1);

The synthesized deduction guide from the constructor is:

|-FunctionTemplateDecl  implicit &lt;deduction guide for C&gt;
| |-TemplateTypeParmDecl &lt;line:1:11, col:20&gt; col:20 typename depth 0 index 0 T
| |-TemplateTypeParmDecl &lt;line:3:15, col:24&gt; col:24 typename depth 0 index 1 U
| `-CXXDeductionGuideDecl &lt;line:4:5, col:8&gt; col:5 implicit &lt;deduction guide for C&gt; 'auto (type-parameter-0-1) -&gt; C&lt;T&gt;'
|   `-ParmVarDecl 0x555d18fe4638 &lt;col:7&gt; col:8 'type-parameter-0-1'

Note that the function parameter type is canonicalized to type-parameter-0-1, this is suboptimal. I think it is better to show a normal U.

zyn0217 added a commit that referenced this issue Jul 22, 2024
… CTAD guides (#99840)

This seems to be low-hanging fruit: We could remove all calls to
`Context.getCanonicalTemplateArgument()` and gain a better
diagnostic/AST.

The non-canonical template arguments shouldn't make a difference when
synthesizing a CTAD guide, so this is intended to be an NFC.

Closes #79798
sgundapa pushed a commit to sgundapa/upstream_effort that referenced this issue Jul 23, 2024
… CTAD guides (llvm#99840)

This seems to be low-hanging fruit: We could remove all calls to
`Context.getCanonicalTemplateArgument()` and gain a better
diagnostic/AST.

The non-canonical template arguments shouldn't make a difference when
synthesizing a CTAD guide, so this is intended to be an NFC.

Closes llvm#79798
yuxuanchen1997 pushed a commit that referenced this issue Jul 25, 2024
… CTAD guides (#99840)

This seems to be low-hanging fruit: We could remove all calls to
`Context.getCanonicalTemplateArgument()` and gain a better
diagnostic/AST.

The non-canonical template arguments shouldn't make a difference when
synthesizing a CTAD guide, so this is intended to be an NFC.

Closes #79798
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"
Projects
None yet
2 participants