Skip to content

clang's -Wunreachable-code does not fire if the first unreachable line is a macro #123064

Open
@nico

Description

@nico

This warns (as it should):

Code:

[[noreturn]] void notreached();
void g();

void f() {
  notreached();
  g();
}

Output:

% clang -c notreach.cc -Wunreachable-code
notreach.cc:6:3: warning: code will never be executed [-Wunreachable-code]
    6 |   g();
      |   ^
1 warning generated.

This doesn't:

Code:

[[noreturn]] void notreached();
void g();

#define MY_MACRO(x) (void)(x)

void f() {
  notreached();
  MY_MACRO(5);
  g();
}

Output:

% clang -c notreach2.cc -Wunreachable-code
# no output

Not emitting unreachable code warnings for the macro itself probably makes sense, but the diagnostic disappearing completely seems surprising.

(reported downstream at https://crbug.com/379845253)

Metadata

Metadata

Assignees

Labels

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

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions