[cfe-commits] r125822 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaTemplate/instantiate-anonymous-union.cpp
Douglas Gregor
dgregor at apple.com
Thu Feb 17 18:44:58 PST 2011
Author: dgregor
Date: Thu Feb 17 20:44:58 2011
New Revision: 125822
URL: http://llvm.org/viewvc/llvm-project?rev=125822&view=rev
Log:
When building a qualified reference to a member of an anonymous struct
or union, place the qualifier on the outermost member reference
expression, which actually contains the entity name.
Fixes PR9188/<rdar://problem/8990184>.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=125822&r1=125821&r2=125822&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Feb 17 20:44:58 2011
@@ -1004,6 +1004,7 @@
// Case 1: the base of the indirect field is not a field.
VarDecl *baseVariable = indirectField->getVarDecl();
+ CXXScopeSpec EmptySS;
if (baseVariable) {
assert(baseVariable->getType()->isRecordType());
@@ -1017,7 +1018,7 @@
DeclarationNameInfo baseNameInfo(DeclarationName(), loc);
ExprResult result =
- BuildDeclarationNameExpr(SS, baseNameInfo, baseVariable);
+ BuildDeclarationNameExpr(EmptySS, baseNameInfo, baseVariable);
if (result.isInvalid()) return ExprError();
baseObjectExpr = result.take();
@@ -1078,7 +1079,7 @@
DeclarationNameInfo memberNameInfo(field->getDeclName(), loc);
result = BuildFieldReferenceExpr(*this, result, baseObjectIsPointer,
- SS, field, foundDecl,
+ EmptySS, field, foundDecl,
memberNameInfo).take();
baseObjectIsPointer = false;
@@ -1088,16 +1089,16 @@
// In all cases, we should now skip the first declaration in the chain.
++FI;
- for (; FI != FEnd; FI++) {
- FieldDecl *field = cast<FieldDecl>(*FI);
+ while (FI != FEnd) {
+ FieldDecl *field = cast<FieldDecl>(*FI++);
// FIXME: these are somewhat meaningless
DeclarationNameInfo memberNameInfo(field->getDeclName(), loc);
DeclAccessPair foundDecl = DeclAccessPair::make(field, field->getAccess());
- CXXScopeSpec memberSS;
result = BuildFieldReferenceExpr(*this, result, /*isarrow*/ false,
- memberSS, field, foundDecl, memberNameInfo)
+ (FI == FEnd? SS : EmptySS), field,
+ foundDecl, memberNameInfo)
.take();
}
Modified: cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp?rev=125822&r1=125821&r2=125822&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp Thu Feb 17 20:44:58 2011
@@ -66,3 +66,24 @@
X x(42.0);
}
+
+namespace PR9188 {
+ struct X0 {
+ union {
+ int member;
+ };
+ };
+
+ static union {
+ int global;
+ };
+
+ struct X1 : X0 {
+ template<typename T>
+ int f() {
+ return this->X0::member + PR9188::global;
+ }
+ };
+
+ template int X1::f<int>();
+}
More information about the cfe-commits
mailing list