Skip to content

Commit 690bf64

Browse files
authored
[clang] Support __is_trivially_copyable(int()&)==false (#81298)
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 #77585
1 parent d773c00 commit 690bf64

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ Bug Fixes to C++ Support
265265
- Fix a crash when trying to call a varargs function that also has an explicit object parameter. (#GH80971)
266266
- Fixed a bug where abbreviated function templates would append their invented template parameters to
267267
an empty template parameter lists.
268+
- Fix parsing of abominable function types inside type traits.
269+
Fixes (`#77585 <https://github.com/llvm/llvm-project/issues/77585>`_)
268270
- Clang now classifies aggregate initialization in C++17 and newer as constant
269271
or non-constant more accurately. Previously, only a subset of the initializer
270272
elements were considered, misclassifying some initializers as constant. Partially fixes

clang/lib/Parse/ParseExprCXX.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3908,7 +3908,10 @@ ExprResult Parser::ParseTypeTrait() {
39083908
SmallVector<ParsedType, 2> Args;
39093909
do {
39103910
// Parse the next type.
3911-
TypeResult Ty = ParseTypeName();
3911+
TypeResult Ty =
3912+
ParseTypeName(/*SourceRange=*/nullptr,
3913+
getLangOpts().CPlusPlus ? DeclaratorContext::TemplateArg
3914+
: DeclaratorContext::TypeName);
39123915
if (Ty.isInvalid()) {
39133916
Parens.skipToEnd();
39143917
return ExprError();
@@ -3950,7 +3953,8 @@ ExprResult Parser::ParseArrayTypeTrait() {
39503953
if (T.expectAndConsume())
39513954
return ExprError();
39523955

3953-
TypeResult Ty = ParseTypeName();
3956+
TypeResult Ty =
3957+
ParseTypeName(/*SourceRange=*/nullptr, DeclaratorContext::TemplateArg);
39543958
if (Ty.isInvalid()) {
39553959
SkipUntil(tok::comma, StopAtSemi);
39563960
SkipUntil(tok::r_paren, StopAtSemi);

clang/test/Sema/static-assert.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: %clang_cc1 -std=c11 -Wgnu-folding-constant -fsyntax-only -verify %s
2-
// RUN: %clang_cc1 -fms-compatibility -Wgnu-folding-constant -DMS -fsyntax-only -verify=expected,ms %s
3-
// RUN: %clang_cc1 -std=c99 -pedantic -Wgnu-folding-constant -fsyntax-only -verify=expected,ext %s
1+
// RUN: %clang_cc1 -std=c11 -Wgnu-folding-constant -fsyntax-only -verify=expected,c %s
2+
// RUN: %clang_cc1 -fms-compatibility -Wgnu-folding-constant -DMS -fsyntax-only -verify=expected,ms,c %s
3+
// RUN: %clang_cc1 -std=c99 -pedantic -Wgnu-folding-constant -fsyntax-only -verify=expected,ext,c %s
44
// RUN: %clang_cc1 -xc++ -std=c++11 -pedantic -fsyntax-only -verify=expected,ext,cxx %s
55

66
_Static_assert("foo", "string is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}}
@@ -57,7 +57,8 @@ UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; // ext-warning 3 {{'_Static_
5757
typedef UNION(char, short) U3; // expected-error {{static assertion failed due to requirement 'sizeof(char) == sizeof(short)': type size mismatch}} \
5858
// expected-note{{evaluates to '1 == 2'}} \
5959
// ext-warning 3 {{'_Static_assert' is a C11 extension}}
60-
typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} \
60+
typedef UNION(float, 0.5f) U4; // c-error {{expected a type}} \
61+
// cxx-error {{type name requires a specifier or qualifier}} \
6162
// ext-warning 3 {{'_Static_assert' is a C11 extension}}
6263

6364
// After defining the assert macro in MS-compatibility mode, we should

clang/test/SemaCXX/type-traits-nonobject.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
static_assert(!__is_pod(void), "");
77
static_assert(!__is_pod(int&), "");
88
static_assert(!__is_pod(int()), "");
9+
static_assert(!__is_pod(int()&), "");
910

1011
static_assert(!__is_trivially_copyable(void), "");
1112
static_assert(!__is_trivially_copyable(int&), "");
1213
static_assert(!__is_trivially_copyable(int()), "");
14+
static_assert(!__is_trivially_copyable(int()&), "");
1315

1416
static_assert(!__is_trivially_relocatable(void), "");
1517
static_assert(!__is_trivially_relocatable(int&), "");
1618
static_assert(!__is_trivially_relocatable(int()), "");
19+
static_assert(!__is_trivially_relocatable(int()&), "");

0 commit comments

Comments
 (0)