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

CTAD: Don't reuse the template parameters of the class in the synthesized deduction guide. #102281

Open
hokein opened this issue Aug 7, 2024 · 1 comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party

Comments

@hokein
Copy link
Collaborator

hokein commented Aug 7, 2024

https://godbolt.org/z/ea8vzaoeP

template <typename T1> struct B {
  B(T1);
};

B b(1);

The AST is:

|-ClassTemplateDecl 0xd400cf0 <<source>:1:1, line:3:1> line:1:31 B
| |-TemplateTypeParmDecl 0xd400b68 <col:11, col:20> col:20 referenced typename depth 0 index 0 T1
...

-FunctionTemplateDecl 0xd401680 <line:1:1, line:2:7> col:3 implicit <deduction guide for B>
| |-TemplateTypeParmDecl 0xd400b68 <line:1:11, col:20> col:20 referenced typename depth 0 index 0 T1
| |

Note that the TemplateTypeParmDecl is the same in the class template decl and deduction guide. We seem to take a shortcurt and reuse the TemplateTypeParmDecl when synthesizing the deduction guide. Instead, we should clone one to make distinct template parameters for the deduction guide.

@hokein hokein added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Aug 7, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 7, 2024

@llvm/issue-subscribers-clang-frontend

Author: Haojian Wu (hokein)

https://godbolt.org/z/ea8vzaoeP
template &lt;typename T1&gt; struct B {
  B(T1);
};

B b(1);

The AST is:

|-ClassTemplateDecl 0xd400cf0 &lt;&lt;source&gt;:1:1, line:3:1&gt; line:1:31 B
| |-TemplateTypeParmDecl 0xd400b68 &lt;col:11, col:20&gt; col:20 referenced typename depth 0 index 0 T1
...

-FunctionTemplateDecl 0xd401680 &lt;line:1:1, line:2:7&gt; col:3 implicit &lt;deduction guide for B&gt;
| |-TemplateTypeParmDecl 0xd400b68 &lt;line:1:11, col:20&gt; col:20 referenced typename depth 0 index 0 T1
| |

Note that the TemplateTypeParmDecl is the same in the class template decl and deduction guide. We seem to take a shortcurt and reuse the TemplateTypeParmDecl when synthesizing the deduction guide. Instead, we should clone one to make distinct template parameters for the deduction guide.

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
Development

No branches or pull requests

3 participants