Index: include/clang/Basic/Attr.td =================================================================== --- include/clang/Basic/Attr.td +++ include/clang/Basic/Attr.td @@ -106,6 +106,8 @@ def GlobalVar : SubsetSubjecthasGlobalStorage()}]>; +def NotAllowedOnDecls : SubsetSubject; + // FIXME: this hack is needed because DeclNodes.td defines the base Decl node // type to be a class, not a definition. This makes it impossible to create an // attribute subject which accepts a Decl. Normally, this is not a problem, @@ -690,7 +692,8 @@ def FallThrough : Attr { let Spellings = [CXX11<"clang", "fallthrough">]; -// let Subjects = [NullStmt]; + let Subjects = SubjectList<[NotAllowedOnDecls], ErrorDiag, + "ExpectedEmptyStatement">; let Documentation = [FallthroughDocs]; } Index: include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -2264,7 +2264,7 @@ "Objective-C instance methods|init methods of interface or class extension declarations|" "variables, functions and classes|Objective-C protocols|" "functions and global variables|structs, unions, and typedefs|structs and typedefs|" - "interface or protocol declarations|kernel functions}1">, + "interface or protocol declarations|kernel functions|empty statements}1">, InGroup; def err_attribute_wrong_decl_type : Error; def warn_type_attribute_wrong_type : Warning< Index: include/clang/Sema/AttributeList.h =================================================================== --- include/clang/Sema/AttributeList.h +++ include/clang/Sema/AttributeList.h @@ -846,7 +846,8 @@ ExpectedStructOrUnionOrTypedef, ExpectedStructOrTypedef, ExpectedObjectiveCInterfaceOrProtocol, - ExpectedKernelFunction + ExpectedKernelFunction, + ExpectedEmptyStatement }; } // end namespace clang Index: test/SemaCXX/switch-implicit-fallthrough.cpp =================================================================== --- test/SemaCXX/switch-implicit-fallthrough.cpp +++ test/SemaCXX/switch-implicit-fallthrough.cpp @@ -1,6 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough %s - int fallthrough(int n) { switch (n / 10) { if (n - 1) { @@ -300,3 +299,8 @@ } return n; } + +[[clang::fallthrough]] int a; // expected-error {{'fallthrough' attribute only applies to empty statements}} +[[clang::fallthrough]] int f(); // expected-error {{'fallthrough' attribute only applies to empty statements}} +void g([[clang::fallthrough]] int p); // expected-error {{'fallthrough' attribute only applies to empty statements}} +struct [[clang::fallthrough]] S; // expected-error {{'fallthrough' attribute only applies to empty statements}}