This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix lookup in typedefs of the currently open class (PR c++/33516)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Mark Mitchell <mark at codesourcery dot com>, Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 31 Oct 2007 16:57:35 -0400
- Subject: [C++ PATCH] Fix lookup in typedefs of the currently open class (PR c++/33516)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
A typedef of a class currently being defined doesn't contain any fields
or methods until the class is finalized. The following patch will in that
case use the current class instead of the lookup.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2007-10-31 Jakub Jelinek <jakub@redhat.com>
PR c++/33516
* parser.c (cp_parser_nested_name_specifier_opt): Use
TYPE_MAIN_VARIANT (new_scope) as scope if new_scope is an incomplete
typedef of currently open class.
* g++.dg/lookup/typedef1.C: New test.
--- gcc/cp/parser.c.jj 2007-10-29 14:29:28.000000000 +0100
+++ gcc/cp/parser.c 2007-10-31 11:21:31.000000000 +0100
@@ -4085,7 +4085,16 @@ cp_parser_nested_name_specifier_opt (cp_
&& !COMPLETE_TYPE_P (new_scope)
/* Do not try to complete dependent types. */
&& !dependent_type_p (new_scope))
- new_scope = complete_type (new_scope);
+ {
+ new_scope = complete_type (new_scope);
+ /* If it is a typedef to current class, use the current
+ class instead, as the typedef won't have any names inside
+ it yet. */
+ if (!COMPLETE_TYPE_P (new_scope)
+ && TYPE_MAIN_VARIANT (new_scope) != new_scope
+ && currently_open_class (new_scope))
+ new_scope = TYPE_MAIN_VARIANT (new_scope);
+ }
/* Make sure we look in the right scope the next time through
the loop. */
parser->scope = new_scope;
--- gcc/testsuite/g++.dg/lookup/typedef1.C.jj 2007-10-31 11:26:11.000000000 +0100
+++ gcc/testsuite/g++.dg/lookup/typedef1.C 2007-10-31 11:25:32.000000000 +0100
@@ -0,0 +1,32 @@
+// PR c++/33516
+// { dg-do compile }
+
+struct S1;
+typedef S1 T1;
+struct S1 {
+ typedef int U;
+ T1::U i;
+};
+struct S2;
+typedef S2 T2;
+struct S2 {
+ typedef int U;
+};
+T2::U j;
+struct S3;
+typedef S3 T3;
+struct S3 {
+ typedef int U;
+ S3::U i;
+};
+
+void
+foo ()
+{
+ S1 s1;
+ S2 s2;
+ S3 s3;
+ s1.i = 6;
+ j = 7;
+ s3.i = 8;
+}
Jakub