OSDN Git Service

PR c++/33516
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 2 Nov 2007 21:37:35 +0000 (21:37 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 2 Nov 2007 21:37:35 +0000 (21:37 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@129862 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/lookup/typedef1.C [new file with mode: 0644]

index 3a90378..1acce71 100644 (file)
@@ -1,3 +1,10 @@
+2007-11-02  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.
+
 2007-11-02  Paolo Carlini  <pcarlini@suse.de>
 
        PR c++/33495
index 7734cc1..0772c87 100644 (file)
@@ -4085,7 +4085,15 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser,
          && !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)
+             && 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;
index 514829c..ccd4ccb 100644 (file)
@@ -1,3 +1,8 @@
+2007-11-02  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/33516
+       * g++.dg/lookup/typedef1.C: New test.
+
 2007-11-02  Janis Johnson  <janis187@us.ibm.com>
 
        PR testsuite/32076
diff --git a/gcc/testsuite/g++.dg/lookup/typedef1.C b/gcc/testsuite/g++.dg/lookup/typedef1.C
new file mode 100644 (file)
index 0000000..f712fc2
--- /dev/null
@@ -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;
+}