Skip to content

switch statements expanded from macro are missing source locations #144052

Open
@tbaederr

Description

@tbaederr

See https://godbolt.org/z/rjzdsKqqh

#define S(a) switch(a){ default }


#define D default
#define C(x) case x

int foo(int a) {

    switch(a) {
         default
    }

    S(a);

    switch(a) {
         D
    }

    switch(a) {
        C(10)
    }

}
<source>:13:17: error: expected ':' after 'default'
   13 |          default
      |                 ^
      |                 :
error: expected ':' after 'default'
<source>:19:11: error: expected ':' after 'default'
   19 |          D
      |           ^
      |           :
<source>:23:14: error: expected ':' after 'case'
   23 |         C(10)
      |              ^
      |              colon
4 errors generated.

the second emitted error does not have a valid source location.

Seems like this only happens if the entire switch is expanded from a macro.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions