]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/43116 (ICE when using attributes in a function alias declaration)
authorRichard Guenther <rguenther@suse.de>
Tue, 27 Apr 2010 12:13:52 +0000 (12:13 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 27 Apr 2010 12:13:52 +0000 (12:13 +0000)
2010-04-27  Richard Guenther  <rguenther@suse.de>

  Backport from mainline:
  2010-03-19  Michael Matz  <matz@suse.de>

PR c++/43116
* attribs.c (decl_attributes): When rebuilding a function pointer
type use the same qualifiers as the original pointer type.

* g++.dg/other/pr43116.C: New testcase.

From-SVN: r158781

gcc/ChangeLog
gcc/attribs.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/pr43116.C [new file with mode: 0644]

index 7b9fc734670113f1e6882ec5fe9774f3a5a11672..3009a5d2284f92772fadb12df959c4d3730994a4 100644 (file)
@@ -1,3 +1,12 @@
+2010-04-27  Richard Guenther  <rguenther@suse.de>
+
+       Backport from mainline:
+       2010-03-19  Michael Matz  <matz@suse.de>
+       PR c++/43116
+       * attribs.c (decl_attributes): When rebuilding a function pointer
+       type use the same qualifiers as the original pointer type.
+
 2010-04-20  Richard Guenther  <rguenther@suse.de>
 
        Backport from mainline
index d88f0697b33fdcd8bb3e039156d1de4b76d1fc87..b44fe15cb36cc5288a593a2c5f9d73e254d06fde 100644 (file)
@@ -240,6 +240,7 @@ decl_attributes (tree *node, tree attributes, int flags)
       tree *anode = node;
       const struct attribute_spec *spec = lookup_attribute_spec (name);
       bool no_add_attrs = 0;
+      int fn_ptr_quals = 0;
       tree fn_ptr_tmp = NULL_TREE;
 
       if (spec == NULL)
@@ -303,6 +304,7 @@ decl_attributes (tree *node, tree attributes, int flags)
                 This would all be simpler if attributes were part of the
                 declarator, grumble grumble.  */
              fn_ptr_tmp = TREE_TYPE (*anode);
+             fn_ptr_quals = TYPE_QUALS (*anode);
              anode = &fn_ptr_tmp;
              flags &= ~(int) ATTR_FLAG_TYPE_IN_PLACE;
            }
@@ -399,6 +401,8 @@ decl_attributes (tree *node, tree attributes, int flags)
          /* Rebuild the function pointer type and put it in the
             appropriate place.  */
          fn_ptr_tmp = build_pointer_type (fn_ptr_tmp);
+         if (fn_ptr_quals)
+           fn_ptr_tmp = build_qualified_type (fn_ptr_tmp, fn_ptr_quals);
          if (DECL_P (*node))
            TREE_TYPE (*node) = fn_ptr_tmp;
          else
index 6098a31346825d313b5a7eae471d024b9f6c3b00..8c5e53148d003c4f881ab463f9eb176d53264152 100644 (file)
@@ -1,3 +1,11 @@
+2010-04-27  Richard Guenther  <rguenther@suse.de>
+
+       Backport from mainline:
+       2010-03-19  Michael Matz  <matz@suse.de>
+       PR c++/43116
+       * g++.dg/other/pr43116.C: New testcase.
+
 2010-04-20  Richard Guenther  <rguenther@suse.de>
 
        Backport from mainline:
diff --git a/gcc/testsuite/g++.dg/other/pr43116.C b/gcc/testsuite/g++.dg/other/pr43116.C
new file mode 100644 (file)
index 0000000..f0d9d01
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+extern "C" int rpl_open (const char *filename, int flags, ...) __attribute__
+((__nonnull__ (1)));
+
+namespace gnulib
+{
+    int (*const open) (const char *filename, int flags, ...) __attribute__
+       ((__nonnull__ (1))) = rpl_open;
+}