c++ - -Wundef is not being ignored with pragma in g++ -
given following code:
#if macro_without_a_value int var; #endif int main(){}
when compiled with, g++ -std=c++1z -wundef -o main main.cpp
,
produces following warning:
main.cpp:1:5: warning: "macro_without_a_value" not defined [-wundef] #if macro_without_a_value ^
i'd keep warning flag enabled, suppress particular instance.
apply following:
#ifdef __gnuc__ #pragma gcc diagnostic ignored "-wundef" #pragma gcc diagnostic push #endif #if macro_without_a_value int var; #endif #ifdef __gnuc__ #pragma gcc diagnostic pop #endif int main(){}
this solves problem in clang++
.
the command clang++ -std=c++1z -wundef -o main main.cpp
builds without warnings.
command g++ -std=c++1z -wundef -o main main.cpp
builds same [-wundef]
warning before.
how can suppress -wundef
warnings in g++
?
g++ (ubuntu 5.1.0-0ubuntu11~14.04.1) 5.1.0 clang version 3.8.0
what i've done before when third party headers inducing warnings wrap them in own private header uses #pragma gcc system_header
silence warnings header. use own wrapper keep includes neat , allow additional customization point in future if needed.
Comments
Post a Comment