This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Fix PR59295 -- remove useless warning
- From: Paul Pluzhnikov <ppluzhnikov at google dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: ppluzhnikov at google dot com, drheld at google dot com
- Date: Thu, 20 Mar 2014 17:33:14 -0700
- Subject: [patch] Fix PR59295 -- remove useless warning
- Authentication-results: sourceware.org; auth=none
Greetings,
Attached patch deletes code to warn about repeated friend declaration.
The warning has apparently been present since at least 1997, but it's
unlikely to have ever prevented any actual bugs.
Ok for trunk once it opens in stage1?
Tested on Linux/x86_64 with no regressions.
Thanks,
Google ref: b/11542609
--
2014-03-20 Paul Pluzhnikov <ppluzhnikov@google.com>
PR c++/59295
* gcc/cp/friend.c (add_friend): Remove complain parameter.
(do_friend): Adjust.
* gcc/cp/cp-tree.h (add_friend): Adjust.
* gcc/cp/pt.c (instantiate_class_template_1): Adjust.
gcc/testsuite/ChangeLog:
2014-03-20 Paul Pluzhnikov <ppluzhnikov@google.com>
PR c++/59295
* g++.old-deja/g++.benjamin/warn02.C: Adjust.
Index: gcc/cp/friend.c
===================================================================
--- gcc/cp/friend.c (revision 208738)
+++ gcc/cp/friend.c (working copy)
@@ -116,14 +116,10 @@
}
/* Add a new friend to the friends of the aggregate type TYPE.
- DECL is the FUNCTION_DECL of the friend being added.
+ DECL is the FUNCTION_DECL of the friend being added. */
- If COMPLAIN is true, warning about duplicate friend is issued.
- We want to have this diagnostics during parsing but not
- when a template is being instantiated. */
-
void
-add_friend (tree type, tree decl, bool complain)
+add_friend (tree type, tree decl)
{
tree typedecl;
tree list;
@@ -146,12 +142,7 @@
for (; friends ; friends = TREE_CHAIN (friends))
{
if (decl == TREE_VALUE (friends))
- {
- if (complain)
- warning (0, "%qD is already a friend of class %qT",
- decl, type);
- return;
- }
+ return;
}
maybe_add_class_template_decl_list (type, decl, /*friend_p=*/1);
@@ -374,20 +365,12 @@
if (TREE_CODE (friend_type) == TEMPLATE_DECL)
{
if (friend_type == probe)
- {
- if (complain)
- warning (0, "%qD is already a friend of %qT", probe, type);
- break;
- }
+ break;
}
else if (TREE_CODE (probe) != TEMPLATE_DECL)
{
if (same_type_p (probe, friend_type))
- {
- if (complain)
- warning (0, "%qT is already a friend of %qT", probe, type);
- break;
- }
+ break;
}
}
@@ -511,7 +494,7 @@
decl = DECL_TI_TEMPLATE (decl);
if (decl)
- add_friend (current_class_type, decl, /*complain=*/true);
+ add_friend (current_class_type, decl);
}
else
error ("member %qD declared as friend before type %qT defined",
@@ -602,8 +585,7 @@
return error_mark_node;
add_friend (current_class_type,
- is_friend_template ? DECL_TI_TEMPLATE (decl) : decl,
- /*complain=*/true);
+ is_friend_template ? DECL_TI_TEMPLATE (decl) : decl);
DECL_FRIEND_P (decl) = 1;
}
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h (revision 208738)
+++ gcc/cp/cp-tree.h (working copy)
@@ -5402,7 +5402,7 @@
/* friend.c */
extern int is_friend (tree, tree);
extern void make_friend_class (tree, tree, bool);
-extern void add_friend (tree, tree, bool);
+extern void add_friend (tree, tree);
extern tree do_friend (tree, tree, tree, tree, enum overload_flags, bool);
/* in init.c */
Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c (revision 208738)
+++ gcc/cp/pt.c (working copy)
@@ -9315,7 +9315,7 @@
}
r = tsubst_friend_function (t, args);
- add_friend (type, r, /*complain=*/false);
+ add_friend (type, r);
if (TREE_CODE (t) == TEMPLATE_DECL)
{
pop_deferring_access_checks ();
Index: gcc/testsuite/g++.old-deja/g++.benjamin/warn02.C
===================================================================
--- gcc/testsuite/g++.old-deja/g++.benjamin/warn02.C (revision 208736)
+++ gcc/testsuite/g++.old-deja/g++.benjamin/warn02.C (working copy)
@@ -20,14 +20,6 @@
int b;
};
-class C
-{
- friend int foo(const char *);
- friend int foo(const char *); // { dg-warning "" }
- int foo2() {return b;}
- int b;
-};
-
class D
{
public: