Qualified friends
Martin v. Loewis
martin@mira.isdn.cs.tu-berlin.de
Sun Feb 21 01:55:00 GMT 1999
egcs currently rejects globally-scoped friend declarations; this was
reported for 1.1.1. It turned out there is an ambiguity in C++. The
examples below show this ambiguity and how it was resolved.
Unfortunately, the grammar change led to a new set of reduce/reduce
conflicts. bison isn't sure whether a certain construct is a
declarator or a primary, it will chose declarator in these cases. As a
result, this patch breaks g++.jason/parse4.C. It currently reads
B( ::g() ).f(); // no syntax error
B( g() ).f(); // gets bogus error - treated as decl XFAIL *-*-*
g++ already treats the second line as a declaration. Now that a
declarator can start with a SCOPE, the first line runs into the same
error.
We desperately need Mark's new grammar.
Regards,
Martin
1999-02-20 Martin von Löwis <loewis@informatik.hu-berlin.de>
* parse.y (complex_direct_notype_declarator): Support global_scope.
* Makefile: Adjust conflict count.
//Build don't link:
void foo();
class R{
int i;
friend void ::foo();
};
void ::foo()
{
R r;
r.i=4;
}
//Build don't link:
struct A{
struct B{};
};
A::B C();
namespace B{
A C();
}
class Test{
friend A (::B::C)(); // Ok
friend A::B (::C)(); // Ok
friend A::B::C(); // ERROR: no A::B::C
};
Index: Makefile.in
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/Makefile.in,v
retrieving revision 1.46
diff -u -p -r1.46 Makefile.in
--- Makefile.in 1999/01/27 01:43:13 1.46
+++ Makefile.in 1999/02/20 20:52:47
@@ -1,5 +1,5 @@
# Makefile for GNU C++ compiler.
-# Copyright (C) 1987, 88, 90-4, 1995, 1998 Free Software Foundation, Inc.
+# Copyright (C) 1987, 88, 90-95, 1998, 1999 Free Software Foundation, Inc.
#This file is part of GNU CC.
@@ -225,7 +225,7 @@ parse.o : $(PARSE_C) $(CONFIG_H) $(CXX_T
$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(BIG_SWITCHFLAG) \
`echo $(PARSE_C) | sed 's,^\./,,'`
-CONFLICTS = expect 36 shift/reduce conflicts and 42 reduce/reduce conflicts.
+CONFLICTS = expect 37 shift/reduce conflicts and 58 reduce/reduce conflicts.
$(PARSE_H) : $(PARSE_C)
$(PARSE_C) : $(srcdir)/parse.y
@echo $(CONFLICTS)
Index: parse.y
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/parse.y,v
retrieving revision 1.107
diff -u -p -r1.107 parse.y
--- parse.y 1998/12/16 21:16:01 1.107
+++ parse.y 1999/02/20 20:52:51
@@ -1,5 +1,5 @@
/* YACC parser for C++ syntax.
- Copyright (C) 1988, 89, 93-97, 1998 Free Software Foundation, Inc.
+ Copyright (C) 1988, 89, 93-98, 1999 Free Software Foundation, Inc.
Hacked by Michael Tiemann (tiemann@cygnus.com)
This file is part of GNU CC.
@@ -2851,6 +2851,12 @@ complex_direct_notype_declarator:
{ $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
| notype_qualified_id
{ enter_scope_of ($1); }
+ | global_scope notype_qualified_id
+ { enter_scope_of ($2); $$ = $2;}
+ | global_scope notype_unqualified_id
+ { $$ = build_parse_node (SCOPE_REF, global_namespace, $2);
+ enter_scope_of ($$);
+ }
| nested_name_specifier notype_template_declarator
{ got_scope = NULL_TREE;
$$ = build_parse_node (SCOPE_REF, $1, $2);
More information about the Gcc-patches
mailing list