Skip to content

Clang Python marks assert as case statement #109787

@Rubyfi

Description

@Rubyfi

Hi,
I'm trying to parse a set of swtich-case statements using the Python clang module and ran into some weird behavior.
Given something like this:

switch(Enum)
{
   case Enum::Value1:
      assert(false);
      break;
   case Enum::Value2:
      ....
      break;
....
}

Clang returns the assert statement's cursor kind as CursorKind.CASE_STMT.
However, this only seems to happen when an assert is the first statement in a case.
Any other statements parse like expected.
When another expression is placed first in the case, the cursor of assert is CursorKind.COMPOUND_STMT instead:

switch(Enum)
{
   case Enum::Value1:
      ;
      assert(false);
      break;
   case Enum::Value2:
      ....
      break;
....
}

Am I misinterpreting the functionality of the underlying cursor; i.e. that it is supposed to help identifying the syntactical meaning of the according token; or is this a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:as-a-librarylibclang and C++ APIquestionA 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