aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorIlya Leoshkevich <iii@linux.ibm.com>2020-06-29 20:36:03 +0200
committerIlya Leoshkevich <iii@linux.ibm.com>2020-07-02 12:38:18 +0200
commitd59a576b8b5e12c3a56f0262912090e2921f5daa (patch)
treed615a216d6a34f5d1ebc2deeef15e8d3e2714b70 /gcc
parentd0e7c73c515c305863620a821ee85bc557bfbef5 (diff)
downloadgcc-d59a576b8b5e12c3a56f0262912090e2921f5daa.zip
gcc-d59a576b8b5e12c3a56f0262912090e2921f5daa.tar.gz
gcc-d59a576b8b5e12c3a56f0262912090e2921f5daa.tar.bz2
Redefine NULL to nullptr
Bootstrap with musl libc fails with numerous "missing sentinel in function call" errors. This is because musl defines NULL as 0L for C++, but gcc requires sentinel value to be a pointer or __null. Jonathan Wakely says: To be really safe during stage 1, GCC should not use NULL as a pointer sentinel in C++ code anyway. The bootstrap compiler could define it to 0 or 0u, neither of which is guaranteed to be OK to pass as a varargs sentinel where a null pointer is expected. Any of (void*)0 or (void*)NULL or nullptr would be safe. While it is possible to fix this by replacing NULL sentinels with nullptrs, such approach would generate backporting conflicts, therefore simply redefine NULL to nullptr at the end of system.h, where it would not confuse system headers. gcc/ChangeLog: 2020-06-30 Ilya Leoshkevich <iii@linux.ibm.com> PR bootstrap/95700 * system.h (NULL): Redefine to nullptr.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/system.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/gcc/system.h b/gcc/system.h
index 5f740e3..a241e13 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -1263,4 +1263,14 @@ void gcc_stablesort (void *, size_t, size_t,
of the number. */
#define PRsa(n) "%" #n PRIu64 "%c"
+/* System headers may define NULL to be an integer (e.g. 0L), which cannot be
+ used safely in certain contexts (e.g. as sentinels). Redefine NULL to
+ nullptr in order to make it safer. Note that this might confuse system
+ headers, however, by convention they must not be included after this point.
+*/
+#ifdef __cplusplus
+#undef NULL
+#define NULL nullptr
+#endif
+
#endif /* ! GCC_SYSTEM_H */