Skip to content

Commit d59a576

Browse files
committed
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 <[email protected]> PR bootstrap/95700 * system.h (NULL): Redefine to nullptr.
1 parent d0e7c73 commit d59a576

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

gcc/system.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,4 +1263,14 @@ void gcc_stablesort (void *, size_t, size_t,
12631263
of the number. */
12641264
#define PRsa(n) "%" #n PRIu64 "%c"
12651265

1266+
/* System headers may define NULL to be an integer (e.g. 0L), which cannot be
1267+
used safely in certain contexts (e.g. as sentinels). Redefine NULL to
1268+
nullptr in order to make it safer. Note that this might confuse system
1269+
headers, however, by convention they must not be included after this point.
1270+
*/
1271+
#ifdef __cplusplus
1272+
#undef NULL
1273+
#define NULL nullptr
1274+
#endif
1275+
12661276
#endif /* ! GCC_SYSTEM_H */

0 commit comments

Comments
 (0)