Skip to content

Commit 69d740e

Browse files
committed
[clang][Interp] Fix creating functions with explicit instance parameters
1 parent d98a785 commit 69d740e

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

clang/lib/AST/Interp/ByteCodeEmitter.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,13 @@ Function *ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
8282
// InterpStack when calling the function.
8383
bool HasThisPointer = false;
8484
if (const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl)) {
85-
if (MD->isImplicitObjectMemberFunction() && !IsLambdaStaticInvoker) {
86-
HasThisPointer = true;
87-
ParamTypes.push_back(PT_Ptr);
88-
ParamOffsets.push_back(ParamOffset);
89-
ParamOffset += align(primSize(PT_Ptr));
85+
if (!IsLambdaStaticInvoker) {
86+
HasThisPointer = MD->isInstance();
87+
if (MD->isImplicitObjectMemberFunction()) {
88+
ParamTypes.push_back(PT_Ptr);
89+
ParamOffsets.push_back(ParamOffset);
90+
ParamOffset += align(primSize(PT_Ptr));
91+
}
9092
}
9193

9294
// Set up lambda capture to closure record field mapping.

clang/test/AST/Interp/cxx23.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,10 @@ namespace LabelGoto {
170170
static_assert(foo() == 1, ""); // all-error {{not an integral constant expression}} \
171171
// all-note {{in call to}}
172172
}
173+
174+
namespace ExplicitLambdaThis {
175+
constexpr auto f = [x = 3]<typename Self>(this Self self) { // all20-error {{explicit object parameters are incompatible with C++ standards before C++2b}}
176+
return x;
177+
};
178+
static_assert(f());
179+
}

clang/test/SemaCXX/cxx2b-deducing-this-constexpr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -fsyntax-only -std=c++2b %s -verify
2+
// RUN: %clang_cc1 -fsyntax-only -std=c++2b %s -verify -fexperimental-new-constant-interpreter
23
// expected-no-diagnostics
34

45
template <typename Base>

0 commit comments

Comments
 (0)