[clang] 5a5f535 - [c++20] Fix handling of operator rewrites naming consteval operator<=>.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 29 19:03:30 PDT 2020
Author: Richard Smith
Date: 2020-06-29T19:02:47-07:00
New Revision: 5a5f5350e1cbe14eaf852d9003523c7fdb1132af
URL: https://github.com/llvm/llvm-project/commit/5a5f5350e1cbe14eaf852d9003523c7fdb1132af
DIFF: https://github.com/llvm/llvm-project/commit/5a5f5350e1cbe14eaf852d9003523c7fdb1132af.diff
LOG: [c++20] Fix handling of operator rewrites naming consteval operator<=>.
Added:
Modified:
clang/lib/Sema/SemaOverload.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 038b814e3aff..d68be854aeeb 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -13506,6 +13506,10 @@ ExprResult Sema::CreateOverloadedBinOp(SourceLocation OpLoc,
if (R.isInvalid())
return ExprError();
+ R = CheckForImmediateInvocation(R, FnDecl);
+ if (R.isInvalid())
+ return ExprError();
+
// For a rewritten candidate, we've already reversed the arguments
// if needed. Perform the rest of the rewrite now.
if ((Best->RewriteKind & CRK_DifferentOperator) ||
@@ -13541,7 +13545,7 @@ ExprResult Sema::CreateOverloadedBinOp(SourceLocation OpLoc,
if (Best->RewriteKind != CRK_None)
R = new (Context) CXXRewrittenBinaryOperator(R.get(), IsReversed);
- return CheckForImmediateInvocation(R, FnDecl);
+ return R;
} else {
// We matched a built-in operator. Convert the arguments, then
// break out so that we will build the appropriate built-in
diff --git a/clang/test/SemaCXX/cxx2a-consteval.cpp b/clang/test/SemaCXX/cxx2a-consteval.cpp
index 0a6d137e9670..3231107add09 100644
--- a/clang/test/SemaCXX/cxx2a-consteval.cpp
+++ b/clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -476,6 +476,25 @@ namespace override {
}
}
+namespace operator_rewrite {
+ struct A {
+ friend consteval int operator<=>(const A&, const A&) { return 0; }
+ };
+ const bool k = A() < A();
+ static_assert(!k);
+
+ A a;
+ bool k2 = A() < a; // OK, does not access 'a'.
+
+ struct B {
+ friend consteval int operator<=>(const B &l, const B &r) { return r.n - l.n; } // expected-note {{read of }}
+ int n;
+ };
+ static_assert(B() >= B());
+ B b; // expected-note {{here}}
+ bool k3 = B() < b; // expected-error-re {{call to consteval function '{{.*}}::operator<=>' is not a constant expression}} expected-note {{in call}}
+}
+
struct A {
int(*ptr)();
consteval A(int(*p)() = nullptr) : ptr(p) {}
More information about the cfe-commits
mailing list