Get error message from Python/clang.cindex C++ parser

87 Views Asked by At

The following Python code is supposed to parse C++ code:

import clang.cindex

index = clang.cindex.Index.create()
translation_unit = index.parse(cpp_source_filename, args=['-std=c++20'])

Problems start if function parse raises a TranslationUnitLoadError. If I catch and print the TranslationUnitLoadError instance, I only get "Error parsing translation unit."

How to get a decent compiler error message, or at least the location of the error in the source file?

Web search yields the advise to look into translation_unit.diagnostics - but this is not pertinent here because the error is raised before translation_unit is set.

0

There are 0 best solutions below