[clang] [clang] Allow constexpr-unknown values pre C++23 (PR #129646)
A. Jiang via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 15 23:32:24 PDT 2025
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/129646 at github.com>
https://github.com/frederick-vs-ja updated https://github.com/llvm/llvm-project/pull/129646
>From 54c3e72e2c3b507ecf8cd65c15b9e137ba7331c5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Tue, 4 Mar 2025 06:29:31 +0100
Subject: [PATCH 1/2] [clang] Alloc constexpr-unknown values pre C++23
Let's check the CI.
---
clang/lib/AST/ExprConstant.cpp | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6ccb6e23f8d2f..9ea42b308f42c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -3470,8 +3470,7 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E,
unsigned Version, APValue *&Result) {
// C++23 [expr.const]p8 If we have a reference type allow unknown references
// and pointers.
- bool AllowConstexprUnknown =
- Info.getLangOpts().CPlusPlus23 && VD->getType()->isReferenceType();
+ bool AllowConstexprUnknown = VD->getType()->isReferenceType();
APValue::LValueBase Base(VD, Frame ? Frame->Index : 0, Version);
@@ -8893,8 +8892,7 @@ bool LValueExprEvaluator::VisitDeclRefExpr(const DeclRefExpr *E) {
bool LValueExprEvaluator::VisitVarDecl(const Expr *E, const VarDecl *VD) {
// C++23 [expr.const]p8 If we have a reference type allow unknown references
// and pointers.
- bool AllowConstexprUnknown =
- Info.getLangOpts().CPlusPlus23 && VD->getType()->isReferenceType();
+ bool AllowConstexprUnknown = VD->getType()->isReferenceType();
// If we are within a lambda's call operator, check whether the 'VD' referred
// to within 'E' actually represents a lambda-capture that maps to a
// data-member/field within the closure object, and if so, evaluate to the
>From caed48e3648e3be46e63587c522f14d6e6559665 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Tue, 4 Mar 2025 07:57:45 +0100
Subject: [PATCH 2/2] allow in c++11 and later
---
clang/lib/AST/ExprConstant.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 9ea42b308f42c..06fd018677d41 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -3470,7 +3470,8 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E,
unsigned Version, APValue *&Result) {
// C++23 [expr.const]p8 If we have a reference type allow unknown references
// and pointers.
- bool AllowConstexprUnknown = VD->getType()->isReferenceType();
+ bool AllowConstexprUnknown =
+ Info.getLangOpts().CPlusPlus11 && VD->getType()->isReferenceType();
APValue::LValueBase Base(VD, Frame ? Frame->Index : 0, Version);
@@ -8892,7 +8893,8 @@ bool LValueExprEvaluator::VisitDeclRefExpr(const DeclRefExpr *E) {
bool LValueExprEvaluator::VisitVarDecl(const Expr *E, const VarDecl *VD) {
// C++23 [expr.const]p8 If we have a reference type allow unknown references
// and pointers.
- bool AllowConstexprUnknown = VD->getType()->isReferenceType();
+ bool AllowConstexprUnknown =
+ Info.getLangOpts().CPlusPlus11 && VD->getType()->isReferenceType();
// If we are within a lambda's call operator, check whether the 'VD' referred
// to within 'E' actually represents a lambda-capture that maps to a
// data-member/field within the closure object, and if so, evaluate to the
More information about the cfe-commits
mailing list