[clang] [clang-tools-extra] [clang] Allow constexpr-unknown values pre C++23 (PR #129646)
A. Jiang via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 5 05:19:44 PDT 2025
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>,"A. Jiang" <de34 at live.cn>,A.
Jiang <de34 at live.cn>
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/4] [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/4] 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
>From 66fb237f90e5e36d055556fd439d4d4521304a8e Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Fri, 5 Sep 2025 19:52:10 +0800
Subject: [PATCH 3/4] Correspondingly update expected diagnostic messages
Except for the regressed one for `constexpr int &n = n;`.
---
clang-tools-extra/clangd/unittests/HoverTests.cpp | 1 +
clang/test/AST/ByteCode/builtin-functions.cpp | 2 +-
clang/test/AST/ByteCode/cxx11.cpp | 4 ++--
clang/test/AST/ByteCode/openmp.cpp | 2 +-
clang/test/CXX/expr/expr.const/p2-0x.cpp | 4 ++--
.../expr.prim/expr.prim.req/simple-requirement.cpp | 3 +--
...stribute_parallel_for_simd_aligned_messages.cpp | 2 +-
.../OpenMP/distribute_simd_aligned_messages.cpp | 2 +-
clang/test/OpenMP/for_simd_aligned_messages.cpp | 2 +-
.../masked_taskloop_simd_aligned_messages.cpp | 2 +-
.../master_taskloop_simd_aligned_messages.cpp | 2 +-
.../OpenMP/parallel_for_simd_aligned_messages.cpp | 2 +-
...allel_masked_taskloop_simd_aligned_messages.cpp | 2 +-
...allel_master_taskloop_simd_aligned_messages.cpp | 2 +-
clang/test/OpenMP/simd_aligned_messages.cpp | 2 +-
.../target_parallel_for_simd_aligned_messages.cpp | 2 +-
clang/test/OpenMP/target_simd_aligned_messages.cpp | 2 +-
...stribute_parallel_for_simd_aligned_messages.cpp | 2 +-
...rget_teams_distribute_simd_aligned_messages.cpp | 2 +-
.../test/OpenMP/taskloop_simd_aligned_messages.cpp | 2 +-
...stribute_parallel_for_simd_aligned_messages.cpp | 2 +-
.../teams_distribute_simd_aligned_messages.cpp | 2 +-
clang/test/SemaCXX/constant-expression-cxx11.cpp | 14 +++++++-------
clang/test/SemaCXX/constexpr-string.cpp | 2 +-
24 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 743c0dc0d0187..666f8f6df8b4f 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -346,6 +346,7 @@ class Foo final {})cpp";
{{"int"}, std::string("T"), std::nullopt},
{{"bool"}, std::string("B"), std::nullopt},
};
+ HI.Value = "false";
return HI;
}},
// Lambda parameter with decltype
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp
index f47bc49d9a1a8..6c08493afe90d 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1398,7 +1398,7 @@ namespace BuiltinMemcpy {
// both-note {{destination of 'memcpy' is (void *)123}}
- constexpr float type_pun(const unsigned &n) {
+ constexpr float type_pun(const unsigned &n) { // expected-error {{constexpr function never produces a constant expression}}
float f = 0.0f;
__builtin_memcpy(&f, &n, 4); // both-note {{cannot constant evaluate 'memcpy' from object of type 'const unsigned int' to object of type 'float'}}
return f;
diff --git a/clang/test/AST/ByteCode/cxx11.cpp b/clang/test/AST/ByteCode/cxx11.cpp
index 72bc7622eb6d8..7c7549cd9fb03 100644
--- a/clang/test/AST/ByteCode/cxx11.cpp
+++ b/clang/test/AST/ByteCode/cxx11.cpp
@@ -210,7 +210,7 @@ namespace GlobalInitializer {
extern int &g; // both-note {{here}}
struct S {
int G : g; // both-error {{constant expression}} \
- // both-note {{initializer of 'g' is unknown}}
+ // both-note {{read of non-constexpr variable 'g' is not allowed in a constant expression}}
};
}
@@ -246,7 +246,7 @@ namespace IntToPtrCast {
}
namespace Volatile {
- constexpr int f(volatile int &&r) {
+ constexpr int f(volatile int &&r) { // expected-error {{constexpr function never produces a constant expression}}
return r; // both-note {{read of volatile-qualified type 'volatile int'}}
}
struct S {
diff --git a/clang/test/AST/ByteCode/openmp.cpp b/clang/test/AST/ByteCode/openmp.cpp
index 15f10a2cd262c..8179276657932 100644
--- a/clang/test/AST/ByteCode/openmp.cpp
+++ b/clang/test/AST/ByteCode/openmp.cpp
@@ -5,7 +5,7 @@ int test1() {
int i;
int &j = i; // both-note {{declared here}}
float *f;
- // both-note at +2 {{initializer of 'j' is not a constant expression}}
+ // both-note at +2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// both-error at +1 {{integral constant expression}}
#pragma omp for simd aligned(f:j)
for (int i = 0; i < 10; ++i);
diff --git a/clang/test/CXX/expr/expr.const/p2-0x.cpp b/clang/test/CXX/expr/expr.const/p2-0x.cpp
index 8401d3033eda9..bc5887ddb1c7f 100644
--- a/clang/test/CXX/expr/expr.const/p2-0x.cpp
+++ b/clang/test/CXX/expr/expr.const/p2-0x.cpp
@@ -411,9 +411,9 @@ namespace References {
int D2 : &d - &c + 1;
int E : e / 2;
int F : f - 11;
- int G : g; // expected-error {{constant expression}} expected-note {{initializer of 'g' is unknown}}
+ int G : g; // expected-error {{constant expression}} expected-note {{read of non-constexpr variable 'g' is not allowed in a constant expression}}
int H : h(); // expected-error {{constant expression}} expected-note {{undefined function 'h'}}
- int I : i; // expected-error {{constant expression}} expected-note {{initializer of 'i' is not a constant expression}}
+ int I : i; // expected-error {{constant expression}} expected-note {{read of non-constexpr variable 'i' is not allowed in a constant expression}}
int J : j();
int K : k;
};
diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp
index 5199708cd8166..a8925deca890b 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp
@@ -104,8 +104,7 @@ class X { virtual ~X(); };
constexpr bool b = requires (X &x) { static_cast<int(*)[(typeid(x), 0)]>(nullptr); };
// expected-warning at -1 {{left operand of comma operator has no effect}}
// expected-warning at -2 {{variable length arrays in C++ are a Clang extension}}
-// expected-note at -3{{function parameter 'x' with unknown value cannot be used in a constant expression}}
-// expected-note at -4{{declared here}}
+// expected-note at -3{{typeid applied to object 'x' whose dynamic type is not constant}}
namespace access_checks {
namespace in_requires_expression {
diff --git a/clang/test/OpenMP/distribute_parallel_for_simd_aligned_messages.cpp b/clang/test/OpenMP/distribute_parallel_for_simd_aligned_messages.cpp
index 960177cf7dda7..c6dab16dc05bc 100644
--- a/clang/test/OpenMP/distribute_parallel_for_simd_aligned_messages.cpp
+++ b/clang/test/OpenMP/distribute_parallel_for_simd_aligned_messages.cpp
@@ -221,7 +221,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp target
#pragma omp teams
-#pragma omp distribute parallel for simd aligned(f:j) // expected-note {{initializer of 'j' is not a constant expression}} expected-error {{integral constant expression}}
+#pragma omp distribute parallel for simd aligned(f:j) // expected-note {{read of non-constexpr variable 'j' is not allowed in a constant expression}} expected-error {{integral constant expression}}
for (I k = 0; k < argc; ++k) { ++k; v += j; }
diff --git a/clang/test/OpenMP/distribute_simd_aligned_messages.cpp b/clang/test/OpenMP/distribute_simd_aligned_messages.cpp
index 6f1dd7d2552d9..65cbb0d39058d 100644
--- a/clang/test/OpenMP/distribute_simd_aligned_messages.cpp
+++ b/clang/test/OpenMP/distribute_simd_aligned_messages.cpp
@@ -221,7 +221,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp target
#pragma omp teams
-#pragma omp distribute simd aligned(f:j) // expected-note {{initializer of 'j' is not a constant expression}} expected-error {{integral constant expression}}
+#pragma omp distribute simd aligned(f:j) // expected-note {{read of non-constexpr variable 'j' is not allowed in a constant expression}} expected-error {{integral constant expression}}
for (I k = 0; k < argc; ++k) { ++k; v += j; }
diff --git a/clang/test/OpenMP/for_simd_aligned_messages.cpp b/clang/test/OpenMP/for_simd_aligned_messages.cpp
index e925d00139f91..72e949e67a11c 100644
--- a/clang/test/OpenMP/for_simd_aligned_messages.cpp
+++ b/clang/test/OpenMP/for_simd_aligned_messages.cpp
@@ -150,7 +150,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp for simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
- // expected-note at +2 {{initializer of 'j' is not a constant expression}}
+ // expected-note at +2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error at +1 {{integral constant expression}}
#pragma omp for simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
diff --git a/clang/test/OpenMP/masked_taskloop_simd_aligned_messages.cpp b/clang/test/OpenMP/masked_taskloop_simd_aligned_messages.cpp
index 8c0ae171fa401..a9d4c35ae26f3 100644
--- a/clang/test/OpenMP/masked_taskloop_simd_aligned_messages.cpp
+++ b/clang/test/OpenMP/masked_taskloop_simd_aligned_messages.cpp
@@ -150,7 +150,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp masked taskloop simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
- // expected-note at +2 {{initializer of 'j' is not a constant expression}}
+ // expected-note at +2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error at +1 {{integral constant expression}}
#pragma omp masked taskloop simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
diff --git a/clang/test/OpenMP/master_taskloop_simd_aligned_messages.cpp b/clang/test/OpenMP/master_taskloop_simd_aligned_messages.cpp
index c2c56dfdb458e..769281e5796b0 100644
--- a/clang/test/OpenMP/master_taskloop_simd_aligned_messages.cpp
+++ b/clang/test/OpenMP/master_taskloop_simd_aligned_messages.cpp
@@ -150,7 +150,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp master taskloop simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
- // expected-note at +2 {{initializer of 'j' is not a constant expression}}
+ // expected-note at +2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error at +1 {{integral constant expression}}
#pragma omp master taskloop simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
diff --git a/clang/test/OpenMP/parallel_for_simd_aligned_messages.cpp b/clang/test/OpenMP/parallel_for_simd_aligned_messages.cpp
index e9ef234def244..9079676524c12 100644
--- a/clang/test/OpenMP/parallel_for_simd_aligned_messages.cpp
+++ b/clang/test/OpenMP/parallel_for_simd_aligned_messages.cpp
@@ -150,7 +150,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp parallel for simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
- // expected-note at +2 {{initializer of 'j' is not a constant expression}}
+ // expected-note at +2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error at +1 {{integral constant expression}}
#pragma omp parallel for simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
diff --git a/clang/test/OpenMP/parallel_masked_taskloop_simd_aligned_messages.cpp b/clang/test/OpenMP/parallel_masked_taskloop_simd_aligned_messages.cpp
index 2cd13d65c8600..615b653786493 100644
--- a/clang/test/OpenMP/parallel_masked_taskloop_simd_aligned_messages.cpp
+++ b/clang/test/OpenMP/parallel_masked_taskloop_simd_aligned_messages.cpp
@@ -150,7 +150,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp parallel masked taskloop simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
- // expected-note at +2 {{initializer of 'j' is not a constant expression}}
+ // expected-note at +2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error at +1 {{integral constant expression}}
#pragma omp parallel masked taskloop simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
diff --git a/clang/test/OpenMP/parallel_master_taskloop_simd_aligned_messages.cpp b/clang/test/OpenMP/parallel_master_taskloop_simd_aligned_messages.cpp
index c6a5f6b90d3a6..14c91f8b15c03 100644
--- a/clang/test/OpenMP/parallel_master_taskloop_simd_aligned_messages.cpp
+++ b/clang/test/OpenMP/parallel_master_taskloop_simd_aligned_messages.cpp
@@ -150,7 +150,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp parallel master taskloop simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
- // expected-note at +2 {{initializer of 'j' is not a constant expression}}
+ // expected-note at +2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error at +1 {{integral constant expression}}
#pragma omp parallel master taskloop simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
diff --git a/clang/test/OpenMP/simd_aligned_messages.cpp b/clang/test/OpenMP/simd_aligned_messages.cpp
index f34eabd37e452..d2495c6e29a4f 100644
--- a/clang/test/OpenMP/simd_aligned_messages.cpp
+++ b/clang/test/OpenMP/simd_aligned_messages.cpp
@@ -152,7 +152,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
- // expected-note at +2 {{initializer of 'j' is not a constant expression}}
+ // expected-note at +2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error at +1 {{integral constant expression}}
#pragma omp simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
diff --git a/clang/test/OpenMP/target_parallel_for_simd_aligned_messages.cpp b/clang/test/OpenMP/target_parallel_for_simd_aligned_messages.cpp
index c635663431f6c..81ff62c5f4b16 100644
--- a/clang/test/OpenMP/target_parallel_for_simd_aligned_messages.cpp
+++ b/clang/test/OpenMP/target_parallel_for_simd_aligned_messages.cpp
@@ -150,7 +150,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp target parallel for simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
- // expected-note at +2 {{initializer of 'j' is not a constant expression}}
+ // expected-note at +2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error at +1 {{integral constant expression}}
#pragma omp target parallel for simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
diff --git a/clang/test/OpenMP/target_simd_aligned_messages.cpp b/clang/test/OpenMP/target_simd_aligned_messages.cpp
index e3b9ec47fba01..60504825349ed 100644
--- a/clang/test/OpenMP/target_simd_aligned_messages.cpp
+++ b/clang/test/OpenMP/target_simd_aligned_messages.cpp
@@ -150,7 +150,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp target simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
- // expected-note at +2 {{initializer of 'j' is not a constant expression}}
+ // expected-note at +2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error at +1 {{integral constant expression}}
#pragma omp target simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
diff --git a/clang/test/OpenMP/target_teams_distribute_parallel_for_simd_aligned_messages.cpp b/clang/test/OpenMP/target_teams_distribute_parallel_for_simd_aligned_messages.cpp
index 40041bebced95..6b2d530448790 100644
--- a/clang/test/OpenMP/target_teams_distribute_parallel_for_simd_aligned_messages.cpp
+++ b/clang/test/OpenMP/target_teams_distribute_parallel_for_simd_aligned_messages.cpp
@@ -167,7 +167,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
int v = 0;
-#pragma omp target teams distribute parallel for simd aligned(f:j) // expected-note {{initializer of 'j' is not a constant expression}} expected-error {{integral constant expression}}
+#pragma omp target teams distribute parallel for simd aligned(f:j) // expected-note {{read of non-constexpr variable 'j' is not allowed in a constant expression}} expected-error {{integral constant expression}}
for (I k = 0; k < argc; ++k) { ++k; v += j; }
diff --git a/clang/test/OpenMP/target_teams_distribute_simd_aligned_messages.cpp b/clang/test/OpenMP/target_teams_distribute_simd_aligned_messages.cpp
index 8f634db9aff0c..a647319e490aa 100644
--- a/clang/test/OpenMP/target_teams_distribute_simd_aligned_messages.cpp
+++ b/clang/test/OpenMP/target_teams_distribute_simd_aligned_messages.cpp
@@ -167,7 +167,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
int v = 0;
-#pragma omp target teams distribute simd aligned(f:j) // expected-note {{initializer of 'j' is not a constant expression}} expected-error {{integral constant expression}}
+#pragma omp target teams distribute simd aligned(f:j) // expected-note {{read of non-constexpr variable 'j' is not allowed in a constant expression}} expected-error {{integral constant expression}}
for (I k = 0; k < argc; ++k) { ++k; v += j; }
diff --git a/clang/test/OpenMP/taskloop_simd_aligned_messages.cpp b/clang/test/OpenMP/taskloop_simd_aligned_messages.cpp
index aa3331a0e249f..5edbb7f3b99a2 100644
--- a/clang/test/OpenMP/taskloop_simd_aligned_messages.cpp
+++ b/clang/test/OpenMP/taskloop_simd_aligned_messages.cpp
@@ -150,7 +150,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
#pragma omp taskloop simd aligned(f)
for (I k = 0; k < argc; ++k) ++k;
int v = 0;
- // expected-note at +2 {{initializer of 'j' is not a constant expression}}
+ // expected-note at +2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
// expected-error at +1 {{integral constant expression}}
#pragma omp taskloop simd aligned(f:j)
for (I k = 0; k < argc; ++k) { ++k; v += j; }
diff --git a/clang/test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp b/clang/test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp
index 5c331e34382a1..6e87d037a7e7b 100644
--- a/clang/test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp
+++ b/clang/test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp
@@ -195,7 +195,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
int v = 0;
#pragma omp target
-#pragma omp teams distribute parallel for simd aligned(f:j) // expected-note {{initializer of 'j' is not a constant expression}} expected-error {{integral constant expression}}
+#pragma omp teams distribute parallel for simd aligned(f:j) // expected-note {{read of non-constexpr variable 'j' is not allowed in a constant expression}} expected-error {{integral constant expression}}
for (I k = 0; k < argc; ++k) { ++k; v += j; }
diff --git a/clang/test/OpenMP/teams_distribute_simd_aligned_messages.cpp b/clang/test/OpenMP/teams_distribute_simd_aligned_messages.cpp
index 7fa78b5735ac4..3d53a0da9f10c 100644
--- a/clang/test/OpenMP/teams_distribute_simd_aligned_messages.cpp
+++ b/clang/test/OpenMP/teams_distribute_simd_aligned_messages.cpp
@@ -196,7 +196,7 @@ template<class I, class C> int foomain(I argc, C **argv) {
int v = 0;
#pragma omp target
-#pragma omp teams distribute simd aligned(f:j) // expected-note {{initializer of 'j' is not a constant expression}} expected-error {{integral constant expression}}
+#pragma omp teams distribute simd aligned(f:j) // expected-note {{read of non-constexpr variable 'j' is not allowed in a constant expression}} expected-error {{integral constant expression}}
for (I k = 0; k < argc; ++k) { ++k; v += j; }
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 91c4ff1cb520d..a3b1b988eef71 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1354,7 +1354,7 @@ constexpr int m2b = const_cast<const int&>(n2); // expected-error {{constant exp
struct T { int n; };
const T t = { 42 }; // expected-note {{declared here}}
-constexpr int f(volatile int &&r) {
+constexpr int f(volatile int &&r) { // cxx11_20-error {{constexpr function never produces a constant expression}}
return r; // expected-note {{read of volatile-qualified type 'volatile int'}}
}
constexpr int g(volatile int &&r) {
@@ -1475,9 +1475,9 @@ namespace ConvertedConstantExpr {
// useless note and instead just point to the non-constant subexpression.
enum class E {
em = m,
- en = n, // expected-error {{enumerator value is not a constant expression}} cxx11_20-note {{initializer of 'n' is unknown}} cxx23-note {{read of non-constexpr variable 'n'}}
+ en = n, // expected-error {{enumerator value is not a constant expression}} expected-note {{read of non-constexpr variable 'n'}}
eo = (m + // expected-error {{not a constant expression}}
- n // cxx11_20-note {{initializer of 'n' is unknown}} cxx23-note {{read of non-constexpr variable 'n'}}
+ n // expected-note {{read of non-constexpr variable 'n'}}
),
eq = reinterpret_cast<long>((int*)0) // expected-error {{not a constant expression}} expected-note {{reinterpret_cast}}
};
@@ -2435,15 +2435,15 @@ namespace array_size {
template<typename T> void f1(T t) {
constexpr int k = t.size();
}
- template<typename T> void f2(const T &t) { // cxx11_20-note 2{{declared here}}
- constexpr int k = t.size(); // cxx11_20-error 2{{constexpr variable 'k' must be initialized by a constant expression}} cxx11_20-note 2{{function parameter 't' with unknown value cannot be used in a constant expression}}
+ template<typename T> void f2(const T &t) {
+ constexpr int k = t.size();
}
template<typename T> void f3(const T &t) {
constexpr int k = T::size();
}
void g(array<3> a) {
f1(a);
- f2(a); // cxx11_20-note {{in instantiation of function template}}
+ f2(a);
f3(a);
}
@@ -2452,7 +2452,7 @@ namespace array_size {
};
void h(array_nonstatic<3> a) {
f1(a);
- f2(a); // cxx11_20-note {{instantiation of}}
+ f2(a);
}
//static_assert(f2(array_size::array<3>{}));
}
diff --git a/clang/test/SemaCXX/constexpr-string.cpp b/clang/test/SemaCXX/constexpr-string.cpp
index c456740ef7551..fed4034e96155 100644
--- a/clang/test/SemaCXX/constexpr-string.cpp
+++ b/clang/test/SemaCXX/constexpr-string.cpp
@@ -615,7 +615,7 @@ namespace MemcpyEtc {
static_assert(test_nontrivial_memmove()); // expected-error {{constant}} expected-note {{in call}}
// Type puns via constant evaluated memcpy are not supported yet.
- constexpr float type_pun(const unsigned &n) {
+ constexpr float type_pun(const unsigned &n) { // expected-error {{constexpr function never produces a constant expression}}
float f = 0.0f;
__builtin_memcpy(&f, &n, 4); // expected-note {{cannot constant evaluate 'memcpy' from object of type 'const unsigned int' to object of type 'float'}}
return f;
>From 078b1f245b3d49e15ff7a81f4da17ef945d44a4f Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Fri, 5 Sep 2025 20:19:28 +0800
Subject: [PATCH 4/4] Fixup for ByteCode tests
---
clang/test/AST/ByteCode/builtin-functions.cpp | 2 +-
clang/test/AST/ByteCode/cxx11.cpp | 4 ++--
clang/test/AST/ByteCode/openmp.cpp | 3 ++-
3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp
index 6c08493afe90d..3d952c5bcc20d 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1398,7 +1398,7 @@ namespace BuiltinMemcpy {
// both-note {{destination of 'memcpy' is (void *)123}}
- constexpr float type_pun(const unsigned &n) { // expected-error {{constexpr function never produces a constant expression}}
+ constexpr float type_pun(const unsigned &n) { // ref-error {{constexpr function never produces a constant expression}}
float f = 0.0f;
__builtin_memcpy(&f, &n, 4); // both-note {{cannot constant evaluate 'memcpy' from object of type 'const unsigned int' to object of type 'float'}}
return f;
diff --git a/clang/test/AST/ByteCode/cxx11.cpp b/clang/test/AST/ByteCode/cxx11.cpp
index 7c7549cd9fb03..c69be604bffc6 100644
--- a/clang/test/AST/ByteCode/cxx11.cpp
+++ b/clang/test/AST/ByteCode/cxx11.cpp
@@ -210,7 +210,7 @@ namespace GlobalInitializer {
extern int &g; // both-note {{here}}
struct S {
int G : g; // both-error {{constant expression}} \
- // both-note {{read of non-constexpr variable 'g' is not allowed in a constant expression}}
+ // ref-note {{read of non-constexpr variable 'g' is not allowed in a constant expression}} expected-note {{initializer of 'g' is unknown}}
};
}
@@ -246,7 +246,7 @@ namespace IntToPtrCast {
}
namespace Volatile {
- constexpr int f(volatile int &&r) { // expected-error {{constexpr function never produces a constant expression}}
+ constexpr int f(volatile int &&r) { // ref-error {{constexpr function never produces a constant expression}}
return r; // both-note {{read of volatile-qualified type 'volatile int'}}
}
struct S {
diff --git a/clang/test/AST/ByteCode/openmp.cpp b/clang/test/AST/ByteCode/openmp.cpp
index 8179276657932..e615550cb94d8 100644
--- a/clang/test/AST/ByteCode/openmp.cpp
+++ b/clang/test/AST/ByteCode/openmp.cpp
@@ -5,7 +5,8 @@ int test1() {
int i;
int &j = i; // both-note {{declared here}}
float *f;
- // both-note at +2 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
+ // ref-note at +3 {{read of non-constexpr variable 'j' is not allowed in a constant expression}}
+ // expected-note at +2 {{initializer of 'j' is not a constant expression}}
// both-error at +1 {{integral constant expression}}
#pragma omp for simd aligned(f:j)
for (int i = 0; i < 10; ++i);
More information about the cfe-commits
mailing list