diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -198,6 +198,11 @@ - Update ``FunctionDeclBitfields.NumFunctionDeclBits``. This fixes: (`#64171 `_). +- Expressions producing ``nullptr`` are correctly evaluated + by the constant interpreter when appearing as the operand + of a binary comparision. + (`#64923 _``) + Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ - Fixed an import failure of recursive friend class template. diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp --- a/clang/lib/AST/ExprConstant.cpp +++ b/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); } diff --git a/clang/test/SemaCXX/compare-cxx2a.cpp b/clang/test/SemaCXX/compare-cxx2a.cpp --- a/clang/test/SemaCXX/compare-cxx2a.cpp +++ b/clang/test/SemaCXX/compare-cxx2a.cpp @@ -461,3 +461,21 @@ template bool f6() { return 0 < y6; } // expected-note {{instantiation of}} void g6() { f6(); } // 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}} +} +}