[LLVMbugs] [Bug 9319] New: Clang++ ignores #pragma completely when using "diagnostic push"

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Feb 24 13:26:55 PST 2011


http://llvm.org/bugs/show_bug.cgi?id=9319

           Summary: Clang++ ignores #pragma completely when using
                    "diagnostic push"
           Product: clang
           Version: 2.8
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: nbigaouette at gmail.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


Created an attachment (id=6231)
 --> (http://llvm.org/bugs/attachment.cgi?id=6231)
clang++ -v -save-temps -Wunreachable-code -c src/Main.cpp -o build/Main.o &>
clang.log

I want to disable "-Wunreachable-code" for some debug output controled by a
global bool. For example:

#include <cstdlib>
#include <iostream>
// const bool verbose = true;
const bool verbose = false;
int main(int argc, char *argv[])
{
    //#pragma GCC diagnostic push
    //#pragma GCC diagnostic ignored "-Wunreachable-code"
    if (verbose)
        std::cout << "First debug output." << std::endl;
    //#pragma GCC diagnostic pop

    if (verbose)
        std::cout << "Second debug output." << std::endl;

    return EXIT_SUCCESS;
}

$ clang++ -Wunreachable-code -c src/Main.cpp -o build/Main.o
src/Main.cpp:18:9: warning: will never be executed [-Wunreachable-code]
        std::cout << "First debug output." << std::endl;
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/Main.cpp:22:9: warning: will never be executed [-Wunreachable-code]         
        std::cout << "Second debug output." << std::endl;
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.

Uncommenting the 'ignored "-Wunreachable-code"' pragma suppresses both
warnings. Uncommenting the push and pop pragma will bring the two warnings
back, while it should hide the first only and let the second pass.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list