Skip to content

[clang][concepts] Clang doesn't properly diagnose concept return types with insufficient template arg count #138889

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

Open
erichkeane opened this issue May 7, 2025 · 3 comments
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts confirmed Verified by a second party

Comments

@erichkeane
Copy link
Collaborator

Given:

template<typename T> concept C = true;

We properly diagnose:

void foo(C<int> auto);

as:
<source>:7:10: error: too many template arguments for concept 'C'

This happens as a part of the call to InventTemplateParameter.

However, we don't do the same for return types or trailing return types:

C<int> auto Foo();
auto Foo2() -> C<int> auto;

Should both diagnose, in Block, File, or Record scope.

However, calls to the InventTemplateParameter all need the InventedParameterInfos to have something in it, which it obviously doesn't, since there are no parameters to be filled in. Likely we need to do something similar with return types, though it isn't clear where that could come from.

@zygoloid did something similar in https://github.com/llvm/llvm-project/commit/9cf98d26e7b1204478cc13ae3df44a6843965c11 for trailing return types, but only applied it to inside a lambda or prototype context, and not File/Block/Record context, so it is incomplete.

@erichkeane erichkeane added concepts C++20 concepts c++20 labels May 7, 2025
@llvmbot
Copy link
Member

llvmbot commented May 7, 2025

@llvm/issue-subscribers-c-20

Author: Erich Keane (erichkeane)

Given:
template&lt;typename T&gt; concept C = true;

We properly diagnose:

void foo(C&lt;int&gt; auto);

as:
&lt;source&gt;:7:10: error: too many template arguments for concept 'C'

This happens as a part of the call to InventTemplateParameter.

However, we don't do the same for return types or trailing return types:

C&lt;int&gt; auto Foo();
auto Foo2() -&gt; C&lt;int&gt; auto;

Should both diagnose, in Block, File, or Record scope.

However, calls to the InventTemplateParameter all need the InventedParameterInfos to have something in it, which it obviously doesn't, since there are no parameters to be filled in. Likely we need to do something similar with return types, though it isn't clear where that could come from.

@zygoloid did something similar in https://github.com/llvm/llvm-project/commit/9cf98d26e7b1204478cc13ae3df44a6843965c11 for trailing return types, but only applied it to inside a lambda or prototype context, and not File/Block/Record context, so it is incomplete.

@EugeneZelenko EugeneZelenko added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label May 7, 2025
@llvmbot
Copy link
Member

llvmbot commented May 7, 2025

@llvm/issue-subscribers-clang-frontend

Author: Erich Keane (erichkeane)

Given:
template&lt;typename T&gt; concept C = true;

We properly diagnose:

void foo(C&lt;int&gt; auto);

as:
&lt;source&gt;:7:10: error: too many template arguments for concept 'C'

This happens as a part of the call to InventTemplateParameter.

However, we don't do the same for return types or trailing return types:

C&lt;int&gt; auto Foo();
auto Foo2() -&gt; C&lt;int&gt; auto;

Should both diagnose, in Block, File, or Record scope.

However, calls to the InventTemplateParameter all need the InventedParameterInfos to have something in it, which it obviously doesn't, since there are no parameters to be filled in. Likely we need to do something similar with return types, though it isn't clear where that could come from.

@zygoloid did something similar in https://github.com/llvm/llvm-project/commit/9cf98d26e7b1204478cc13ae3df44a6843965c11 for trailing return types, but only applied it to inside a lambda or prototype context, and not File/Block/Record context, so it is incomplete.

@shafik
Copy link
Collaborator

shafik commented May 8, 2025

Interesting MSVC catches none of them: https://godbolt.org/z/s3PfxWz43

@shafik shafik added the confirmed Verified by a second party label May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts confirmed Verified by a second party
Projects
None yet
Development

No branches or pull requests

4 participants