Hi,
another old PR, about -Wredundant-decls (not in -Wall, nor in -Wextra,
thus safe bootstrap-wise).
The issue is that we are emitting a bogus warning for a declaration
followed by a specialization. The fix seems easy, just check !
DECL_TEMPLATE_SPECIALIZATION on newdecl; then however, don't miss
redundant declarations for the specialization itself, thus the OR with
DECL_TEMPLATE_SPECIALIZATION on olddecl. The testcase checks both
situations.
Tested x86_64-linux.
Thanks,
Paolo.
////////////////////
/cp
2011-01-02 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/15867
* decl.c (duplicate_decls): With -Wredundant-decls don't warn for
declaration followed by specialization.
/testsuite
2011-01-02 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/15867
* g++.dg/warn/Wredundant-decls-spec.C: New.
Index: testsuite/g++.dg/warn/Wredundant-decls-spec.C
===================================================================
--- testsuite/g++.dg/warn/Wredundant-decls-spec.C (revision 0)
+++ testsuite/g++.dg/warn/Wredundant-decls-spec.C (revision 0)
@@ -0,0 +1,12 @@
+// PR c++/15867
+// { dg-options -Wredundant-decls }
+
+template <typename T> struct S
+{
+ void foo() {}
+};
+
+template<> void S<int>::foo();
+
+template<> void S<double>::foo(); // { dg-warning "previous declaration" }
+template<> void S<double>::foo(); // { dg-warning "redundant redeclaration" }
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 182810)
+++ cp/decl.c (working copy)
@@ -1698,7 +1698,10 @@ duplicate_decls (tree newdecl, tree olddecl, bool
/* Don't warn about extern decl followed by definition. */
&& !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
/* Don't warn about friends, let add_friend take care of it. */
- && ! (newdecl_is_friend || DECL_FRIEND_P (olddecl)))
+ && ! (newdecl_is_friend || DECL_FRIEND_P (olddecl))
+ /* Don't warn about declaration followed by specialization. */
+ && (! DECL_TEMPLATE_SPECIALIZATION (newdecl)
+ || DECL_TEMPLATE_SPECIALIZATION (olddecl)))
{
warning (OPT_Wredundant_decls, "redundant redeclaration of %qD in
same scope", newdecl);
warning (OPT_Wredundant_decls, "previous declaration of %q+D",
olddecl);