]> granicus.if.org Git - clang/commitdiff
Fix bogus compiler errors when declaring anonymous union, outside a class, with
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 23 Sep 2010 14:26:01 +0000 (14:26 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 23 Sep 2010 14:26:01 +0000 (14:26 +0000)
members with the same name as a decl outside the scope where the members are actually introduced.
Fixes http://llvm.org/PR6741

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

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

index 0b3e60f82a80e07f5fc4716e4845846e93af84cf..48e36a9dc475e7a55464a43f9dd96570cbf4531f 100644 (file)
@@ -1707,11 +1707,10 @@ 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;
-  }
+  assert(PrevDecl && "Expected a non-null Decl");
+
+  if (!SemaRef.isDeclInScope(PrevDecl, Owner, S))
+    return false;
 
   SemaRef.Diag(NameLoc, diagnostic) << Name;
   SemaRef.Diag(PrevDecl->getLocation(), diag::note_previous_declaration);
index 5f84bcca28db50ed73c7e64ca6c4a9725be1b310..553ae658e53b3e247d88f9178e2872839de15c26 100644 (file)
@@ -155,3 +155,23 @@ namespace test4 {
     (void) a.us1; // expected-error {{private member}}
   }
 }
+
+typedef void *voidPtr;
+
+void f2() {
+    union { int **ctxPtr; void **voidPtr; };
+}
+
+void foo_PR6741() {
+    union {
+        char *m_a;
+        int *m_b;
+    };
+    if(1) {
+        union {
+            char *m_a;
+            int *m_b;
+        };
+    }
+}