-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clang][bytecode] Don't diagnose defined functions that will have a body #165002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesBut don't have one, yet. That happens for class methods, which are "defined" but have no body, hence they willHaveBody. Fixes #164995 Full diff: https://github.com/llvm/llvm-project/pull/165002.diff 2 Files Affected:
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, "");
+}
|
shafik
approved these changes
Oct 24, 2025
Contributor
Author
|
This breaks template<typename T> constexpr T f(T);
template<typename T> constexpr T g(T t) {
// FIXME: It'd be nice to say that the function is currently being defined, rather than being undefined.
typedef int arr[f(T())]; // expected-error {{variable length array}} expected-note {{undefined function 'f<int>'}}
return t;
}
template<typename T> constexpr T f(T t) { // expected-note {{declared here}}
typedef int arr[g(T())]; // expected-error {{zero size array}} expected-note {{instantiation of}}
return t;
}
int n = f(0); // expected-note 2{{instantiation of}} |
ff32dd7 to
9cb1447
Compare
9cb1447 to
8a8363a
Compare
But don't have one, yet. That happens for class methods, which are "defined" but have no body, hence they willHaveBody. Fixes llvm#164995
8a8363a to
11b3be1
Compare
dvbuka
pushed a commit
to dvbuka/llvm-project
that referenced
this pull request
Oct 27, 2025
…ody (llvm#165002) Don't use `hasBody()`, which checks all declarations. Fixes llvm#164995
Lukacma
pushed a commit
to Lukacma/llvm-project
that referenced
this pull request
Oct 29, 2025
…ody (llvm#165002) Don't use `hasBody()`, which checks all declarations. Fixes llvm#164995
aokblast
pushed a commit
to aokblast/llvm-project
that referenced
this pull request
Oct 30, 2025
…ody (llvm#165002) Don't use `hasBody()`, which checks all declarations. Fixes llvm#164995
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:bytecode
Issues for the clang bytecode constexpr interpreter
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Don't use
hasBody(), which checks all declarations.Fixes #164995