EricWF created this revision. EricWF added reviewers: rsmith, aaron.ballman, rjmccall. EricWF added a dependency: D45410: [Sema] Remove dead code in BuildAnonymousStructUnionMemberReference. NFCI.
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 }; Repository: rC Clang https://reviews.llvm.org/D45411 Files: lib/Sema/SemaExprMember.cpp test/SemaCXX/PR35832.cpp Index: test/SemaCXX/PR35832.cpp =================================================================== --- /dev/null +++ test/SemaCXX/PR35832.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// expected-no-diagnostics + +class B { +public: + int i; + struct { struct { union { int j; }; }; }; +}; + +auto ptr = &B::j; + +class X : public B { }; +class Y : public B { static B bb; }; + +class Z : public X { +public: + int a() { return X::i; } + int b() { return X::j; } + int c() { return this->X::j; } +}; Index: lib/Sema/SemaExprMember.cpp =================================================================== --- lib/Sema/SemaExprMember.cpp +++ lib/Sema/SemaExprMember.cpp @@ -848,7 +848,7 @@ // 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: test/SemaCXX/PR35832.cpp =================================================================== --- /dev/null +++ test/SemaCXX/PR35832.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// expected-no-diagnostics + +class B { +public: + int i; + struct { struct { union { int j; }; }; }; +}; + +auto ptr = &B::j; + +class X : public B { }; +class Y : public B { static B bb; }; + +class Z : public X { +public: + int a() { return X::i; } + int b() { return X::j; } + int c() { return this->X::j; } +}; Index: lib/Sema/SemaExprMember.cpp =================================================================== --- lib/Sema/SemaExprMember.cpp +++ lib/Sema/SemaExprMember.cpp @@ -848,7 +848,7 @@ // 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();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits