diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 871c434d67ee..3d72bf8f6521 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -52,7 +52,9 @@ Bug Fixes - ``-Wtautological-compare`` missed warnings for tautological comparisons involving a negative integer literal. This fixes `Issue 42918 `_. - +- Fixes an accepts-invalid bug in C when using a ``_Noreturn`` function + specifier on something other than a function declaration. This fixes + `Issue 56800 `_. Improvements to Clang's diagnostics ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index aef9909a7c97..fa19c6a0cbfa 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -2599,6 +2599,8 @@ void Parser::ParseSpecifierQualifierList(DeclSpec &DS, AccessSpecifier AS, Diag(DS.getVirtualSpecLoc(), diag::err_typename_invalid_functionspec); if (DS.hasExplicitSpecifier()) Diag(DS.getExplicitSpecLoc(), diag::err_typename_invalid_functionspec); + if (DS.isNoreturnSpecified()) + Diag(DS.getNoreturnSpecLoc(), diag::err_typename_invalid_functionspec); DS.ClearFunctionSpecs(); } diff --git a/clang/test/Parser/c11-noreturn.c b/clang/test/Parser/c11-noreturn.c index 0ce883ea43e3..5562a9412b5a 100644 --- a/clang/test/Parser/c11-noreturn.c +++ b/clang/test/Parser/c11-noreturn.c @@ -15,4 +15,15 @@ _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}} +struct GH56800 { + _Noreturn int f1; // expected-error {{type name does not allow function specifier to be specified}} +}; + +_Noreturn int AlsoBad; // expected-error {{'_Noreturn' can only appear on functions}} +void func(_Noreturn int ThisToo) { // expected-error {{'_Noreturn' can only appear on functions}} + for (_Noreturn int i = 0; i < 10; ++i) // expected-error {{'_Noreturn' can only appear on functions}} + ; +} + + // CHECK-EXT: '_Noreturn' is a C11 extension