Skip to content

Commit 4e3541c

Browse files
committed
Improve the test coverage of the C API -- Take 1
1 parent ded27fb commit 4e3541c

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/Interpreter/CppInterOp.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,12 +783,16 @@ namespace Cpp {
783783
return false;
784784
}
785785

786-
TCppFunction_t GetDefaultConstructor(TCppScope_t scope) {
786+
TCppFunction_t GetDefaultConstructor(compat::Interpreter& interp, TCppScope_t scope) {
787787
if (!HasDefaultConstructor(scope))
788788
return nullptr;
789789

790790
auto *CXXRD = (clang::CXXRecordDecl*)scope;
791-
return getSema().LookupDefaultConstructor(CXXRD);
791+
return interp.getCI()->getSema().LookupDefaultConstructor(CXXRD);
792+
}
793+
794+
TCppFunction_t GetDefaultConstructor(TCppScope_t scope) {
795+
return GetDefaultConstructor(getInterp(), scope);
792796
}
793797

794798
TCppFunction_t GetDestructor(TCppScope_t scope) {
@@ -3376,7 +3380,7 @@ namespace Cpp {
33763380
if (!HasDefaultConstructor(Class))
33773381
return nullptr;
33783382

3379-
auto* const Ctor = GetDefaultConstructor(Class);
3383+
auto* const Ctor = GetDefaultConstructor(interp, Class);
33803384
if (JitCall JC = MakeFunctionCallable(&interp, Ctor)) {
33813385
if (arena) {
33823386
JC.Invoke(&arena, {}, (void*)~0); // Tell Invoke to use placement new.

unittests/CppInterOp/InterpreterTest.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ TEST(InterpreterTest, CreateInterpreter) {
117117
auto CXI = clang_createInterpreterFromRawPtr(I);
118118
auto CLI = clang_Interpreter_getClangInterpreter(CXI);
119119
EXPECT_TRUE(CLI);
120+
121+
clang_Interpreter_addSearchPath(CXI, "dummy", false, false);
122+
clang_Interpreter_addIncludePath(CXI, "dummy");
123+
clang_Interpreter_declare(CXI, "#include <iostream>", false);
124+
clang_Interpreter_process(CXI, "int c = 42;");
125+
auto CXV = clang_createValue();
126+
auto Res = clang_Interpreter_evaluate(CXI, "c", CXV);
127+
EXPECT_EQ(Res, CXError_Success);
128+
129+
clang_Value_dispose(CXV);
120130
auto I2 = clang_Interpreter_takeInterpreterAsPtr(CXI);
121131
EXPECT_EQ(I, I2);
122132
clang_Interpreter_dispose(CXI);

0 commit comments

Comments
 (0)