Comments (2)
Thanks for contributing, robotboy.
Unfortunately this is a breaking change. Before, people could write either
#if GTEST_OS_WINDOWS
or
#ifdef GTEST_OS_WINDOWS
and they mean the same thing. After this change, the meaning of the
latter is silently changed. If we were to make this change, we have
to first fix all existing users (at lease those inside Google, who'll
be directly affected), which can be a lot of work.
Also, the new definitions are more error-prone. After the change, if
someone accidentally writes #ifdef GTEST_OS_WINDOWS instead of #if
GTEST_OS_WINDOWS, the code may still compile, but not in the way he
expects. I like that the old definitions let you use both forms
interchangeably.
Ideally gtest should compile without any warning. In this case,
fixing this warning is expensive and leads to new problems. -Wundef
is not part of -Wall or -Wextra, so I'm fine with not being clean
here.
BTW, I don't like how GCC's -Wundef works. Treating undefined macros
as 0 is a standard technique explicitly allowed by the C/C++ standard.
GCC should complain about a macro FOO in a #if context *only if*
"#define FOO ..." doesn't appear in the source code (even if it's
#if-ed out).
(Note that the GTEST_HAS_* macros have the same problem as GTEST_OS_*,
and we should keep their behaviors consistent.)
Original comment by [email protected]
on 28 Dec 2009 at 7:03
- Changed state: WontFix
- Added labels: OpSys-All, Priority-Low, Type-Enhancement, Usability
- Removed labels: Priority-Medium, Type-Defect
from googletest.
You are absolutely right. I failed to consider the breaks this would cause in
existing code. I have attached a patch that you may find more acceptable.
This patch
adds GTEST_DEFINE_OS_MACROS which the user can define to enable the ability to
build
with -Wundef. If this macro is not defined then the GTEST_OS_* macros behave
as they
do currently.
I would argue with your second point however. gtest-port.h is fairly inconsistent
(but documented) with it's use of undefined and 0 to mean the lack of a
feature. All
of the GTEST_HAS_CLONE type macros will be defined to 1 or 0 by the time the
user can
use them in a source file. I realize these are more about telling gtest-port
how to
behave. But GTEST_IS_THREADSAFE is also defined to 0 instead of left undefined
to
indicate that GTEST is not threadsafe. So people already have to be very
careful when
they try to test these macros. Secondly, the use of #ifdef can introduce bugs
by
masking spelling errors in the macro name. So #ifdef GTEST_OS_WINDOWS_MOBILE
and
#ifdef GTEST_OS_WINODWS_MOBILE would also both compile but not in the way the
user
expects.
Consistency of behavior is good. That said, my patch doesn't attempt to change the
behavior of the GTEST_HAS_ macros that are left undefined for two reasons.
One, there
are many more uses of them and the semantics are less obvious. And two, they
all seem
to be used in a way that is consistent with the use of -Wundef, so they are not
a
problem for me when compiling my code with -Wundef.
Lastly, I could also go through and modify all instances of #if GTEST_OS_* and
similar to be #if defined(GTEST_OS_*) if that solution sounded better to you.
I did
most of that work already in a separate branch and it works, it just requires
modifying
many more files. My current patch seemed less intrusive.
Thanks,
Anton
Original comment by [email protected]
on 28 Dec 2009 at 8:56
Attachments:
from googletest.
Related Issues (20)
- Netbeans IDE hates googletest macros HOT 1
- Hexadecimal Printing in Test Fail messages HOT 1
- Python testing scripts allow binaries under test to write XML output HOT 1
- Need to simplify Python test scripts to pass required env deltas into Subproces calls HOT 2
- Visual Studio 2010 Express does not compile googletest due to tuple issue HOT 3
- google test compilation fails on visual studio 2010 beta HOT 1
- gtest_break_on_failure does not honour EXPECT_FATAL_FAILURE HOT 3
- gtest compile error with STLPort Debug (MSVC++ 9.0) in death tests HOT 8
- define macros to simplify warning suppression HOT 1
- gtest may invoke an ANSI WIn32 API on a Unicode argument. HOT 2
- Enhancement: comparison between containers HOT 2
- Report failing tests to stderr instead of stdout HOT 1
- On SUN Warning: A non-POD object of type ... passed as a variable argument to function "testing::internal::IsNullLiteralHelper(...)". HOT 1
- Death tests don't pass when using FAIL() in a child process on Windows. HOT 5
- 奇怪的tuple 编译错误 HOT 2
- configure.ac:29: error: possibly undefined macro: AC_PROG_LIBTOOL HOT 4
- EXPECT_DEATH test passes but leaves a dumped core from spawned process. HOT 2
- gtest-port_test.cc tries to use testing::Types without looking at GTEST_HAS_TYPED_TEST HOT 1
- gtest should treat - as _ when parsing command line flags HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from googletest.