diff mbox series

c++: Stop defining true, false and bool as macros in <stdbool.h>

Message ID 20200902191326.GA1852830@redhat.com
State New
Headers show
Series c++: Stop defining true, false and bool as macros in <stdbool.h> | expand

Commit Message

Jonathan Wakely Sept. 2, 2020, 7:13 p.m. UTC
Since r216679 these macros have only been defined in C++98 mode, rather
than all modes. That is permitted as a GNU extension because that header
doesn't exist in the C++ standard until C++11, so we can make it do
whatever we want for C++98. But as discussed in the PR c++/60304
comments, these macros shouldn't ever be defined for C++.

This patch removes the macro definitions for C++98 too.

The new test already passed for C++98 (and the conversion is ill-formed
in C++11 and later) so this new test is arguably unnecessary.

gcc/ChangeLog:

	PR c++/60304
	* ginclude/stdbool.h (bool, false, true): Never define for C++.

gcc/testsuite/ChangeLog:

	PR c++/60304
	* g++.dg/warn/Wconversion-null-5.C: New test.


Back in 2012 Gerald argued that we should keep these macros in case
there is code depending on them. We've not been defining them in C++11
and later modes (including our default -std=gnu++14) for nearly six
years now (GCC 5.1 shipped with the change).  I'm not aware of any
reports of problems. I think it's time to stop defining them at all.

Bootstrapped and tested on powerpc64le-linux, OK for trunk?
commit f049cda373d29ea1bce4065b24cbb392cdc5b172
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Sep 2 18:51:28 2020

    c++: Stop defining true, false and bool as macros in <stdbool.h>
    
    Since r216679 these macros have only been defined in C++98 mode, rather
    than all modes. That is permitted as a GNU extension because that header
    doesn't exist in the C++ standard until C++11, so we can make it do
    whatever we want for C++98. But as discussed in the PR c++/60304
    comments, these macros shouldn't ever be defined for C++.
    
    This patch removes the macro definitions for C++98 too.
    
    The new test already passed for C++98 (and the conversion is ill-formed
    in C++11 and later) so this new test is arguably unnecessary.
    
    gcc/ChangeLog:
    
            PR c++/60304
            * ginclude/stdbool.h (bool, false, true): Never define for C++.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/60304
            * g++.dg/warn/Wconversion-null-5.C: New test.

Comments

Nathan Sidwell Sept. 2, 2020, 7:31 p.m. UTC | #1
On 9/2/20 3:13 PM, Jonathan Wakely wrote:
> Since r216679 these macros have only been defined in C++98 mode, rather
> than all modes. That is permitted as a GNU extension because that header
> doesn't exist in the C++ standard until C++11, so we can make it do
> whatever we want for C++98. But as discussed in the PR c++/60304
> comments, these macros shouldn't ever be defined for C++.
> 
> This patch removes the macro definitions for C++98 too.
> 
> The new test already passed for C++98 (and the conversion is ill-formed
> in C++11 and later) so this new test is arguably unnecessary.
> 
> gcc/ChangeLog:
> 
> 	PR c++/60304
> 	* ginclude/stdbool.h (bool, false, true): Never define for C++.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR c++/60304
> 	* g++.dg/warn/Wconversion-null-5.C: New test.
> 
> 
> Back in 2012 Gerald argued that we should keep these macros in case
> there is code depending on them. We've not been defining them in C++11
> and later modes (including our default -std=gnu++14) for nearly six
> years now (GCC 5.1 shipped with the change).  I'm not aware of any
> reports of problems. I think it's time to stop defining them at all.
> 
> Bootstrapped and tested on powerpc64le-linux, OK for trunk?

seems reasonable, thanks
diff mbox series

Patch

diff --git a/gcc/ginclude/stdbool.h b/gcc/ginclude/stdbool.h
index 72be438692f..1b56498d96f 100644
--- a/gcc/ginclude/stdbool.h
+++ b/gcc/ginclude/stdbool.h
@@ -39,13 +39,6 @@  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 /* Supporting _Bool in C++ is a GCC extension.  */
 #define _Bool	bool
 
-#if __cplusplus < 201103L
-/* Defining these macros in C++98 is a GCC extension.  */
-#define bool	bool
-#define false	false
-#define true	true
-#endif
-
 #endif /* __cplusplus */
 
 /* Signal that all the definitions are present.  */
diff --git a/gcc/testsuite/g++.dg/warn/Wconversion-null-5.C b/gcc/testsuite/g++.dg/warn/Wconversion-null-5.C
new file mode 100644
index 00000000000..05980ea91ab
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wconversion-null-5.C
@@ -0,0 +1,6 @@ 
+// PR c++/60304
+// { dg-do compile { target c++98_only } }
+// { dg-options "-Wconversion-null" }
+
+#include <stdbool.h>
+int * foo() {return false;} // { dg-warning "converting 'false' to pointer" }