-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang] Fix the local parameter of void type inside the Requires expression.
#109831
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
Changes from 2 commits
9c112e7
8206940
7af1afb
590727f
a2b0e45
fe609a4
2468551
c9c15de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // RUN: %clang -fsyntax-only -std=c++2a -Xclang -verify %s | ||
|
||
|
|
||
| namespace GH109538 { | ||
| static_assert(requires(void *t) { t; }); | ||
| static_assert(requires(void) { 42; }); | ||
| static_assert(requires(void t) { // expected-error {{argument may not have 'void' type}} | ||
| t; | ||
| }); | ||
| static_assert(requires(void t, int a) { // expected-error {{'void' must be the first and only parameter if specified}} | ||
| t; | ||
| }); | ||
| static_assert(requires(const void) { // expected-error {{'void' as parameter must not have type qualifiers}} | ||
| 42; | ||
| }); | ||
| } // namespace GH109538 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we unify these with the parameter type checks in SemaType?
Also, it would make sense to perform the same error recovery here, which is to just adjust these parameter types
to
int, or perhaps some other error recovery, but consistently between requires local parameters and function parameters.I don't think it's helpful to mark the requires body as invalid, but in some scenarios we can mark the parameter itself as invalid, if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you suggesting unifying the parameter type check for void type only or for all parameters? As I understand it, the complete parameter check involves a lot more branches, such as support for objc, opencl, etc. It appears challenging to merge these two aspects seamlessly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the invalidity of the Decl should be used to indicate the "unsatisfied" flag such that the constant expression would result in a false value. That said, marking the parameters as invalid should also work.
Note that we don't seem ever to use the invalid flag. I think you need to examine that flag in
RequiresExpr's constructor.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. The required expression will now evaluate to false if it has an incorrect void parameter now.