From: Richard Guenther Date: Tue, 27 Apr 2010 12:13:52 +0000 (+0000) Subject: backport: re PR c++/43116 (ICE when using attributes in a function alias declaration) X-Git-Tag: releases/gcc-4.3.5~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e58fd664548f1f8fb76405910bfd0cbdf3c3a83a;p=thirdparty%2Fgcc.git backport: re PR c++/43116 (ICE when using attributes in a function alias declaration) 2010-04-27 Richard Guenther Backport from mainline: 2010-03-19 Michael Matz 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7b9fc7346701..3009a5d2284f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2010-04-27 Richard Guenther + + Backport from mainline: + 2010-03-19 Michael Matz + + 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 Backport from mainline diff --git a/gcc/attribs.c b/gcc/attribs.c index d88f0697b33f..b44fe15cb36c 100644 --- a/gcc/attribs.c +++ b/gcc/attribs.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6098a3134682..8c5e53148d00 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2010-04-27 Richard Guenther + + Backport from mainline: + 2010-03-19 Michael Matz + + PR c++/43116 + * g++.dg/other/pr43116.C: New testcase. + 2010-04-20 Richard Guenther 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 index 000000000000..f0d9d01e4a86 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/pr43116.C @@ -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; +}