]> granicus.if.org Git - clang/commitdiff
[Sema] Fix PR35832 - Ambiguity accessing anonymous struct/union with multiple bases.
authorEric Fiselier <eric@efcs.ca>
Sun, 8 Apr 2018 06:21:33 +0000 (06:21 +0000)
committerEric Fiselier <eric@efcs.ca>
Sun, 8 Apr 2018 06:21:33 +0000 (06:21 +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

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

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

index c737d7bfd442dbf8cec3fc49ac456b81624201da..680ca99d660e2585a7ca70685373ba36c7e59d29 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();
index 1a35c9dbf7cc83ea952c775220d4dfd5671acbea..4de55506223c5a9df243867ff237be47a3fe0f64 100644 (file)
@@ -2239,7 +2239,6 @@ public:
       // We have a reference to an unnamed field.  This is always the
       // base of an anonymous struct/union member access, i.e. the
       // field is always of record type.
-      assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
       assert(Member->getType()->isRecordType() &&
              "unnamed member not of record type?");
 
diff --git a/test/SemaCXX/PR35832.cpp b/test/SemaCXX/PR35832.cpp
new file mode 100644 (file)
index 0000000..fd47cd6
--- /dev/null
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+class B {
+public:
+ int i;
+ struct {  struct { union { int j; }; };  };
+ union { int k; };
+};
+
+class X : public B { };
+class Y : public B { };
+
+class Z : public X, public Y {
+public:
+ int a() { return X::i; }
+ int b() { return X::j; }
+ int c() { return X::k; }
+ int d() { return this->X::j; }
+};