]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
sys/cdefs.h: Do not require C++ compilers to define __STDC__
authorJonathan Wakely <jwakely@redhat.com>
Fri, 13 May 2022 13:16:34 +0000 (14:16 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 16 May 2022 15:48:51 +0000 (16:48 +0100)
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. So only give an error if
__GNUC__ is defined and neither __STDC__ nor __cplusplus is defined.

Reviewed-by: Fangrui Song <maskray@google.com>
misc/sys/cdefs.h

index 1c2b044a0d27da18709a95f1ccecdf556434b173..f525f67547f0c81902a591c8fc1f23b2cf38072e 100644 (file)
@@ -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.  */