Skip to content

How to get error message from Python/clang.cindex C++ parser #73448

Open
@jwuttke

Description

@jwuttke

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:toolingLibToolingquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions