Skip to content

Commit c784abf

Browse files
committed
[clang][Interp] Delay compiling functions that don't have a body yet
Sometimes, isDefined() returns true, even though the function doesn't have a body yet, but will have one later. This is for example the case when referring to a class member function via a member pointer before the member function has been fully parsed. Reject them at first and compile them later.
1 parent 840c7c6 commit c784abf

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

clang/lib/AST/Interp/ByteCodeEmitter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ Function *ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
147147
assert(Func);
148148
// For not-yet-defined functions, we only create a Function instance and
149149
// compile their body later.
150-
if (!FuncDecl->isDefined()) {
150+
if (!FuncDecl->isDefined() ||
151+
(FuncDecl->willHaveBody() && !FuncDecl->hasBody())) {
151152
Func->setDefined(false);
152153
return Func;
153154
}

clang/test/AST/Interp/memberpointers.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %clang_cc1 -std=c++14 -fexperimental-new-constant-interpreter -verify=expected,both %s
2+
// RUN: %clang_cc1 -std=c++23 -fexperimental-new-constant-interpreter -verify=expected,both %s
23
// RUN: %clang_cc1 -std=c++14 -verify=ref,both %s
4+
// RUN: %clang_cc1 -std=c++23 -verify=ref,both %s
35

46
namespace MemberPointers {
57
struct A {

0 commit comments

Comments
 (0)