[Sema] Fix PR35832 - Ambiguity accessing anonymous struct/union with multiple bases.
authorEric Fiselier <eric@efcs.ca>
Sun, 8 Apr 2018 05:50:01 +0000 (05:50 +0000)
committerEric Fiselier <eric@efcs.ca>
Sun, 8 Apr 2018 05:50:01 +0000 (05:50 +0000)
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

llvm-svn: 329519

clang/lib/Sema/SemaExprMember.cpp
clang/test/SemaCXX/PR35832.cpp [new file with mode: 0644]

index c737d7b..680ca99 100644 (file)
@@ -848,7 +848,7 @@ Sema::BuildAnonymousStructUnionMemberReference(const CXXScopeSpec &SS,
     // 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();
diff --git a/clang/test/SemaCXX/PR35832.cpp b/clang/test/SemaCXX/PR35832.cpp
new file mode 100644 (file)
index 0000000..67dd3c1
--- /dev/null
@@ -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; }
+};