summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/AST/Decl.h12
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td2
-rw-r--r--clang/lib/Sema/SemaDecl.cpp12
-rw-r--r--clang/test/SemaCXX/cxx-concept-declaration.cpp4
4 files changed, 30 insertions, 0 deletions
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index e06b58b37be..76c05852f72 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -815,6 +815,9 @@ protected:
/// \brief Whether this variable is (C++0x) constexpr.
unsigned IsConstexpr : 1;
+ /// \brief Whether this variable is a (C++ Concepts TS) concept.
+ unsigned IsConcept : 1;
+
/// \brief Whether this variable is the implicit variable for a lambda
/// init-capture.
unsigned IsInitCapture : 1;
@@ -1238,6 +1241,15 @@ public:
NonParmVarDeclBits.IsConstexpr = IC;
}
+ /// Whether this variable is (C++ Concepts TS) concept.
+ bool isConcept() const {
+ return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsConcept;
+ }
+ void setConcept(bool IC) {
+ assert(!isa<ParmVarDecl>(this));
+ NonParmVarDeclBits.IsConcept = IC;
+ }
+
/// Whether this variable is the implicit variable for a lambda init-capture.
bool isInitCapture() const {
return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsInitCapture;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 65670f454be..43c1b47b5ff 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1971,6 +1971,8 @@ 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<
"function concept declaration must be a definition">;
+def err_var_concept_not_initialized : Error<
+ "variable concept declaration must be initialized">;
// C++11 char16_t/char32_t
def warn_cxx98_compat_unicode_type : Warning<
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9f499de0843..962610c1ce5 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5855,6 +5855,9 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
if (D.getDeclSpec().isConstexprSpecified())
NewVD->setConstexpr(true);
+
+ if (D.getDeclSpec().isConceptSpecified())
+ NewVD->setConcept(true);
}
// Set the lexical context. If the declarator has a C++ scope specifier, the
@@ -9407,6 +9410,15 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl,
return;
}
+ // C++ Concepts TS [dcl.spec.concept]p1: [...] A variable template
+ // definition having the concept specifier is called a variable concept. A
+ // concept definition refers to [...] a variable concept and its initializer.
+ if (Var->isConcept()) {
+ Diag(Var->getLocation(), diag::err_var_concept_not_initialized);
+ Var->setInvalidDecl();
+ return;
+ }
+
// OpenCL v1.1 s6.5.3: variables declared in the constant address space must
// be initialized.
if (!Var->isInvalidDecl() &&
diff --git a/clang/test/SemaCXX/cxx-concept-declaration.cpp b/clang/test/SemaCXX/cxx-concept-declaration.cpp
index f9878bc5812..1837a63989a 100644
--- a/clang/test/SemaCXX/cxx-concept-declaration.cpp
+++ b/clang/test/SemaCXX/cxx-concept-declaration.cpp
@@ -19,3 +19,7 @@ struct C {
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}}
+
+template<typename T>
+concept bool D6; // expected-error {{variable concept declaration must be initialized}}
+
OpenPOWER on IntegriCloud