]> granicus.if.org Git - clang/commitdiff
Patch fixes a lookup bug in c++'s anonymous union member
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 22 Jan 2010 18:30:17 +0000 (18:30 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 22 Jan 2010 18:30:17 +0000 (18:30 +0000)
lookup. Fixes radar 7562438.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94191 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/anonymous-union.cpp

index c2fa89260391ef02873f41035923f61dcda9864d..4066a646a5f7687420d66b487ad918162c5c0771 100644 (file)
@@ -1394,6 +1394,7 @@ Sema::DeclPtrTy Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) {
 /// \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 @@ static bool CheckAnonMemberRedeclaration(Sema &SemaRef,
 
   // 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 @@ bool Sema::InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner,
                                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
index 374241c9e4e6042dea8c9faebbbc1d07cc75bb09..0590db28d83266287ae77307ddf4047d3b3a4476 100644 (file)
@@ -111,3 +111,13 @@ struct BadMembers {
 
 // <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;