[PATCH] D158601: [Clang] Always constant-evaluate operands of comparisons to nullptr
Corentin Jabot via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 24 01:47:06 PDT 2023
cor3ntin updated this revision to Diff 553038.
cor3ntin added a comment.
Rebase
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D158601/new/
https://reviews.llvm.org/D158601
Files:
clang/docs/ReleaseNotes.rst
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/compare-cxx2a.cpp
Index: clang/test/SemaCXX/compare-cxx2a.cpp
===================================================================
--- clang/test/SemaCXX/compare-cxx2a.cpp
+++ clang/test/SemaCXX/compare-cxx2a.cpp
@@ -461,3 +461,21 @@
template<typename T> bool f6() { return 0 < y6; } // expected-note {{instantiation of}}
void g6() { f6<int>(); } // expected-note {{instantiation of}}
}
+
+
+namespace GH64923 {
+using nullptr_t = decltype(nullptr);
+struct MyTask{};
+constexpr MyTask DoAnotherThing() {
+ return {};
+}
+
+constexpr nullptr_t operator++(MyTask &&T); // expected-note 2{{declared here}}
+void DoSomething() {
+ if constexpr (++DoAnotherThing() != nullptr) {} // expected-error {{constexpr if condition is not a constant expression}} \
+ // expected-note {{undefined function 'operator++' cannot be used in a constant expression}}
+
+ if constexpr (nullptr == ++DoAnotherThing()) {} // expected-error {{constexpr if condition is not a constant expression}} \
+ // expected-note {{undefined function 'operator++' cannot be used in a constant expression}}
+}
+}
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -13310,6 +13310,10 @@
// C++11 [expr.rel]p4, [expr.eq]p3: If two operands of type std::nullptr_t
// are compared, the result is true of the operator is <=, >= or ==, and
// false otherwise.
+ LValue Res;
+ if (!EvaluatePointer(E->getLHS(), Res, Info) ||
+ !EvaluatePointer(E->getRHS(), Res, Info))
+ return false;
return Success(CmpResult::Equal, E);
}
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -198,6 +198,11 @@
- Update ``FunctionDeclBitfields.NumFunctionDeclBits``. This fixes:
(`#64171 <https://github.com/llvm/llvm-project/issues/64171>`_).
+- Expressions producing ``nullptr`` are correctly evaluated
+ by the constant interpreter when appearing as the operand
+ of a binary comparision.
+ (`#64923 <https://github.com/llvm/llvm-project/issues/64923>_``)
+
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed an import failure of recursive friend class template.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158601.553038.patch
Type: text/x-patch
Size: 2408 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230824/03c960d1/attachment.bin>
More information about the cfe-commits
mailing list