Skip to content

[clang] -Wunreachable-code does not work on macros #116296

@tiagomacarios

Description

@tiagomacarios

For the code below clang should emit 2 unreachable code warnings, but it only emits one

https://godbolt.org/z/fT9rs5xYn

#include <type_traits>

[[noreturn]] void crash() noexcept;

#define VerifyElseCrash(b) \
    if (!b) [[unlikely]] { \
        crash();           \
    }

void some_other_funtion();

int f1() {
    if (!false) [[unlikely]] {
        crash();
    }

    some_other_funtion(); // dead code
}

int f2() {
    VerifyElseCrash(false);

    some_other_funtion(); // dead code
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerenhancementImproving things as opposed to bug fixing, e.g. new or missing featurefalse-negativeWarning doesn't fire when it shouldquality-of-implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions