This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/35758] [4.3/4.4 Regression] vector_size attribute lost in function arguments for templates



------- Comment #15 from jakub at gcc dot gnu dot org  2008-04-07 10:52 -------
I've tried the first step - putting the attributes that require type to
TYPE_ATTRIBUTES rather than DECL_ATTRIBUTES, see below.
Unfortunately tsubst doesn't call apply_late_template_attributes in that case
(the only place which calls it on TYPE_ATTRIBUTES is instantiate_class_template
on the fn type).  So I'm giving up on this.

The patch was:
--- decl2.c.jj  2008-03-25 23:31:25.000000000 +0100
+++ decl2.c     2008-04-07 12:40:19.000000000 +0200
@@ -1041,12 +1041,13 @@ is_late_template_attribute (tree attr, t
    at instantiation time.  */

 static tree
-splice_template_attributes (tree *attr_p, tree decl)
+splice_template_attributes (tree *attr_p, tree *type_attr_p, tree decl)
 {
   tree *p = attr_p;
   tree late_attrs = NULL_TREE;
   tree *q = &late_attrs;

+  *type_attr_p = NULL_TREE;
   if (!p)
     return NULL_TREE;

@@ -1054,11 +1055,28 @@ splice_template_attributes (tree *attr_p
     {
       if (is_late_template_attribute (*p, decl))
        {
-         ATTR_IS_DEPENDENT (*p) = 1;
-         *q = *p;
+         const struct attribute_spec *spec
+           = lookup_attribute_spec (TREE_PURPOSE (*p));
+
+         /* Put attributes that require type into TYPE_ATTRIBUTES,
+            rather than DECL_ATTRIBUTES.  */
+         if (DECL_P (decl)
+             && spec
+             && spec->type_required
+             && !CLASS_TYPE_P (TREE_TYPE (decl)))
+           {
+             *type_attr_p = *p;
+             type_attr_p = &TREE_CHAIN (*type_attr_p);
+             *type_attr_p = NULL_TREE;
+           }
+         else
+           {
+             ATTR_IS_DEPENDENT (*p) = 1;
+             *q = *p;
+             q = &TREE_CHAIN (*q);
+             *q = NULL_TREE;
+           }
          *p = TREE_CHAIN (*p);
-         q = &TREE_CHAIN (*q);
-         *q = NULL_TREE;
        }
       else
        p = &TREE_CHAIN (*p);
@@ -1071,12 +1089,17 @@ splice_template_attributes (tree *attr_p
    DECL_P.  */

 static void
-save_template_attributes (tree *attr_p, tree *decl_p)
+save_template_attributes (tree *attr_p, tree *decl_p, int flags)
 {
-  tree late_attrs = splice_template_attributes (attr_p, *decl_p);
+  tree type_attrs;
+  tree late_attrs = splice_template_attributes (attr_p, &type_attrs, *decl_p);
   tree *q;
   tree old_attrs = NULL_TREE;

+  if (type_attrs)
+    cplus_decl_attributes (&TREE_TYPE (*decl_p), type_attrs,
+                          flags & ~(int) ATTR_FLAG_TYPE_IN_PLACE);
+
   if (!late_attrs)
     return;

@@ -1135,7 +1158,7 @@ cplus_decl_attributes (tree *decl, tree 
       if (check_for_bare_parameter_packs (attributes))
        return;

-      save_template_attributes (&attributes, decl);
+      save_template_attributes (&attributes, decl, flags);
       if (attributes == NULL_TREE)
        return;
     }


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35758


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]