Giter Club home page Giter Club logo

Comments (2)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 16, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 16, 2024
    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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.