Skip to content

clang error report missing location #143216

Closed
@jurahul

Description

@jurahul

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

For this small program which uses macros,

#define ODD_NUMBERS \
       1 \
  case 3: \
  case 5

#define EVEN_NUMBERS \
       0: \
  case 2: \
  case 4


int classify(int x) {
  switch (x) {
  case 1:
  //case 1
  case 3:
  case 5: return 0;
  case 0:
  case 2:
  case 4: return 1;
  default: return 2;
  }
}

int classify1(int x) {
  switch (x) {
  case ODD_NUMBERS: return 0;
  case EVEN_NUMBERS: return 1;
  default: return 2;
  }
}

int main() {
  return classify(0) + classify1(1);
}

The missing : after case 1 in the non-macro version is reported with proper location:

<source>:15:9: error: expected ':' after 'case'
   15 |   case 1
      |         ^
      |         :

However, the missing : for the case in macro is just reported as:

error: expected ':' after 'case'

with no line information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions