Skip to content

Commit 510222c

Browse files
[MRE] cant resolve static variable offset for templated class
1 parent d9bf9ab commit 510222c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

unittests/CppInterOp/VariableReflectionTest.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,28 @@ TEST(VariableReflectionTest, GetVariableOffset) {
299299

300300
auto* VD_C_s_a = Cpp::GetNamed("s_a", Decls[4]); // C::s_a
301301
EXPECT_TRUE((bool) Cpp::GetVariableOffset(VD_C_s_a));
302+
303+
Cpp::Declare(R"(
304+
template <typename T> struct ClassWithStatic {
305+
static T const ref_value;
306+
};
307+
template <typename T> T constexpr ClassWithStatic<T>::ref_value = 42;
308+
)");
309+
310+
Cpp::TCppScope_t klass = Cpp::GetNamed("ClassWithStatic");
311+
EXPECT_TRUE(klass);
312+
313+
ASTContext& C = Interp->getCI()->getASTContext();
314+
std::vector<Cpp::TemplateArgInfo> template_args = {
315+
{C.IntTy.getAsOpaquePtr()}};
316+
Cpp::TCppScope_t klass_instantiated = Cpp::InstantiateTemplate(
317+
klass, template_args.data(), template_args.size());
318+
EXPECT_TRUE(klass_instantiated);
319+
320+
Cpp::TCppScope_t var = Cpp::GetNamed("ref_value", klass_instantiated);
321+
EXPECT_TRUE(var);
322+
323+
EXPECT_TRUE(Cpp::GetVariableOffset(var));
302324
}
303325

304326
#define CODE \

0 commit comments

Comments
 (0)