[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
llvm-svn: 245123
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 680443a..f62de29 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1969,7 +1969,7 @@
"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">;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index c3fdd90..9282eca 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3662,6 +3662,14 @@
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 @@
// 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;
}
diff --git a/clang/test/SemaCXX/cxx-concept-declaration.cpp b/clang/test/SemaCXX/cxx-concept-declaration.cpp
index 1837a63..ccdf55e 100644
--- a/clang/test/SemaCXX/cxx-concept-declaration.cpp
+++ b/clang/test/SemaCXX/cxx-concept-declaration.cpp
@@ -23,3 +23,13 @@
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}}