psmason / googletest

Automatically exported from code.google.com/p/googletest
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Undefined preprocessor symbols in gtest-port.h make it hard to use -Wundef #258

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
(Why might you want to use -Wundef? See 
http://ozlabs.org/~rusty/index.cgi/tech/2008-01-04.html)

This is sort of a minor problem.

When compiling our gtest-based tests w/ gcc's -Wundef, there are a number of 
warnings like:
gtest/include/gtest/internal/gtest-port.h:207:5: warning: "GTEST_OS_CYGWIN" is 
not defined

That's because #if is used on undefined symbols. There are a couple solutions:

1) #define everything to 0 (all in one place at the top). #undef it then 
#define it to 1 when it's detected.
2) change all the call-site conditionals to #ifdef where possible, or #if 
defined(FOO) || defined(BAR) otherwise
3) change all the define-site conditionals to #define the rest of the 
conflicting options to 0
4) Other?

Of these, 3 is a combinatorial explosion and 2 expands the scope of the changes 
to the rest of the code rather than limiting 
the scope to gtest-port. That pretty much leaves 1, unless you have a better 
idea.

If you're willing to accept a patch for any of these methods, let me know and 
I'll cut the patch. Otherwise, close this 
wontfix and I won't :)

Original issue reported on code.google.com by novas0x2a on 11 Mar 2010 at 11:00

GoogleCodeExporter commented 9 years ago
Thanks for the suggestion.  We discussed this before (in issue 240 and then some
off-line communication) and decided not to do it.  Basically I think the 
behavior of
gcc's -Wundef is broken and the warning is unnecessarily aggressive.  My 
suggestion
for you is to use gcc's -isystem flag to treat gtest headers as system headers, 
s.t.
you can use -Wundef to catch undefined macros in your own code without showing
warnings in gtest headers.

Original comment by w...@google.com on 12 Mar 2010 at 8:07