[PATCH] D157708: [Sema] Suppress lookup diagnostics when checking reversed operators
Ilya Biryukov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 11 05:41:59 PDT 2023
ilya-biryukov created this revision.
ilya-biryukov added reviewers: shafik, rsmith.
Herald added a project: All.
ilya-biryukov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
The standard specified that Clang should 'search' for members in this
case, which does not involve full lookup and the corresponding checks.
See `[over.match.oper]p4` and `[basic.lookup.general]p3`.
The added test has an example code that breaks.
The change that exposed this behavior is cc1b6668c57170cd440d321037ced89d6a61a9cb <https://reviews.llvm.org/rGcc1b6668c57170cd440d321037ced89d6a61a9cb>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D157708
Files:
clang/lib/Sema/SemaOverload.cpp
clang/test/SemaCXX/cxx20-reversed-operators-search.cpp
Index: clang/test/SemaCXX/cxx20-reversed-operators-search.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/cxx20-reversed-operators-search.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+
+namespace members {
+
+struct X {
+ virtual ~X();
+ virtual bool operator ==(X);
+ bool operator !=(X);
+};
+
+struct Y {
+ virtual ~Y();
+ virtual bool operator ==(Y);
+ bool operator !=(Y);
+};
+
+struct Z : X, Y {
+ virtual bool operator==(Z);
+ bool operator==(X) override;
+ bool operator==(Y) override;
+};
+
+void test() {
+ bool b = Z() == Z();
+}
+
+} // namespace members
+
Index: clang/lib/Sema/SemaOverload.cpp
===================================================================
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -950,7 +950,10 @@
LookupResult Members(S, NotEqOp, OpLoc,
Sema::LookupNameKind::LookupMemberName);
S.LookupQualifiedName(Members, RHSRec->getDecl());
- Members.suppressAccessDiagnostics();
+ // According to [over.match.oper]p4 we should run "search" and not "lookup"
+ // for reversed operators, so suppress diagnostics.
+ Members.suppressDiagnostics();
+
for (NamedDecl *Op : Members)
if (FunctionsCorrespond(S.Context, EqFD, Op->getAsFunction()))
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157708.549355.patch
Type: text/x-patch
Size: 1417 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230811/83fe2a0d/attachment.bin>
More information about the cfe-commits
mailing list