diff mbox

[var-template] Accept variable template declaration

Message ID 87hajt61f7.fsf@euclid.axiomatics.org
State New
Headers show

Commit Message

Gabriel Dos Reis March 30, 2013, 2:56 a.m. UTC
Jason Merrill <jason@redhat.com> writes:

| On 03/29/2013 06:29 PM, Gabriel Dos Reis wrote:
| > +  if (TREE_CODE (t) != TEMPLATE_DECL
| > +      || !(DECL_NAMESPACE_SCOPE_P (t) || DECL_MEMBER_TEMPLATE_P (t)))
| 
| Why check the scope?

ah right, if it is a template the scope was already checked.

| > -  if (!TYPE_P (ctx) || !CLASSTYPE_TEMPLATE_INFO (ctx))
| > -    permerror (DECL_SOURCE_LOCATION (decl),
| > -	       "%qD is not a static data member of a class template", decl);
| > +  if (!TYPE_P (ctx) || !CLASSTYPE_TEMPLATE_INFO (ctx)) {
| > +    if (cxx_dialect < cxx1y)
| > +      permerror (DECL_SOURCE_LOCATION (decl),
| > +                 "%qD is not a static data member of a class template", decl);
| > +  }
| >    else if (template_header_count > wanted)
| 
| I think we still want to check for excess template headers.

right your are.

| > +      else if (VAR_P (decl)) {
| > +        if (!DECL_DECLARED_CONSTEXPR_P (decl))
| > +          error ("template declaration of non-constexpr variable %qD", decl);
| > +      }
| 
| Open brace should be on a line by itself.

oops, fixed.  Too many coding standards...

-- Gaby

2013-03-29  Gabriel Dos Reis  <gdr@integrable-solutions.net>
 
	* cp-tree.h (variable_template_p): Do not check scope.
	* pt.c (check_template_variable): Fix thinko from previous change.
	(push_template_decl_real): Fix formatting.

Comments

Jason Merrill March 31, 2013, 5:13 a.m. UTC | #1
On 03/29/2013 10:56 PM, Gabriel Dos Reis wrote:
>    int wanted = num_template_headers_for_class (ctx);

I think you want to add one to wanted if decl is a primary template.

Jason
Gabriel Dos Reis April 1, 2013, 8:53 p.m. UTC | #2
On Sun, Mar 31, 2013 at 12:13 AM, Jason Merrill <jason@redhat.com> wrote:
>
> On 03/29/2013 10:56 PM, Gabriel Dos Reis wrote:
>>
>>    int wanted = num_template_headers_for_class (ctx);
>
>
> I think you want to add one to wanted if decl is a primary template.

OK but I am a little bit dense here: why is that necessary?

-- Gaby
Jason Merrill April 1, 2013, 8:58 p.m. UTC | #3
On 04/01/2013 04:53 PM, Gabriel Dos Reis wrote:
> On Sun, Mar 31, 2013 at 12:13 AM, Jason Merrill <jason@redhat.com> wrote:
>>
>> On 03/29/2013 10:56 PM, Gabriel Dos Reis wrote:
>>>
>>>     int wanted = num_template_headers_for_class (ctx);
>>
>> I think you want to add one to wanted if decl is a primary template.
>
> OK but I am a little bit dense here: why is that necessary?

By 'primary' I mean something that is itself a template, not just a 
member of a class template.  Previously variables couldn't be primary 
templates, but I believe your proposal is to change that; in that case, 
we should expect to see a template header for such a template, in 
addition to any headers for enclosing classes.

Jason
Gabriel Dos Reis April 1, 2013, 9:11 p.m. UTC | #4
On Mon, Apr 1, 2013 at 3:58 PM, Jason Merrill <jason@redhat.com> wrote:
> On 04/01/2013 04:53 PM, Gabriel Dos Reis wrote:
>>
>> On Sun, Mar 31, 2013 at 12:13 AM, Jason Merrill <jason@redhat.com> wrote:
>>>
>>>
>>> On 03/29/2013 10:56 PM, Gabriel Dos Reis wrote:
>>>>
>>>>
>>>>     int wanted = num_template_headers_for_class (ctx);
>>>
>>>
>>> I think you want to add one to wanted if decl is a primary template.
>>
>>
>> OK but I am a little bit dense here: why is that necessary?
>
>
> By 'primary' I mean something that is itself a template, not just a member
> of a class template.  Previously variables couldn't be primary templates,
> but I believe your proposal is to change that; in that case, we should
> expect to see a template header for such a template, in addition to any
> headers for enclosing classes.

Ah, yes; got it.  Thanks!

-- Gaby
diff mbox

Patch

Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 197259)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -4930,8 +4930,7 @@ 
 inline bool
 variable_template_p (tree t)
 {
-  if (TREE_CODE (t) != TEMPLATE_DECL
-      || !(DECL_NAMESPACE_SCOPE_P (t) || DECL_MEMBER_TEMPLATE_P (t)))
+  if (TREE_CODE (t) != TEMPLATE_DECL)
     return false;
   if (tree r = DECL_TEMPLATE_RESULT (t))
     return VAR_P (r);
Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c	(revision 197259)
+++ gcc/cp/pt.c	(working copy)
@@ -2275,7 +2275,7 @@ 
       permerror (DECL_SOURCE_LOCATION (decl),
                  "%qD is not a static data member of a class template", decl);
   }
-  else if (template_header_count > wanted)
+  if (template_header_count > wanted)
     {
       pedwarn (DECL_SOURCE_LOCATION (decl), 0,
 	       "too many template headers for %D (should be %d)",
@@ -4618,10 +4618,11 @@ 
 	       && TYPE_DECL_ALIAS_P (decl))
 	/* alias-declaration */
 	gcc_assert (!DECL_ARTIFICIAL (decl));
-      else if (VAR_P (decl)) {
-        if (!DECL_DECLARED_CONSTEXPR_P (decl))
-          error ("template declaration of non-constexpr variable %qD", decl);
-      }
+      else if (VAR_P (decl))
+        {
+          if (!DECL_DECLARED_CONSTEXPR_P (decl))
+            error ("template declaration of non-constexpr variable %qD", decl);
+        }
       else
 	{
 	  error ("template declaration of %q#D", decl);