diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index e619750e3..02670ca38 100755 --- a/lib/CppInterOp/CppInterOp.cpp +++ b/lib/CppInterOp/CppInterOp.cpp @@ -1477,7 +1477,8 @@ intptr_t GetVariableOffset(compat::Interpreter& I, Decl* D, #ifdef CPPINTEROP_USE_CLING cling::Interpreter::PushTransactionRAII RAII(&getInterp()); #endif // CPPINTEROP_USE_CLING - getSema().InstantiateVariableDefinition(SourceLocation(), VD); + getSema().InstantiateVariableDefinition(SourceLocation(), VD, true, + true); } if (VD->hasInit() && (VD->isConstexpr() || VD->getType().isConstQualified())) { diff --git a/unittests/CppInterOp/VariableReflectionTest.cpp b/unittests/CppInterOp/VariableReflectionTest.cpp index b9baf6c55..4dd196cc6 100644 --- a/unittests/CppInterOp/VariableReflectionTest.cpp +++ b/unittests/CppInterOp/VariableReflectionTest.cpp @@ -299,6 +299,28 @@ TEST(VariableReflectionTest, GetVariableOffset) { auto* VD_C_s_a = Cpp::GetNamed("s_a", Decls[4]); // C::s_a EXPECT_TRUE((bool) Cpp::GetVariableOffset(VD_C_s_a)); + + Cpp::Declare(R"( + template struct ClassWithStatic { + static T const ref_value; + }; + template T constexpr ClassWithStatic::ref_value = 42; + )"); + + Cpp::TCppScope_t klass = Cpp::GetNamed("ClassWithStatic"); + EXPECT_TRUE(klass); + + ASTContext& C = Interp->getCI()->getASTContext(); + std::vector template_args = { + {C.IntTy.getAsOpaquePtr()}}; + Cpp::TCppScope_t klass_instantiated = Cpp::InstantiateTemplate( + klass, template_args.data(), template_args.size()); + EXPECT_TRUE(klass_instantiated); + + Cpp::TCppScope_t var = Cpp::GetNamed("ref_value", klass_instantiated); + EXPECT_TRUE(var); + + EXPECT_TRUE(Cpp::GetVariableOffset(var)); } #define CODE \