This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
proposed fix for PR c++/8662
- From: Joe Buck <jbuck at synopsys dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 21 Nov 2002 17:09:01 -0800 (PST)
- Subject: proposed fix for PR c++/8662
In PR 8662, we accept
class { int i; } a;
void foo() { a.i; }
without a diagnostic. The reason is that, for the anonymous classes,
nothing in the flow notes whether the keyword "class" or "struct" was
given, as handle_class_head is not called.
The following 2-line patch (against 3.2.1) appears to solve the problem:
Index: parse.y
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cp/parse.y,v
retrieving revision 1.248.2.5.4.3
diff -u -r1.248.2.5.4.3 parse.y
--- parse.y 21 Oct 2002 18:38:39 -0000 1.248.2.5.4.3
+++ parse.y 22 Nov 2002 00:57:05 -0000
@@ -2521,6 +2521,8 @@
current_aggr = $1;
$$.t = TYPE_MAIN_DECL (xref_tag ($1, make_anon_name (), 0));
$$.new_type_flag = 0;
+ CLASSTYPE_DECLARED_CLASS (TREE_TYPE ($$.t))
+ = $1 == class_type_node;
yyungetc ('{', 1);
}
;
We then get the output
8662.C:1: `int <anonymous class>::i' is private
8662.C:2: within this context
I copied that code directly from the corresponding position in
handle_class_head, so there's no original content (meaning you don't need
legal papers for this patch, even if it weren't two lines). I verified
that
struct { int i; } a;
void foo() { a.i; }
is accepted after the patch.