diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 6 | ||||
| -rw-r--r-- | clang/test/Parser/cxx-concept-declaration.cpp | 4 | ||||
| -rw-r--r-- | clang/test/SemaCXX/cxx-concept-declaration.cpp | 4 |
4 files changed, 13 insertions, 3 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 44508d5..c300d6fe 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -1965,6 +1965,8 @@ def note_private_extern : Note< "use __attribute__((visibility(\"hidden\"))) attribute instead">; // C++ Concepts TS +def err_concept_decl_non_template : Error< + "'concept' can only appear on the definition of a function template or variable template">; 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< diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 98db0c7..f273de1 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -4865,6 +4865,12 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D, // 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); diff --git a/clang/test/Parser/cxx-concept-declaration.cpp b/clang/test/Parser/cxx-concept-declaration.cpp index 591629c..fad5975 100644 --- a/clang/test/Parser/cxx-concept-declaration.cpp +++ b/clang/test/Parser/cxx-concept-declaration.cpp @@ -25,6 +25,4 @@ template<typename T> concept concept bool C6 = true; // expected-warning {{dupli template<typename T> concept concept bool C7() { return true; } // expected-warning {{duplicate 'concept' declaration specifier}} -concept D1 = true; // expected-error {{C++ requires a type specifier for all declarations}} - -template<concept T> concept bool D2 = true; // expected-error {{unknown type name 'T'}} +template<concept T> concept bool D1 = true; // expected-error {{unknown type name 'T'}} diff --git a/clang/test/SemaCXX/cxx-concept-declaration.cpp b/clang/test/SemaCXX/cxx-concept-declaration.cpp index 6bc2d482..f9878bc 100644 --- a/clang/test/SemaCXX/cxx-concept-declaration.cpp +++ b/clang/test/SemaCXX/cxx-concept-declaration.cpp @@ -15,3 +15,7 @@ struct B { struct C { template<typename T> 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 appear on the definition of a function template or variable template}} + +concept bool D5 = true; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} |
