llvm-capstone/clang/test/Modules/lambda-merge.cpp
Richard Smith 4a1ccfe8a3 When merging lambdas, keep track of the capture lists from each version.
Different versions of a lambda will in general refer to different
enclosing variable declarations, because we do not merge most
block-scope declarations, such as local variables. Keep track of all the
declarations that correspond to a lambda's capture fields so that we can
rewrite the name of any of those variables to the lambda capture,
regardless of which copy of the body of `operator()` we look at.
2022-12-08 11:37:00 -08:00

60 lines
1.0 KiB
C++

// RUN: %clang_cc1 -fmodules -std=c++17 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
#pragma clang module build A
module A {}
#pragma clang module contents
#pragma clang module begin A
template<typename T> T f(T v) {
v();
return v;
}
inline auto g() {
int n = 0;
return f([=] { return n; });
}
template<typename T> constexpr T f2(T v) {
v();
return v;
}
constexpr auto g2() {
int n = 0;
return f2([=] { return n; });
}
#pragma clang module end
#pragma clang module endbuild
#pragma clang module build B
module B {}
#pragma clang module contents
#pragma clang module begin B
template<typename T> T f(T v) {
v();
return v;
}
inline auto g() {
int n = 0;
return f([=] { return n; });
}
template<typename T> constexpr T f2(T v) {
v();
return v;
}
constexpr auto g2() {
int n = 0;
return f2([=] { return n; });
}
#pragma clang module end
#pragma clang module endbuild
#pragma clang module import A
#pragma clang module import B
// CHECK: define {{.*}}use_g
int use_g() {
return g()();
}
static_assert(g2()() == 0);