-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Description
Moved from JIRA ROOT 10150 because it is tightly related to other GitHub issues and pull requests
When using TInterpreter to just-in-time compile C++ code, it seems that namespaces are not preserved. Here is a MWE (root jit.cpp+):
#include <TInterpreter.h>
#include <functional>
#include <iostream>
namespace Foo {
struct Particle { float m_pt; float pt() const { return m_pt; } };
}
template <typename FType>
FType get_functor( std::string const& functor_string ) {
auto intern = gInterpreter->MakeInterpreterValue();
gInterpreter->Evaluate( functor_string.c_str(), *intern );
return *static_cast<FType*>( intern->GetAsPointer() );
}
void jit() {
auto functor = get_functor<std::function<bool(Foo::Particle const&)>>( "std::function<bool(Foo::Particle const&)>( [](Foo::Particle const& particle){return particle.pt() > 15;} );" );
Foo::Particle low_pT_particle{1.f}, high_pT_particle{40.f};
std::cout << functor( high_pT_particle ) << " " << functor( low_pT_particle ) << std::endl;
}This produces the error:
$ root jit.cpp+
root [0]
Processing jit.cpp+...
Info in <TMacOSXSystem::ACLiC>: creating shared library /Users/olupton/./jit_cpp.so
input_line_14:1:88: error: unknown type name 'Particle'
extern "C" void __cling_Destruct_0x7fde41c26a90(void* obj){((std::function<bool (const Particle &)>*)obj)->~function();}
^
1 0You can see from the 1 0 printout that, despite the error, the code appears to run OK. The error shows that the Foo:: namespace prefix has been lost.
The involved code is in Interpreter.cpp:
largestream code;
code << "extern \"C\" void " << funcname.str() << "(void* obj){(("
<< utils::TypeName::GetFullyQualifiedName(
clang::QualType(RD->getTypeForDecl(), 0), RD->getASTContext())
<< "*)obj)->~" << RD->getNameAsString() << "();}";Related: