r243876 - [CONCEPTS] Add concept to VarDecl and diagnostic for uninitialized variable concept

Nathan Wilson nwilson20 at gmail.com
Mon Aug 3 07:25:46 PDT 2015


Author: nwilson
Date: Mon Aug  3 09:25:45 2015
New Revision: 243876

URL: http://llvm.org/viewvc/llvm-project?rev=243876&view=rev
Log:
[CONCEPTS] Add concept to VarDecl and diagnostic for uninitialized variable concept

Summary: Add IsConcept bit to VarDecl::NonParmVarDeclBitfields and associated isConcept/setConcept member functions. Set IsConcept to true when 'concept' specifier is in variable declaration. Create diagnostic when variable concept is not initialized.

Reviewers: fraggamuffin, hubert.reinterpretcast, faisalv, aaron.ballman, rsmith

Subscribers: aemerson, cfe-commits

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

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    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/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=243876&r1=243875&r2=243876&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Aug  3 09:25:45 2015
@@ -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;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=243876&r1=243875&r2=243876&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Aug  3 09:25:45 2015
@@ -1971,6 +1971,8 @@ def err_concept_decls_may_only_appear_in
   "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<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=243876&r1=243875&r2=243876&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Aug  3 09:25:45 2015
@@ -5855,6 +5855,9 @@ Sema::ActOnVariableDeclarator(Scope *S,
 
     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
@@ -9406,6 +9409,15 @@ void Sema::ActOnUninitializedDecl(Decl *
       Var->setInvalidDecl();
       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.

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=243876&r1=243875&r2=243876&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx-concept-declaration.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx-concept-declaration.cpp Mon Aug  3 09:25:45 2015
@@ -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}}
+





More information about the cfe-commits mailing list