diff mbox

[c++-concepts] variable concept fixes

Message ID CANq5SyvPthg96k36012Bqc7umigwMhJug1EWe-pUbUnHKPye3g@mail.gmail.com
State New
Headers show

Commit Message

Andrew Sutton Aug. 20, 2014, 6:56 p.m. UTC
Add more diagnostics for variable concepts. Also fix a regression
where non-template concepts variables were causing ICEs because they
aren't being allocated via build_lang_decl.

2014-08-15  Andrew Sutton  <andrew.n.sutton@gmail.com>

Additional declaration restrictions on variable concepts.
    * gcc/cp/decl.c (is_concept_var): New.
    (cp_finish_decl): Check for uninitialized variable
    concepts.
    (grokvardecl): Don't set the concept flag for non-template variables.
    * g++.dg/concepts/decl-diagnose.C: Add tests.

Andrew Sutton

Comments

Paolo Carlini Aug. 20, 2014, 7:24 p.m. UTC | #1
Hi,

On 08/20/2014 08:56 PM, Andrew Sutton wrote:
> +  return VAR_P (decl)
> +         && DECL_LANG_SPECIFIC (decl)
> +         && DECL_DECLARED_CONCEPT_P (decl);
this is brittle from the formatting point of view. Please double check 
in detail what I'm going to say, but I think that in such cases you 
simply want to wrap the whole thing in round parentheses.

Paolo.
Andrew Sutton Aug. 20, 2014, 9:08 p.m. UTC | #2
> On 08/20/2014 08:56 PM, Andrew Sutton wrote:
>>
>> +  return VAR_P (decl)
>> +         && DECL_LANG_SPECIFIC (decl)
>> +         && DECL_DECLARED_CONCEPT_P (decl);
>
> this is brittle from the formatting point of view. Please double check in
> detail what I'm going to say, but I think that in such cases you simply want
> to wrap the whole thing in round parentheses.

Sorry, did you just mean to wrap the entire conjunction in parens? I'm
trying to find the formatting guidelines to check, but not succeeding
at the moment.

Andrew
Paolo Carlini Aug. 21, 2014, 8:26 a.m. UTC | #3
Hi Andrew,

On 08/20/2014 11:08 PM, Andrew Sutton wrote:
>> On 08/20/2014 08:56 PM, Andrew Sutton wrote:
>>> +  return VAR_P (decl)
>>> +         && DECL_LANG_SPECIFIC (decl)
>>> +         && DECL_DECLARED_CONCEPT_P (decl);
>> this is brittle from the formatting point of view. Please double check in
>> detail what I'm going to say, but I think that in such cases you simply want
>> to wrap the whole thing in round parentheses.
> Sorry, did you just mean to wrap the entire conjunction in parens? I'm
> trying to find the formatting guidelines to check, but not succeeding
> at the moment.
Yes, I meant the whole conjunction, sorry about my sloppy language. In 
terms of GNU coding standards:

     http://www.gnu.org/prep/standards/standards.html#Formatting

toward the end of the section, for example.

Paolo.
diff mbox

Patch

Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 214239)
+++ gcc/cp/decl.c	(working copy)
@@ -6259,6 +6259,16 @@  value_dependent_init_p (tree init)
   return false;
 }
 
+// Returns true if a DECL is VAR_DECL with the concept specifier. Note
+// that not all variables are decl-lang-specific.
+static inline bool
+is_concept_var (tree decl) 
+{
+  return VAR_P (decl) 
+         && DECL_LANG_SPECIFIC (decl)
+         && DECL_DECLARED_CONCEPT_P (decl);
+}
+
 /* Finish processing of a declaration;
    install its line number and initial value.
    If the length of an array type is not known before,
@@ -6435,6 +6445,8 @@  cp_finish_decl (tree decl, tree init, bo
 	    init = NULL_TREE;
 	  release_tree_vector (cleanups);
 	}
+      else if (!init && is_concept_var (decl))
+        error ("variable concept has no initializer");
       else if (!DECL_PRETTY_FUNCTION_P (decl))
 	{
 	  /* Deduce array size even if the initializer is dependent.  */
@@ -8264,9 +8276,17 @@  grokvardecl (tree type,
   else
     DECL_INTERFACE_KNOWN (decl) = 1;
 
-  // Mark the variable as a concept.
+  // Check that the variable can be safely declared as a concept.
   if (conceptp)
-    DECL_DECLARED_CONCEPT_P (decl) = true;
+    {
+      if (!processing_template_decl) 
+        {
+          error ("a non-template variable cannot be %<concept%>");
+          return NULL_TREE;
+        }
+      else
+        DECL_DECLARED_CONCEPT_P (decl) = true;
+    }
 
   // Handle explicit specializations and instantiations of variable templates.
   if (orig_declarator)