-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
[clang] Support __is_trivially_copyable(int()&)==false
#81298
Conversation
IMHO it would be productive to make a similar change for `typeid`, in `ParseCXXTypeid`, in order to improve Clang's error message for https://godbolt.org/z/oKKWxeYra But that might be better done by adding a new DeclaratorContext specifically for TypeidArg, instead of pretending that the argument to `typeid` is a template argument, because I don't know what else that change might affect. Fixes llvm#77585
@llvm/pr-subscribers-clang Author: Amirreza Ashouri (AMP999) ChangesIMHO it would be productive to make a similar change for Fixes #77585 Full diff: https://github.com/llvm/llvm-project/pull/81298.diff 1 Files Affected:
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index fd262ff31e661a..746a8b2286ac4c 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3899,7 +3899,9 @@ ExprResult Parser::ParseTypeTrait() {
SmallVector<ParsedType, 2> Args;
do {
// Parse the next type.
- TypeResult Ty = ParseTypeName();
+ TypeResult Ty = ParseTypeName(nullptr, getLangOpts().CPlusPlus
+ ? DeclaratorContext::TemplateArg
+ : DeclaratorContext::TypeName);
if (Ty.isInvalid()) {
Parens.skipToEnd();
return ExprError();
@@ -3941,7 +3943,7 @@ ExprResult Parser::ParseArrayTypeTrait() {
if (T.expectAndConsume())
return ExprError();
- TypeResult Ty = ParseTypeName();
+ TypeResult Ty = ParseTypeName(nullptr, DeclaratorContext::TemplateArg);
if (Ty.isInvalid()) {
SkipUntil(tok::comma, StopAtSemi);
SkipUntil(tok::r_paren, StopAtSemi);
|
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.
This would need a release note + I think it needs better testing. @AaronBallman might wish to take a look as well, this is his code ownership.
clang/test/Sema/static-assert.c
Outdated
@@ -57,7 +57,7 @@ UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; // ext-warning 3 {{'_Static_ | |||
typedef UNION(char, short) U3; // expected-error {{static assertion failed due to requirement 'sizeof(char) == sizeof(short)': type size mismatch}} \ | |||
// expected-note{{evaluates to '1 == 2'}} \ | |||
// ext-warning 3 {{'_Static_assert' is a C11 extension}} | |||
typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} \ | |||
typedef UNION(float, 0.5f) U4; // expected-error-re {{{{type name requires a specifier or qualifier|expected a type}}}} \ |
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.
This test doesn't seem right... why is there an 'or' here?
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 there's an 'or' because the RUN lines run this in both C and C++ mode, so you get different diagnostics. A better way to express that is with a different -verify
prefix on the RUN lines so that you can do something like cpp-error {{blah}}
and c-error {{blah}}
to make it more clear what's happening.
clang/lib/Parse/ParseExprCXX.cpp
Outdated
@@ -3899,7 +3899,9 @@ ExprResult Parser::ParseTypeTrait() { | |||
SmallVector<ParsedType, 2> Args; | |||
do { | |||
// Parse the next type. | |||
TypeResult Ty = ParseTypeName(); | |||
TypeResult Ty = ParseTypeName(nullptr, getLangOpts().CPlusPlus |
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.
TypeResult Ty = ParseTypeName(nullptr, getLangOpts().CPlusPlus | |
TypeResult Ty = ParseTypeName(/*SourceRange=*/nullptr, getLangOpts().CPlusPlus |
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.
This is going to need additional tests (ie a test for __is_trivially_copyable(int()&)
would be a good start!)
clang/lib/Parse/ParseExprCXX.cpp
Outdated
@@ -3941,7 +3943,7 @@ ExprResult Parser::ParseArrayTypeTrait() { | |||
if (T.expectAndConsume()) | |||
return ExprError(); | |||
|
|||
TypeResult Ty = ParseTypeName(); | |||
TypeResult Ty = ParseTypeName(nullptr, DeclaratorContext::TemplateArg); |
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.
TypeResult Ty = ParseTypeName(nullptr, DeclaratorContext::TemplateArg); | |
TypeResult Ty = ParseTypeName(/*SourceRange=*/nullptr, DeclaratorContext::TemplateArg); |
@cor3ntin I've reflected your suggestions in the code. Could you help me to land this PR, if it looks good to you? |
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.
LGTM
…for abominable types With the llvm#81298 being approved, as soon as it gets merged into the `main` branch, we can completely remove the `has_unique_object_representations` struct and use the builtin instead.
Hey folks, Because of this change the error message for certain type traits changed.
Earlier the error message was: Ref: https://godbolt.org/z/d4884bYz3 I personally feel the previous error made more sense for this case as the type name is missing in the type trait call. If the type name is present but the qualifier or specifier are not present then only the new message makes sense. What do you think, is it a regression or correct behaviour? |
I think the former diagnostic is more clear. It seems the issue is around here: llvm-project/clang/lib/Parse/ParseDecl.cpp Line 2828 in d7975c9
We changed the |
@AaronBallman precisely! @AMP999 do you have thoughts about how we can fix this issue? |
Filed this issue: #86997 |
I don't know, but it seems to me that ideally the |
IMHO it would be productive to make a similar change for
typeid
, inParseCXXTypeid
, in order to improve Clang's error message for https://godbolt.org/z/oKKWxeYraBut that might be better done by adding a new DeclaratorContext specifically for TypeidArg, instead of pretending that the argument to
typeid
is a template argument, because I don't know what else that change might affect.Fixes #77585