[Clang][Sema] Fix regression due to missing ambiguity check before attempting access check. (#80730)

Previously when fixing ambiguous lookup diagnostics in
cc1b6668c57170cd440d321037ced89d6a61a9cb The change refactored
`LookupResult` to split out diagnosing access and ambiguous lookups. The
call to `getSema().CheckLookupAccess(...)` should have guarded by a
check for isAmbiguous(). This change adds that guard.

Fixes: https://github.com/llvm/llvm-project/issues/80435
This commit is contained in:
Shafik Yaghmour 2024-02-05 14:40:07 -08:00 committed by GitHub
parent 8ce036d539
commit a7bc9cb6ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View File

@ -754,7 +754,8 @@ public:
private:
void diagnoseAccess() {
if (isClassLookup() && getSema().getLangOpts().AccessControl)
if (!isAmbiguous() && isClassLookup() &&
getSema().getLangOpts().AccessControl)
getSema().CheckLookupAccess(*this);
}

View File

@ -23,3 +23,25 @@ struct D: I1, I2, B2 {
int D::* mpD = &D::i; // expected-error {{non-static member 'i' found in multiple base-class subobjects of type 'B1'}}
}
};
namespace GH80435 {
struct A {
void *data; // expected-note {{member found by ambiguous name lookup}}
};
class B {
void *data; // expected-note {{member found by ambiguous name lookup}}
};
struct C : A, B {};
decltype(C().data) x; // expected-error {{member 'data' found in multiple base classes of different types}}
struct D { // expected-note {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'C' to 'const D' for 1st argument}}
// expected-note@-1{{candidate constructor (the implicit move constructor) not viable: no known conversion from 'C' to 'D' for 1st argument}}
template <typename Container, decltype(Container().data) = 0 >
D(Container); // expected-note {{candidate template ignored: substitution failure [with Container = C]: member 'data' found in multiple base classes of different types}}
};
D y(C{}); // expected-error {{no matching constructor for initialization of 'D'}}
}