Author: nwilson Date: Fri Aug 14 18:19:32 2015 New Revision: 245123 URL: http://llvm.org/viewvc/llvm-project?rev=245123&view=rev Log: [CONCEPTS] Add diagnostic; invalid tag when concept specified
Summary: Adding check to emit diagnostic for invalid tag when concept is specified and associated tests. Reviewers: rsmith, hubert.reinterpretcast, fraggamuffin, faisalv, aaron.ballman Subscribers: aaron.ballman, cfe-commits Differential Revision: http://reviews.llvm.org/D11916 Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaDecl.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=245123&r1=245122&r2=245123&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Aug 14 18:19:32 2015 @@ -1969,7 +1969,7 @@ def note_private_extern : Note< "use __attribute__((visibility(\"hidden\"))) attribute instead">; // C++ Concepts TS -def err_concept_decl_non_template : Error< +def err_concept_wrong_decl_kind : 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">; Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=245123&r1=245122&r2=245123&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Aug 14 18:19:32 2015 @@ -3662,6 +3662,14 @@ Decl *Sema::ParsedFreeStandingDeclSpec(S return TagD; } + if (DS.isConceptSpecified()) { + // C++ Concepts TS [dcl.spec.concept]p1: A concept definition refers to + // either a function concept and its definition or a variable concept and + // its initializer. + Diag(DS.getConceptSpecLoc(), diag::err_concept_wrong_decl_kind); + return TagD; + } + DiagnoseFunctionSpecifiers(DS); if (DS.isFriendSpecified()) { @@ -4865,7 +4873,7 @@ NamedDecl *Sema::HandleDeclarator(Scope // template, declared in namespace scope if (!TemplateParamLists.size()) { Diag(D.getDeclSpec().getConceptSpecLoc(), - diag::err_concept_decl_non_template); + diag:: err_concept_wrong_decl_kind); return nullptr; } 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=245123&r1=245122&r2=245123&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/cxx-concept-declaration.cpp (original) +++ cfe/trunk/test/SemaCXX/cxx-concept-declaration.cpp Fri Aug 14 18:19:32 2015 @@ -23,3 +23,13 @@ concept bool D5 = true; // expected-erro template<typename T> concept bool D6; // expected-error {{variable concept declaration must be initialized}} +// Tag +concept class CC1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} +concept struct CS1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} +concept union CU1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} +concept enum CE1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} +template <typename T> concept class TCC1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} +template <typename T> concept struct TCS1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} +template <typename T> concept union TCU1 {}; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} + +concept bool; // expected-error {{'concept' can only appear on the definition of a function template or variable template}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits