This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 20212
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 6 Apr 2005 08:56:36 -0700
- Subject: C++ PATCH: PR 20212
- Reply-to: mark at codesourcery dot com
This patch fixes a spurious warning in template code; the "unused"
attribute was being ignored on parameters to function templates.
Tested on x86_64-unknown-linux-gnu, applied on the mainline and on the
branch.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2005-04-06 Mark Mitchell <mark@codesourcery.com>
PR c++/20212
* pt.c (regenerate_decl_from_template): Copy attributes for
parameters from the pattern to the instantiation.
2005-04-06 Mark Mitchell <mark@codesourcery.com>
PR c++/20212
* g++.dg/warn/Wunused-11.C: New test.
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.990
diff -c -5 -p -r1.990 pt.c
*** cp/pt.c 3 Apr 2005 14:24:28 -0000 1.990
--- cp/pt.c 6 Apr 2005 15:41:52 -0000
*************** regenerate_decl_from_template (tree decl
*** 11188,11205 ****
--- 11188,11212 ----
= skip_artificial_parms_for (code_pattern,
DECL_ARGUMENTS (code_pattern));
while (decl_parm)
{
tree parm_type;
+ tree attributes;
if (DECL_NAME (decl_parm) != DECL_NAME (pattern_parm))
DECL_NAME (decl_parm) = DECL_NAME (pattern_parm);
parm_type = tsubst (TREE_TYPE (pattern_parm), args, tf_error,
NULL_TREE);
parm_type = type_decays_to (parm_type);
if (!same_type_p (TREE_TYPE (decl_parm), parm_type))
TREE_TYPE (decl_parm) = parm_type;
+ attributes = DECL_ATTRIBUTES (pattern_parm);
+ if (DECL_ATTRIBUTES (decl_parm) != attributes)
+ {
+ DECL_ATTRIBUTES (decl_parm) = attributes;
+ cplus_decl_attributes (&decl_parm, attributes, /*flags=*/0);
+ }
decl_parm = TREE_CHAIN (decl_parm);
pattern_parm = TREE_CHAIN (pattern_parm);
}
/* Merge additional specifiers from the CODE_PATTERN. */
Index: testsuite/g++.dg/warn/Wunused-11.C
===================================================================
RCS file: testsuite/g++.dg/warn/Wunused-11.C
diff -N testsuite/g++.dg/warn/Wunused-11.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/warn/Wunused-11.C 6 Apr 2005 15:44:00 -0000
***************
*** 0 ****
--- 1,11 ----
+ // PR c++/20212
+ // { dg-options "-O2 -Wunused -Wextra" }
+
+ template<int> void f(int);
+ void g(int i)
+ {
+ f<0>(i);
+ }
+ template<int> void f(int i __attribute__((unused)) )
+ {}
+