Index: include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -1966,6 +1966,8 @@ "use __attribute__((visibility(\"hidden\"))) attribute instead">; // C++ Concepts TS +def err_concept_decl_non_template : Error< + "concept can only be applied to a function or variable template definition">; def err_concept_decls_may_only_appear_in_namespace_scope : Error< "concept declarations may only appear in namespace scope">; def err_function_concept_not_defined : Error< Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -4865,6 +4865,12 @@ // C++ Concepts TS [dcl.spec.concept]p1: The concept specifier shall be // applied only to the definition of a function template or variable // template, declared in namespace scope + if (!TemplateParamLists.size()) { + Diag(D.getDeclSpec().getConceptSpecLoc(), + diag::err_concept_decl_non_template); + return nullptr; + } + if (!DC->getRedeclContext()->isFileContext()) { Diag(D.getIdentifierLoc(), diag::err_concept_decls_may_only_appear_in_namespace_scope); Index: test/SemaCXX/cxx-concept-declaration.cpp =================================================================== --- test/SemaCXX/cxx-concept-declaration.cpp +++ test/SemaCXX/cxx-concept-declaration.cpp @@ -15,3 +15,7 @@ struct C { template static concept bool D3 = true; // expected-error {{concept declarations may only appear in namespace scope}} }; + +concept bool D4() { return true; } // expected-error {{concept can only be applied to a function or variable template definition}} + +concept bool D5 = true; // expected-error {{concept can only be applied to a function or variable template definition}}