[cfe-commits] r94191 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/anonymous-union.cpp

Fariborz Jahanian fjahanian at apple.com
Fri Jan 22 10:30:17 PST 2010


Author: fjahanian
Date: Fri Jan 22 12:30:17 2010
New Revision: 94191

URL: http://llvm.org/viewvc/llvm-project?rev=94191&view=rev
Log:
Patch fixes a lookup bug in c++'s anonymous union member
lookup. Fixes radar 7562438.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/anonymous-union.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=94191&r1=94190&r2=94191&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jan 22 12:30:17 2010
@@ -1394,6 +1394,7 @@
 /// \return true if this is a forbidden redeclaration
 static bool CheckAnonMemberRedeclaration(Sema &SemaRef,
                                          Scope *S,
+                                         DeclContext *Owner,
                                          DeclarationName Name,
                                          SourceLocation NameLoc,
                                          unsigned diagnostic) {
@@ -1406,6 +1407,11 @@
 
   // Pick a representative declaration.
   NamedDecl *PrevDecl = R.getRepresentativeDecl()->getUnderlyingDecl();
+  if (PrevDecl && Owner->isRecord()) {
+    RecordDecl *Record = cast<RecordDecl>(Owner);
+    if (!SemaRef.isDeclInScope(PrevDecl, Record, S))
+      return false;
+  }
 
   SemaRef.Diag(NameLoc, diagnostic) << Name;
   SemaRef.Diag(PrevDecl->getLocation(), diag::note_previous_declaration);
@@ -1440,7 +1446,7 @@
                                FEnd = AnonRecord->field_end();
        F != FEnd; ++F) {
     if ((*F)->getDeclName()) {
-      if (CheckAnonMemberRedeclaration(*this, S, (*F)->getDeclName(),
+      if (CheckAnonMemberRedeclaration(*this, S, Owner, (*F)->getDeclName(),
                                        (*F)->getLocation(), diagKind)) {
         // C++ [class.union]p2:
         //   The names of the members of an anonymous union shall be

Modified: cfe/trunk/test/SemaCXX/anonymous-union.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/anonymous-union.cpp?rev=94191&r1=94190&r2=94191&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/anonymous-union.cpp (original)
+++ cfe/trunk/test/SemaCXX/anonymous-union.cpp Fri Jan 22 12:30:17 2010
@@ -111,3 +111,13 @@
 
 // <rdar://problem/6481130>
 typedef union { }; // expected-error{{declaration does not declare anything}}
+
+// <rdar://problem/7562438>
+typedef struct objc_module *Foo ;
+
+typedef struct _s {
+    union {
+        int a;
+        int Foo;
+    };
+} s, *ps;





More information about the cfe-commits mailing list