Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/Interpreter/CppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1862,10 +1862,22 @@ namespace Cpp {
{
std::string name;
{
llvm::raw_string_ostream stream(name);
std::string complete_name;
llvm::raw_string_ostream stream(complete_name);
FD->getNameForDiagnostic(stream,
FD->getASTContext().getPrintingPolicy(),
/*Qualified=*/false);

// insert space between template argument list and the function name
// this is require if the function is `operator<`
// `operator<<type1, type2, ...>` is invalid syntax
// whereas `operator< <type1, type2, ...>` is valid
std::string simple_name = FD->getNameAsString();
size_t idx = complete_name.find(simple_name, 0) + simple_name.size();
std::string name_without_template_args = complete_name.substr(0, idx);
std::string template_args = complete_name.substr(idx);
name = name_without_template_args +
(template_args.empty() ? "" : " " + template_args);
}
callbuf << name;
}
Expand Down
28 changes: 28 additions & 0 deletions unittests/CppInterOp/FunctionReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,34 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) {
FCI_f.Invoke(&res, {nullptr, 0});
EXPECT_TRUE(res);
#endif

// templated operators
Interp->process(R"(
class TOperator{
public:
template<typename T>
bool operator<(T t) { return true; }
};
)");
Cpp::TCppScope_t TOperator = Cpp::GetNamed("TOperator");

auto* TOperatorCtor = Cpp::GetDefaultConstructor(TOperator);
auto FCI_TOperatorCtor = Cpp::MakeFunctionCallable(TOperatorCtor);
void* toperator = nullptr;
FCI_TOperatorCtor.Invoke((void*)&toperator);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: multilevel pointer conversion from 'void **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]

  FCI_TOperatorCtor.Invoke((void*)&toperator);
                                  ^


EXPECT_TRUE(toperator);
std::vector<Cpp::TCppScope_t> operators;
Cpp::GetOperator(TOperator, Cpp::OP_Less, operators);
EXPECT_EQ(operators.size(), 1);

Cpp::TCppScope_t op_templated = operators[0];
auto TAI = Cpp::TemplateArgInfo(Cpp::GetType("int"));
Cpp::TCppScope_t op = Cpp::InstantiateTemplate(op_templated, &TAI, 1);
auto FCI_op = Cpp::MakeFunctionCallable(op);
bool boolean = false;
FCI_op.Invoke((void*)&boolean, {args, /*args_size=*/1}, object);
EXPECT_TRUE(boolean);
}

TEST(FunctionReflectionTest, IsConstMethod) {
Expand Down
Loading