[PATCH] Check for ISO C compilers should also allow C++

Jonathan Wakely jwakely@redhat.com
Fri May 13 16:31:54 GMT 2022


Tested x86_64-linux.

There is a suggestion[1] to make clang++ stop defining __STDC__ but it's
blocked by this. The clang++ change will still be blocked while old
Glibc versions are still in use, but we can start the clock ticking by
fixing Glibc now.

[1] https://discourse.llvm.org/t/rfc-stop-defining-the-stdc-and-related-macros-in-c-mode/62468/1

>From a quick grep, I don't think any other places in Glibc need a
similar change. Florian pointed out that gnulib overrides
<sys/cdefs.h> and so should make the same change in its version.

OK to push?

-- >8 --

The check for an ISO C compiler assumes that anything GCC-like will
define __STDC__, even if it's actually a C++ compiler. That's currently
true for G++ and compilers like clang++ that also define __GNUC__, but
it might not always be true.

The C++ standard leaves it implementation-defined whether or not
__STDC__ is defined by C++ compilers. And really the check should be
"ISO C or ISO C++ conforming compiler" anyway.
---
 misc/sys/cdefs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
index f1faf8292c..aab0e7f6a9 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -27,8 +27,8 @@
 /* The GNU libc does not support any K&R compilers or the traditional mode
    of ISO C compilers anymore.  Check for some of the combinations not
    supported anymore.  */
-#if defined __GNUC__ && !defined __STDC__
-# error "You need a ISO C conforming compiler to use the glibc headers"
+#if defined __GNUC__ && !defined __STDC__ && !defined __cplusplus
+# error "You need a ISO C or C++ conforming compiler to use the glibc headers"
 #endif
 
 /* Some user header file might have defined this before.  */
-- 
2.35.1



More information about the Libc-alpha mailing list