https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/123667
Fixes #123524 >From 00b8b64879ad3ae35a0a671da563ac876ffaf228 Mon Sep 17 00:00:00 2001 From: Oleksandr T <oleksandr.taras...@outlook.com> Date: Mon, 20 Jan 2025 22:51:00 +0200 Subject: [PATCH] [Clang] use constant evaluation context for constexpr if conditions --- clang/docs/ReleaseNotes.rst | 2 +- clang/lib/Parse/ParseExprCXX.cpp | 6 ++++++ clang/test/SemaCXX/constexpr-if.cpp | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/constexpr-if.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index f6d5c346021d60..cd16ce13a4e6b6 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -963,7 +963,7 @@ Bug Fixes to C++ Support - Fixed a crash caused by the incorrect construction of template arguments for CTAD alias guides when type constraints are applied. (#GH122134) - Fixed canonicalization of pack indexing types - Clang did not always recognized identical pack indexing. (#GH123033) - +- Clang now permits the use of immediate-escalating expressions in ``constexpr`` if conditions. (#GH123524) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index 33a90e0cb8a42a..e174d9a24e7440 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, SourceLocation Loc, return ParseCXXCondition(nullptr, Loc, CK, MissingOK); } + EnterExpressionEvaluationContext Eval( + Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated, + /*LambdaContextDecl=*/nullptr, + /*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other, + /*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf); + // Parse the expression. ExprResult Expr = ParseExpression(); // expression if (Expr.isInvalid()) diff --git a/clang/test/SemaCXX/constexpr-if.cpp b/clang/test/SemaCXX/constexpr-if.cpp new file mode 100644 index 00000000000000..1832086fee42d4 --- /dev/null +++ b/clang/test/SemaCXX/constexpr-if.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -std=c++26 -verify %s + +// expected-no-diagnostics + +namespace GH123524 { +consteval void fn1() {} +void fn2() { + if constexpr (&fn1 != nullptr) { } +} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits