This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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
diff -u -r1. parse.y
--- parse.y	21 Oct 2002 18:38:39 -0000
+++ 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;
+		    = $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

struct { int i; } a;
void foo() { a.i; }

is accepted after the patch.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]