[llvm-bugs] [Bug 41332] New: false positive for for -Wunreachable-code.

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Apr 1 07:10:28 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=41332

            Bug ID: 41332
           Summary: false positive for for -Wunreachable-code.
           Product: clang
           Version: 7.0
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: pawel_sikora at zoho.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

#include <cstdio>

void foo( int i ) {
    char const* j = nullptr;

    switch ( i ) {

        if ( 0 ) {
        case 1:
            j = "one";
        }
        if ( 0 ) {
        case 2:
            j = "two";
        }
        {
            std::printf( "%s\n", j );
            return;
        }

        default:
            std::puts( "unknown" );
    };
}

int main() {
    foo( 0 );
    foo( 1 );
    foo( 2 );
    foo( 3 );
    return 0;
}

// clang version 7.0.1 (Fedora 7.0.1-6.fc29)
% clang++ t.cpp -Wall -Wunreachable-code -o t && ./t
t.cpp:8:14: warning: code will never be executed [-Wunreachable-code]
        if ( 0 ) {
             ^
1 warning generated.
unknown
one
two
unknown

// g++ (GCC) 8.3.1 20190223 (Red Hat 8.3.1-2)
% g++ t.cpp -Wall -Wunreachable-code -o t && ./t                                
t.cpp: In function ‘void foo(int)’:
t.cpp:8:9: warning: statement will never be executed [-Wswitch-unreachable]
         if ( 0 ) {
         ^~
unknown
one
two
unknown

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190401/473ebe46/attachment.html>


More information about the llvm-bugs mailing list