[cfe-commits] r114641 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/anonymous-union.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Thu Sep 23 07:26:01 PDT 2010
Author: akirtzidis
Date: Thu Sep 23 09:26:01 2010
New Revision: 114641
URL: http://llvm.org/viewvc/llvm-project?rev=114641&view=rev
Log:
Fix bogus compiler errors when declaring anonymous union, outside a class, with
members with the same name as a decl outside the scope where the members are actually introduced.
Fixes http://llvm.org/PR6741
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=114641&r1=114640&r2=114641&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Sep 23 09:26:01 2010
@@ -1707,11 +1707,10 @@
// 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);
Modified: cfe/trunk/test/SemaCXX/anonymous-union.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/anonymous-union.cpp?rev=114641&r1=114640&r2=114641&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/anonymous-union.cpp (original)
+++ cfe/trunk/test/SemaCXX/anonymous-union.cpp Thu Sep 23 09:26:01 2010
@@ -155,3 +155,23 @@
(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;
+ };
+ }
+}
More information about the cfe-commits
mailing list