Interpreter->declare crash on bad script

Hi,

I am trying to properly handle compiler errors.
I’m on OSX, using root 6 form brew:

$ brew info root6
homebrew/science/root6: stable 6.06.06 (bottled), HEAD

Here is a piece of code, that try to use cling interpreter to declare a script containing an error:

// g++ -g -L/usr/local/lib/root -L/usr/local/opt/root6/lib/root -lCling -I/usr/local/etc/root/cling -I/usr/local/etc/root/ -std=c++14 -DDEBUG -o compile_crash compile_crash.cc
#include <vector>
#include <exception>
#include <sstream>
#include <iostream>
#include <fstream>

#include "cling/Interpreter/Interpreter.h"

const char * script =
  "template <typename UnaryOperation>                        \n"
  "static int lambda_operation(UnaryOperation op);           \n"
  "                                                          \n"
  "template <typename T>                                     \n"
  "inline int templated_function() {                         \n"
  "                                                          \n"
  "  lambda_operation([](int) -> int { return 3; });         \n"
  "                                                          \n"
  "  something_wrong;                                        \n"
  "}                                                         \n"
  "                                                          \n"
  "static void __main() {                                    \n"
  "  templated_function<int>();                              \n"
  "}                                                         \n";

cling::Interpreter* interpreter(nullptr);

void setup() {

  std::string base_cling_directory = "/usr/local/etc/root";
  std::string include_root = "-I" + base_cling_directory;
  std::vector<const char*> args = {"-nostdinc++",
                                   "-std=c++14",
                                   "-DDEBUG",
#ifdef __APPLE__
                                   "-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
#elif __linux__
                                   "-I/usr/include/c++/5", "-I/usr/include/x86_64-linux-gnu/c++/5", "-I/usr/include/c++/5/backward",
#else
  #error "Unknown compiler"
#endif
                                   include_root.c_str()};

  const std::string llvmdir = base_cling_directory + "/cling";
  interpreter               = new cling::Interpreter(args.size(), args.data(), llvmdir.c_str());
}

int main() {
  setup();
  interpreter->declare(script);

  return 0;
}

Instead of returning a compile error as a result of the interpreter->declare (I expected cling::Interpreter::CompilationResult::kFailure), I have this output:

$ ./compile_crash_2
input_line_3:9:3: error: use of undeclared identifier 'something_wrong'
  something_wrong;
  ^

 *** Break *** segmentation violation
 Generating stack trace...
 0x0000000100d92423 in clang::RecursiveASTVisitor<clang::(anonymous namespace)::StaticVarCollector>::TraverseStmt(clang::Stmt*) (in libCling.so) + 28995
 0x0000000100d8c776 in clang::RecursiveASTVisitor<clang::(anonymous namespace)::StaticVarCollector>::TraverseStmt(clang::Stmt*) (in libCling.so) + 5270
 0x0000000100d8d506 in clang::RecursiveASTVisitor<clang::(anonymous namespace)::StaticVarCollector>::TraverseStmt(clang::Stmt*) (in libCling.so) + 8742
 0x0000000100d8bcfa in clang::RecursiveASTVisitor<clang::(anonymous namespace)::StaticVarCollector>::TraverseStmt(clang::Stmt*) (in libCling.so) + 2586
 0x0000000100d8a6b8 in clang::DeclUnloader::VisitFunctionDecl(clang::FunctionDecl*) (in libCling.so) + 128
 0x0000000100d967b2 in clang::declvisitor::Base<clang::declvisitor::make_ptr, clang::DeclUnloader, bool>::Visit(clang::Decl*) (in libCling.so) + 96
 0x0000000100d8b170 in cling::TransactionUnloader::RevertTransaction(cling::Transaction*) (in libCling.so) + 300
 0x0000000100d7908a in cling::IncrementalParser::rollbackTransaction(cling::Transaction*) (in libCling.so) + 168
 0x0000000100d78d7d in cling::IncrementalParser::commitTransaction(llvm::PointerIntPair<cling::Transaction*, 2u, cling::IncrementalParser::EParseResult, llvm::PointerLikeTypeTraits<cling::Transaction*> >) (in libCling.so) +
 0x0000000100d7963a in cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) (in libCling.so) + 146
 0x0000000100d7d5b5 in cling::Interpreter::DeclareInternal(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cling::CompilationOptions const&, cling::Transaction**) const (in libC
 0x0000000100d7c026 in cling::Interpreter::declare(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cling::Transaction**) (in libCling.so) + 52
 0x0000000100cab943 in main (in compile_crash_2) (compile_crash_2.cc:50)
 0x00007fff8cd255ad in start (in libdyld.dylib) + 1
 0x0000000000000001 in <unknown function>

Is there some way to get proper compile error handling ?

Thanks in advance for you help

Vincent

Sorry, wrong place …
Opened another here: Interpreter->declare crash on bad script