From b20dcef8a7058dce63ed3f43543162813e61ea95 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Tue, 27 Aug 2019 14:41:39 +0000 Subject: [PATCH] Replace some custom C11 extension warnings with the generic warning. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@370066 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticParseKinds.td | 6 ---- lib/Parse/ParseDecl.cpp | 2 +- lib/Parse/ParseDeclCXX.cpp | 2 +- lib/Parse/ParseExpr.cpp | 5 ++- test/Parser/c11-noreturn.c | 2 +- test/Sema/generic-selection.c | 33 ++++++++++--------- test/Sema/static-assert.c | 36 +++++++++++++-------- 7 files changed, 46 insertions(+), 40 deletions(-) diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index 1aeb8ad0bb..edeab1e98a 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/include/clang/Basic/DiagnosticParseKinds.td @@ -119,8 +119,6 @@ def warn_microsoft_qualifiers_ignored : Warning< "qualifiers after comma in declarator list are ignored">, InGroup; -def ext_c11_generic_selection : Extension< - "generic selections are a C11-specific feature">, InGroup; def err_duplicate_default_assoc : Error< "duplicate default generic association">; def note_previous_default_assoc : Note< @@ -129,8 +127,6 @@ def note_previous_default_assoc : Note< def ext_c11_feature : Extension< "'%0' is a C11 extension">, InGroup; -def ext_c11_noreturn : Extension< - "_Noreturn functions are a C11-specific feature">, InGroup; def err_c11_noreturn_misplaced : Error< "'_Noreturn' keyword must precede function declarator">; @@ -374,8 +370,6 @@ def err_unexpected_token_in_nested_name_spec : Error< "'%0' cannot be a part of nested name specifier; did you mean ':'?">; def err_bool_redeclaration : Error< "redeclaration of C++ built-in type 'bool'">; -def ext_c11_static_assert : Extension< - "_Static_assert is a C11-specific feature">, InGroup; def warn_cxx98_compat_static_assert : Warning< "static_assert declarations are incompatible with C++98">, InGroup, DefaultIgnore; diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 1375409a75..9b3b5c77ff 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -3626,7 +3626,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, } case tok::kw__Noreturn: if (!getLangOpts().C11) - Diag(Loc, diag::ext_c11_noreturn); + Diag(Tok, diag::ext_c11_feature) << Tok.getName(); isInvalid = DS.setFunctionSpecNoreturn(Loc, PrevSpec, DiagID); break; diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 8e69bb2295..cf03ed6379 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -862,7 +862,7 @@ Decl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){ "Not a static_assert declaration"); if (Tok.is(tok::kw__Static_assert) && !getLangOpts().C11) - Diag(Tok, diag::ext_c11_static_assert); + Diag(Tok, diag::ext_c11_feature) << Tok.getName(); if (Tok.is(tok::kw_static_assert)) Diag(Tok, diag::warn_cxx98_compat_static_assert); diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 2eb8ff9a8b..0ced0257c8 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -2733,11 +2733,10 @@ ExprResult Parser::ParseStringLiteralExpression(bool AllowUserDefinedLiteral) { /// \endverbatim ExprResult Parser::ParseGenericSelectionExpression() { assert(Tok.is(tok::kw__Generic) && "_Generic keyword expected"); - SourceLocation KeyLoc = ConsumeToken(); - if (!getLangOpts().C11) - Diag(KeyLoc, diag::ext_c11_generic_selection); + Diag(Tok, diag::ext_c11_feature) << Tok.getName(); + SourceLocation KeyLoc = ConsumeToken(); BalancedDelimiterTracker T(*this, tok::l_paren); if (T.expectAndConsume()) return ExprError(); diff --git a/test/Parser/c11-noreturn.c b/test/Parser/c11-noreturn.c index 9b932abeaf..6666731f29 100644 --- a/test/Parser/c11-noreturn.c +++ b/test/Parser/c11-noreturn.c @@ -15,4 +15,4 @@ _Noreturn int; // expected-error {{'_Noreturn' can only appear on functions}} ex _Noreturn struct S; // expected-error {{'_Noreturn' can only appear on functions}} _Noreturn enum E { e }; // expected-error {{'_Noreturn' can only appear on functions}} -// CHECK-EXT: _Noreturn functions are a C11-specific feature +// CHECK-EXT: '_Noreturn' is a C11 extension diff --git a/test/Sema/generic-selection.c b/test/Sema/generic-selection.c index 9829958305..f083dff8ac 100644 --- a/test/Sema/generic-selection.c +++ b/test/Sema/generic-selection.c @@ -1,40 +1,43 @@ // RUN: %clang_cc1 -std=c11 -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c99 -pedantic -fsyntax-only -verify=expected,ext %s void g(void); void foo(int n) { - (void) _Generic(0, + (void) _Generic(0, // ext-warning {{'_Generic' is a C11 extension}} struct A: 0, // expected-error {{type 'struct A' in generic association incomplete}} void(): 0, // expected-error {{type 'void ()' in generic association not an object type}} int[n]: 0); // expected-error {{type 'int [n]' in generic association is a variably modified type}} - (void) _Generic(0, + (void) _Generic(0, // ext-warning {{'_Generic' is a C11 extension}} void (*)(): 0, // expected-note {{compatible type 'void (*)()' specified here}} void (*)(void): 0); // expected-error {{type 'void (*)(void)' in generic association compatible with previously specified type 'void (*)()'}} - (void) _Generic((void (*)()) 0, // expected-error {{controlling expression type 'void (*)()' compatible with 2 generic association types}} + (void) _Generic((void (*)()) 0, // expected-error {{controlling expression type 'void (*)()' compatible with 2 generic association types}} \ + // ext-warning {{'_Generic' is a C11 extension}} void (*)(int): 0, // expected-note {{compatible type 'void (*)(int)' specified here}} void (*)(void): 0); // expected-note {{compatible type 'void (*)(void)' specified here}} - (void) _Generic(0, // expected-error {{controlling expression type 'int' not compatible with any generic association type}} + (void) _Generic(0, // expected-error {{controlling expression type 'int' not compatible with any generic association type}} \ + // ext-warning {{'_Generic' is a C11 extension}} char: 0, short: 0, long: 0); - int a1[_Generic(0, int: 1, short: 2, float: 3, default: 4) == 1 ? 1 : -1]; - int a2[_Generic(0, default: 1, short: 2, float: 3, int: 4) == 4 ? 1 : -1]; - int a3[_Generic(0L, int: 1, short: 2, float: 3, default: 4) == 4 ? 1 : -1]; - int a4[_Generic(0L, default: 1, short: 2, float: 3, int: 4) == 1 ? 1 : -1]; - int a5[_Generic(0, int: 1, short: 2, float: 3) == 1 ? 1 : -1]; - int a6[_Generic(0, short: 1, float: 2, int: 3) == 3 ? 1 : -1]; + int a1[_Generic(0, int: 1, short: 2, float: 3, default: 4) == 1 ? 1 : -1]; // ext-warning {{'_Generic' is a C11 extension}} + int a2[_Generic(0, default: 1, short: 2, float: 3, int: 4) == 4 ? 1 : -1]; // ext-warning {{'_Generic' is a C11 extension}} + int a3[_Generic(0L, int: 1, short: 2, float: 3, default: 4) == 4 ? 1 : -1]; // ext-warning {{'_Generic' is a C11 extension}} + int a4[_Generic(0L, default: 1, short: 2, float: 3, int: 4) == 1 ? 1 : -1]; // ext-warning {{'_Generic' is a C11 extension}} + int a5[_Generic(0, int: 1, short: 2, float: 3) == 1 ? 1 : -1]; // ext-warning {{'_Generic' is a C11 extension}} + int a6[_Generic(0, short: 1, float: 2, int: 3) == 3 ? 1 : -1]; // ext-warning {{'_Generic' is a C11 extension}} - int a7[_Generic("test", char *: 1, default: 2) == 1 ? 1 : -1]; - int a8[_Generic(g, void (*)(void): 1, default: 2) == 1 ? 1 : -1]; + int a7[_Generic("test", char *: 1, default: 2) == 1 ? 1 : -1]; // ext-warning {{'_Generic' is a C11 extension}} + int a8[_Generic(g, void (*)(void): 1, default: 2) == 1 ? 1 : -1]; // ext-warning {{'_Generic' is a C11 extension}} const int i = 12; - int a9[_Generic(i, int: 1, default: 2) == 1 ? 1 : -1]; + int a9[_Generic(i, int: 1, default: 2) == 1 ? 1 : -1]; // ext-warning {{'_Generic' is a C11 extension}} // This is expected to not trigger any diagnostics because the controlling // expression is not evaluated. - (void)_Generic(*(int *)0, int: 1); + (void)_Generic(*(int *)0, int: 1); // ext-warning {{'_Generic' is a C11 extension}} } int __attribute__((overloadable)) test (int); @@ -42,5 +45,5 @@ double __attribute__((overloadable)) test (double); char testc(char); void PR30201(void) { - _Generic(4, char:testc, default:test)(4); + _Generic(4, char:testc, default:test)(4); // ext-warning {{'_Generic' is a C11 extension}} } diff --git a/test/Sema/static-assert.c b/test/Sema/static-assert.c index e8cfb1fa58..cdb227f825 100644 --- a/test/Sema/static-assert.c +++ b/test/Sema/static-assert.c @@ -1,25 +1,30 @@ // RUN: %clang_cc1 -std=c11 -fsyntax-only -verify %s -// RUN: %clang_cc1 -xc++ -std=c++11 -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c99 -pedantic -fsyntax-only -verify=expected,ext %s +// RUN: %clang_cc1 -xc++ -std=c++11 -pedantic -fsyntax-only -verify=expected,ext %s -_Static_assert("foo", "string is nonzero"); +_Static_assert("foo", "string is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}} #ifndef __cplusplus // expected-error@-2 {{static_assert expression is not an integral constant expression}} #endif -_Static_assert(1, "1 is nonzero"); -_Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} +_Static_assert(1, "1 is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}} +_Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} \ + // ext-warning {{'_Static_assert' is a C11 extension}} void foo(void) { - _Static_assert(1, "1 is nonzero"); - _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} + _Static_assert(1, "1 is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}} + _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} \ + // ext-warning {{'_Static_assert' is a C11 extension}} } -_Static_assert(1, invalid); // expected-error {{expected string literal for diagnostic message in static_assert}} +_Static_assert(1, invalid); // expected-error {{expected string literal for diagnostic message in static_assert}} \ + // ext-warning {{'_Static_assert' is a C11 extension}} struct A { int a; - _Static_assert(1, "1 is nonzero"); - _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} + _Static_assert(1, "1 is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}} + _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} \ + // ext-warning {{'_Static_assert' is a C11 extension}} }; #ifdef __cplusplus @@ -36,7 +41,12 @@ struct A { _Static_assert(sizeof(T1) == sizeof(T2), "type size mismatch"); \ } -typedef UNION(unsigned, struct A) U1; -UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; -typedef UNION(char, short) U3; // expected-error {{static_assert failed due to requirement 'sizeof(char) == sizeof(short)' "type size mismatch"}} -typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} +typedef UNION(unsigned, struct A) U1; // ext-warning 3 {{'_Static_assert' is a C11 extension}} +UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; // ext-warning 3 {{'_Static_assert' is a C11 extension}} +#if defined(__cplusplus) +// ext-warning@-2 {{designated initializers are a C99 feature}} +#endif +typedef UNION(char, short) U3; // expected-error {{static_assert failed due to requirement 'sizeof(char) == sizeof(short)' "type size mismatch"}} \ + // ext-warning 3 {{'_Static_assert' is a C11 extension}} +typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} \ + // ext-warning 3 {{'_Static_assert' is a C11 extension}} -- 2.40.0