Skip to content

[clang++] Unnecessary warning "non-void function does not return a value in all control paths" #111509

Open
@mkornaukhov03

Description

@mkornaukhov03

I have the following snippet:

int foo(int) {
    bool matched = false;
    do {
      if (matched) {
        break;
      }
        return 42;
    } while(false);
}


int main() {
    foo(42);
}

I compile it with clang++-18:

$ clang++-18 --version
Ubuntu clang version 18.1.8 (++20240731024944+3b5b5c1ec4a3-1~exp1~20240731145000.144)
Target: x86_64-pc-linux-gnu
Thread model: posix
$ clang++-18 -Wreturn-type main.cpp 
main.cpp:9:1: warning: non-void function does not return a value in all control paths [-Wreturn-type]
    9 | }
      | ^
1 warning generated.

Variable matched is effectively constant and there are no paths that "do not return a value".
The expected behavior is such that there should be no such warning.

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 partyfalse-positiveWarning fires when it should notquality-of-implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions