summaryrefslogtreecommitdiffstats
path: root/gcc/cp/friend.c
diff options
context:
space:
mode:
authorlerdsuwa <lerdsuwa@138bc75d-0d04-0410-961f-82ee72b054a4>2003-08-23 12:53:48 +0000
committerlerdsuwa <lerdsuwa@138bc75d-0d04-0410-961f-82ee72b054a4>2003-08-23 12:53:48 +0000
commitb123b79dd58608ee5ec79de477a96f9de59064b6 (patch)
treeecb689f7b3c2f693d19580d30f4517483bf94220 /gcc/cp/friend.c
parentc81cf4c1fc95476f1dae2b2494292b8694a75238 (diff)
downloadppe42-gcc-b123b79dd58608ee5ec79de477a96f9de59064b6.tar.gz
ppe42-gcc-b123b79dd58608ee5ec79de477a96f9de59064b6.zip
PR c++/641, c++/11876
* friend.c (add_friend): Add complain parameter. (make_friend_class): Likewise. (do_friend): Adjust add_friend call. * decl.c (grokdeclarator): Adjust make_friend_class call. * parser.c (cp_parser_member_declaration): Likewise. (cp_parser_template_declaration_after_exp): Likewise. * pt.c (instantiate_class_template): Adjust make_friend_class and add_friend call. * cp-tree.h (make_friend_class): Adjust declaration. (add_friend): Likewise. * g++.dg/template/friend22.C: New test. * g++.dg/template/friend23.C: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@70732 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/friend.c')
-rw-r--r--gcc/cp/friend.c49
1 files changed, 32 insertions, 17 deletions
diff --git a/gcc/cp/friend.c b/gcc/cp/friend.c
index b71c5f203db..1b3d4b46233 100644
--- a/gcc/cp/friend.c
+++ b/gcc/cp/friend.c
@@ -127,10 +127,14 @@ is_friend (tree type, tree supplicant)
}
/* 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)
+add_friend (tree type, tree decl, bool complain)
{
tree typedecl;
tree list;
@@ -153,10 +157,13 @@ add_friend (tree type, tree decl)
{
if (decl == TREE_VALUE (friends))
{
- warning ("`%D' is already a friend of class `%T'",
- decl, type);
- cp_warning_at ("previous friend declaration of `%D'",
- TREE_VALUE (friends));
+ if (complain)
+ {
+ warning ("`%D' is already a friend of class `%T'",
+ decl, type);
+ cp_warning_at ("previous friend declaration of `%D'",
+ TREE_VALUE (friends));
+ }
return;
}
}
@@ -192,10 +199,14 @@ add_friend (tree type, tree decl)
classes that are not defined. If a type has not yet been defined,
then the DECL_WAITING_FRIENDS contains a list of types
waiting to make it their friend. Note that these two can both
- be in use at the same time! */
+ be in use at the same time!
+
+ 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
-make_friend_class (tree type, tree friend_type)
+make_friend_class (tree type, tree friend_type, bool complain)
{
tree classes;
int is_template_friend;
@@ -227,8 +238,9 @@ make_friend_class (tree type, tree friend_type)
}
else if (same_type_p (type, friend_type))
{
- pedwarn ("class `%T' is implicitly friends with itself",
- type);
+ if (complain)
+ pedwarn ("class `%T' is implicitly friends with itself",
+ type);
return;
}
else
@@ -275,8 +287,9 @@ make_friend_class (tree type, tree friend_type)
{
if (friend_type == probe)
{
- warning ("`%D' is already a friend of `%T'",
- probe, type);
+ if (complain)
+ warning ("`%D' is already a friend of `%T'",
+ probe, type);
break;
}
}
@@ -284,8 +297,9 @@ make_friend_class (tree type, tree friend_type)
{
if (same_type_p (probe, friend_type))
{
- warning ("`%T' is already a friend of `%T'",
- probe, type);
+ if (complain)
+ warning ("`%T' is already a friend of `%T'",
+ probe, type);
break;
}
}
@@ -369,7 +383,7 @@ do_friend (tree ctype, tree declarator, tree decl, tree parmdecls,
parameters. Instead, we rely on tsubst_friend_function
to check the validity of the declaration later. */
if (processing_template_decl)
- add_friend (current_class_type, decl);
+ add_friend (current_class_type, decl, /*complain=*/true);
/* A nested class may declare a member of an enclosing class
to be a friend, so we do lookup here even if CTYPE is in
the process of being defined. */
@@ -378,7 +392,7 @@ do_friend (tree ctype, tree declarator, tree decl, tree parmdecls,
decl = check_classfn (ctype, decl);
if (decl)
- add_friend (current_class_type, decl);
+ add_friend (current_class_type, decl, /*complain=*/true);
}
else
error ("member `%D' declared as friend before type `%T' defined",
@@ -446,7 +460,8 @@ do_friend (tree ctype, tree declarator, tree decl, tree parmdecls,
}
add_friend (current_class_type,
- is_friend_template ? DECL_TI_TEMPLATE (decl) : decl);
+ is_friend_template ? DECL_TI_TEMPLATE (decl) : decl,
+ /*complain=*/true);
DECL_FRIEND_P (decl) = 1;
}
OpenPOWER on IntegriCloud