This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/72837] New: -Wundef is not being ignored with pragma
- From: "TrevorJamesHickey at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 08 Aug 2016 14:16:21 +0000
- Subject: [Bug c++/72837] New: -Wundef is not being ignored with pragma
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72837
Bug ID: 72837
Summary: -Wundef is not being ignored with pragma
Product: gcc
Version: 5.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: TrevorJamesHickey at gmail dot com
Target Milestone: ---
Given the following code:
#if MACRO_WITHOUT_A_VALUE
int var;
#endif
int main(){}
When compiled with, `g++ -std=c++1z -Wundef -o main main.cpp`,
it produces the following warning:
main.cpp:1:5: warning: "MACRO_WITHOUT_A_VALUE" is not defined [-Wundef]
#if MACRO_WITHOUT_A_VALUE
^
I'd like to keep the warning flag enabled, but suppress this particular
instance.
I apply the 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 only solves the problem in `clang++`.
The command `clang++ -std=c++1z -Wundef -o main main.cpp` builds without
warnings.
The command `g++ -std=c++1z -Wundef -o main main.cpp` builds with the same
`[-Wundef]` warning as before.
**How can I suppress `-Wundef` warnings in `g++`?**
g++ (Ubuntu 5.1.0-0ubuntu11~14.04.1) 5.1.0
clang version 3.8.0
http://stackoverflow.com/questions/38831058/wundef-is-not-being-ignored-with-pragma-in-g