Cling - How to get error from the execution of the last statement into a string

Is there a way to re-direct Cling’s stdout/stderr to a std::string?

I am using metaprocesor’s process function. How I can get the error from the execution of the last statement into a string.

int ret_val = metaProcessor->process(input_line, compRes, &value, disableValuePrinting);

if (compRes != cling::Interpreter::kSuccess) {
	string result = "Statement is not correct."; //How I get the excat error message?
}

Check the classes inheriting from clang::DiagnosticConsumer https://clang.llvm.org/doxygen/classclang_1_1DiagnosticConsumer.html

clang::TextDiagnosticBuffer might do what you need. You can set the diagnostic consumer with the clang::CompilerInstance as returned by cling:: Interpreter

Axel

Thanks Alex! I was able to write my own diagnostic consumer and set it up as a new client in diagnostics engine. It worked flawlessly!

Regards,
Abhishek

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.