[clang] [clang][bytecode] Don't diagnose defined functions that will have a body (PR #165002)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 24 08:39:43 PDT 2025
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/165002
But don't have one, yet. That happens for class methods, which are "defined" but have no body, hence they willHaveBody.
Fixes https://github.com/llvm/llvm-project/issues/164995
>From ff32dd724382e73b49bda089aa1f1ca70802ff85 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Fri, 24 Oct 2025 17:38:16 +0200
Subject: [PATCH] [clang][bytecode] Don't diagnose defined functions that will
have a body
But don't have one, yet. That happens for class methods, which are
"defined" but have no body, hence they willHaveBody.
Fixes https://github.com/llvm/llvm-project/issues/164995
---
clang/lib/AST/ByteCode/Interp.cpp | 2 +-
clang/test/AST/ByteCode/records.cpp | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index a72282caf5e73..40e66153a5b11 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -997,7 +997,7 @@ static bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
// If the declaration is defined, declared 'constexpr' _and_ has a body,
// the below diagnostic doesn't add anything useful.
if (DiagDecl->isDefined() && DiagDecl->isConstexpr() &&
- DiagDecl->hasBody())
+ (DiagDecl->hasBody() || DiagDecl->willHaveBody()))
return false;
S.FFDiag(S.Current->getLocation(OpPC),
diff --git a/clang/test/AST/ByteCode/records.cpp b/clang/test/AST/ByteCode/records.cpp
index 00218ba02bb31..02dd26fa15394 100644
--- a/clang/test/AST/ByteCode/records.cpp
+++ b/clang/test/AST/ByteCode/records.cpp
@@ -1861,3 +1861,12 @@ namespace PrimitiveInitializedByInitList {
} c{ 17 };
static_assert(c.b == 17, "");
}
+
+namespace MethodWillHaveBody {
+ class A {
+ public:
+ static constexpr int get_value2() { return 1 + get_value(); }
+ static constexpr int get_value() { return 1; }
+ };
+ static_assert(A::get_value2() == 2, "");
+}
More information about the cfe-commits
mailing list