Skip to content

Commit

Permalink
[Clang][Sema] Fix regression due to missing ambiguity check before at…
Browse files Browse the repository at this point in the history
…tempting access check.

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
  • Loading branch information
shafik committed Feb 5, 2024
1 parent 5942868 commit 1795bc0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ Bug Fixes to C++ Support
parameter where we did an incorrect specialization of the initialization of
the default parameter.
Fixes (`#68490 <https://github.com/llvm/llvm-project/issues/68490>`_)
- Fix regression due missing ambiguity check before checking lookup access.
Fixes (`80435 <https://github.com/llvm/llvm-project/issues/80435>`_)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
3 changes: 2 additions & 1 deletion clang/include/clang/Sema/Lookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,8 @@ class LookupResult {

private:
void diagnoseAccess() {
if (isClassLookup() && getSema().getLangOpts().AccessControl)
if (!isAmbiguous() && isClassLookup() &&
getSema().getLangOpts().AccessControl)
getSema().CheckLookupAccess(*this);
}

Expand Down
22 changes: 22 additions & 0 deletions clang/test/CXX/class.derived/class.member.lookup/p11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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'}}
}

0 comments on commit 1795bc0

Please sign in to comment.