Skip to content

Instantly share code, notes, and snippets.

@nbigaouette
Created February 24, 2011 21:37
Show Gist options
  • Save nbigaouette/842939 to your computer and use it in GitHub Desktop.
Save nbigaouette/842939 to your computer and use it in GitHub Desktop.
Simple test case for testing clang++ #pragma
// Compilation:
// 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.
//
// What it should be:
// $ clang++ -Wunreachable-code -c src/Main.cpp -o build/Main.o
// src/Main.cpp:22:9: warning: will never be executed [-Wunreachable-code]
// std::cout << "Second debug output." << std::endl;
// ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 1 warning generated.
//
// See http://llvm.org/bugs/show_bug.cgi?id=9319
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment