[clang] [clang][bytecode] Don't diagnose definition wihout body (PR #208679)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 10 02:54:42 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/208679
Let the declared_at note point to the declaration in that case.
>From 79454ebee61c23843879489e12168b3c9debb1bc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Fri, 10 Jul 2026 11:52:59 +0200
Subject: [PATCH] [clang][bytecode] Don't diagnose definition wihout body
Let the declared_at note point to the declaration in that case.
---
clang/lib/AST/ByteCode/Interp.cpp | 6 ++++--
clang/test/AST/ByteCode/invalid.cpp | 9 +++++++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index b2af27fc88542..0adcdfe6e78c9 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1110,8 +1110,10 @@ static bool diagnoseCallableDecl(InterpState &S, CodePtr OpPC,
diag::note_constexpr_invalid_function, 1)
<< DiagDecl->isConstexpr() << (bool)CD << DiagDecl;
- if (DiagDecl->getDefinition())
- S.Note(DiagDecl->getDefinition()->getLocation(), diag::note_declared_at);
+ const FunctionDecl *Definition;
+ const Stmt *Body = DiagDecl->getBody(Definition);
+ if (Body && Definition)
+ S.Note(Definition->getLocation(), diag::note_declared_at);
else
S.Note(DiagDecl->getLocation(), diag::note_declared_at);
}
diff --git a/clang/test/AST/ByteCode/invalid.cpp b/clang/test/AST/ByteCode/invalid.cpp
index e79b698a32719..930565181b202 100644
--- a/clang/test/AST/ByteCode/invalid.cpp
+++ b/clang/test/AST/ByteCode/invalid.cpp
@@ -218,3 +218,12 @@ namespace InvalidVirtualCast {
static_assert((X *)(Y *)&z, ""); // both-error {{not an integral constant expression}} \
// both-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
}
+
+namespace DefinitionInBody {
+ int foo(); // both-note {{declared here}}
+ int foo() {
+ static_assert(foo() == 1); // both-error {{not an integral constant expression}} \
+ // both-note {{non-constexpr function 'foo' cannot be used in a constant expression}}
+ return 5;
+ }
+}
More information about the cfe-commits
mailing list