This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] <stdbool.h> should not define bool, true or false as macros for C++


I want to resurrect this patch that I didn't pursue for 4.8, because
our <stdbool.h> violates this very explicit requirement in the C++11
and C++14 standards:

18.10 [support.runtime] p8
"The header <cstdbool> and the header <stdbool.h> shall not define
macros named bool, true, or false."

Is the gcc/ginclude/stdbool.h change OK for trunk?

Tested x86_64-linux. I also looked in the Debian Code Search and it
seems that all the code which cares whether bool is a macro follows
one of these patterns:

#ifdef bool
#undef bool

#ifdef bool
  /* Leave if macro is from C99 stdbool.h */
  #ifndef __bool_true_false_are_defined
    #undef bool
(The __bool_true_false_are_defined macro *is* defined in C++)

#ifdef bool
#error bool should not be defined
#endif
(That's in the libc++ testsuite for <stdbool.h>, we fail that test obviously)

#ifdef bool
#define HAS_BOOL
#endif

So although that search only covers FOSS code I don't think we're
going to break much C++ code by doing this, and it's needed for C++11
anyway.



On 5 February 2012 13:00, Jonathan Wakely wrote:
> On 4 February 2012 23:35, Gerald Pfeifer wrote:
>> For what it's worth, I strongly suggest that you only define those when
>> __cpluplus is pre-C++11.
>>
>> There is simply too much software out there which will run into this
>
> Really? Why would any C++ code assume "bool" is defined as a macro?
> It's been a keyword in C++ for longer than C99 has defined it as a macro.
>
>> and being aggressive in breaking (admittedly non-standard confirming
>> programs) gives GCC a bad reputation and is not nice to our users to
>> begin with.
>
> Fair enough, this revised patch still defines bool, true and false for
> C++98 mode, but not for C++11 mode.
>
> gcc/
>         * ginclude/stdbool.h (true, false, bool): Do not define for C++11.
>
> libstdc++/
>        * testsuite/18_support/headers/cstdbool/macros.cc: New.
>
> Tested x86_64-linux, OK for trunk?

Attachment: patch.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]