r243690 - [Concepts] Add diagnostic: non template declaration

Hubert Tong hubert.reinterpretcast at gmail.com
Thu Jul 30 14:20:55 PDT 2015


Author: hubert.reinterpretcast
Date: Thu Jul 30 16:20:55 2015
New Revision: 243690

URL: http://llvm.org/viewvc/llvm-project?rev=243690&view=rev
Log:
[Concepts] Add diagnostic: non template declaration

Summary:
Adding diagnostic for concepts declared as non template (function
or variable)

Reviewers: faisalv, fraggamuffin, rsmith, hubert.reinterpretcast

Subscribers: nwilson, cfe-commits

Differential Revision: http://reviews.llvm.org/D11490

Patch by Nathan Wilson!

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Parser/cxx-concept-declaration.cpp
    cfe/trunk/test/SemaCXX/cxx-concept-declaration.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=243690&r1=243689&r2=243690&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jul 30 16:20:55 2015
@@ -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<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=243690&r1=243689&r2=243690&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Jul 30 16:20:55 2015
@@ -4865,6 +4865,12 @@ NamedDecl *Sema::HandleDeclarator(Scope
     // 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);

Modified: cfe/trunk/test/Parser/cxx-concept-declaration.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-concept-declaration.cpp?rev=243690&r1=243689&r2=243690&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx-concept-declaration.cpp (original)
+++ cfe/trunk/test/Parser/cxx-concept-declaration.cpp Thu Jul 30 16:20:55 2015
@@ -25,6 +25,4 @@ template<typename T> concept concept boo
 
 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'}}

Modified: cfe/trunk/test/SemaCXX/cxx-concept-declaration.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx-concept-declaration.cpp?rev=243690&r1=243689&r2=243690&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx-concept-declaration.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx-concept-declaration.cpp Thu Jul 30 16:20:55 2015
@@ -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}}





More information about the cfe-commits mailing list