Skip to content

Commit 2427c85

Browse files
shafiktstellar
authored andcommitted
[Clang][Sema] Fix regression due to missing ambiguity check before attempting access check. (#80730)
Previously when fixing ambiguous lookup diagnostics in cc1b666 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: #80435 (cherry picked from commit a7bc9cb)
1 parent 73cd40d commit 2427c85

File tree

2 files changed

+24
-1
lines changed
  • clang
    • include/clang/Sema
    • test/CXX/class.derived/class.member.lookup

2 files changed

+24
-1
lines changed

clang/include/clang/Sema/Lookup.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,8 @@ class LookupResult {
754754

755755
private:
756756
void diagnoseAccess() {
757-
if (isClassLookup() && getSema().getLangOpts().AccessControl)
757+
if (!isAmbiguous() && isClassLookup() &&
758+
getSema().getLangOpts().AccessControl)
758759
getSema().CheckLookupAccess(*this);
759760
}
760761

clang/test/CXX/class.derived/class.member.lookup/p11.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,25 @@ struct D: I1, I2, B2 {
2323
int D::* mpD = &D::i; // expected-error {{non-static member 'i' found in multiple base-class subobjects of type 'B1'}}
2424
}
2525
};
26+
27+
namespace GH80435 {
28+
struct A {
29+
void *data; // expected-note {{member found by ambiguous name lookup}}
30+
};
31+
32+
class B {
33+
void *data; // expected-note {{member found by ambiguous name lookup}}
34+
};
35+
36+
struct C : A, B {};
37+
38+
decltype(C().data) x; // expected-error {{member 'data' found in multiple base classes of different types}}
39+
40+
struct D { // expected-note {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'C' to 'const D' for 1st argument}}
41+
// expected-note@-1{{candidate constructor (the implicit move constructor) not viable: no known conversion from 'C' to 'D' for 1st argument}}
42+
template <typename Container, decltype(Container().data) = 0 >
43+
D(Container); // expected-note {{candidate template ignored: substitution failure [with Container = C]: member 'data' found in multiple base classes of different types}}
44+
};
45+
46+
D y(C{}); // expected-error {{no matching constructor for initialization of 'D'}}
47+
}

0 commit comments

Comments
 (0)