r329519 - [Sema] Fix PR35832 - Ambiguity accessing anonymous struct/union with multiple bases.
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 7 22:50:01 PDT 2018
Author: ericwf
Date: Sat Apr 7 22:50:01 2018
New Revision: 329519
URL: http://llvm.org/viewvc/llvm-project?rev=329519&view=rev
Log:
[Sema] Fix PR35832 - Ambiguity accessing anonymous struct/union with multiple bases.
Summary:
Currently clang doesn't do qualified lookup when building indirect field decl references. This causes ambiguity when the field is in a base class to which there are multiple valid paths even though a qualified name is used.
For example:
```
class B {
protected:
int i;
union { int j; };
};
class X : public B { };
class Y : public B { };
class Z : public X, public Y {
int a() { return X::i; } // works
int b() { return X::j; } // fails
};
```
Reviewers: rsmith, aaron.ballman, rjmccall
Reviewed By: rjmccall
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D45411
Added:
cfe/trunk/test/SemaCXX/PR35832.cpp
Modified:
cfe/trunk/lib/Sema/SemaExprMember.cpp
Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=329519&r1=329518&r2=329519&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Sat Apr 7 22:50:01 2018
@@ -848,7 +848,7 @@ Sema::BuildAnonymousStructUnionMemberRef
// Build the first member access in the chain with full information.
result =
BuildFieldReferenceExpr(result, baseObjectIsPointer, SourceLocation(),
- EmptySS, field, foundDecl, memberNameInfo)
+ SS, field, foundDecl, memberNameInfo)
.get();
if (!result)
return ExprError();
Added: cfe/trunk/test/SemaCXX/PR35832.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR35832.cpp?rev=329519&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/PR35832.cpp (added)
+++ cfe/trunk/test/SemaCXX/PR35832.cpp Sat Apr 7 22:50:01 2018
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+class B {
+public:
+ int i;
+ struct { struct { union { int j; }; }; };
+};
+
+class X : public B { };
+class Y : public B { };
+
+class Z : public X, Y {
+public:
+ int a() { return X::i; }
+ int b() { return X::j; }
+ int c() { return this->X::j; }
+};
More information about the cfe-commits
mailing list