From: James Y Knight <jyknight@google.com>
To: musl@lists.openwall.com
Subject: [PATCH] Define NULL as __null in C++ mode when using GCC or Clang.
Date: Tue, 9 Jul 2019 15:19:00 -0400 [thread overview]
Message-ID: <CAA2zVHpkNJ_2yxfUU6B73JuGC4iygtcvjzKUobO05_GqWJ2wJg@mail.gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 958 bytes --]
Both GCC and Clang ship their own stddef.h which does this (musl's
stddef.h is simply ignored). But, musl also defines the macro in a
number of other headers. Thus, depending on which header you include
last, you'll end up with a different definition of NULL.
Mostly, getting musl's definition simply degrades warning diagnostics
in C++ slightly -- e.g. GCC can no longer emit this warning:
warning: passing NULL to non-pointer argument 1 of 'int foo(long int)'
[-Wconversion-null]
If you're using Clang's modules support, it can also break
compilation. In that case, the conflicting definitions may be detected
as a module incompatibility.
A different (potentially better) fix would be to always retrieve the
definition of NULL from the compiler's stddef.h (via #define
__need_NULL #include <stddef.h>). It may also be best to delete the
musl stddef.h entirely for clarity, since it's currently ignored,
anyhow.
But, this seemed the more minimal fix.
[-- Attachment #1.2: Type: text/html, Size: 1084 bytes --]
[-- Attachment #2: 0001-Define-NULL-as-__null-in-C-mode-when-using-GCC-or-Cl.patch --]
[-- Type: text/x-patch, Size: 3931 bytes --]
From 3d898d4825c28f08ade92c40822fa5bfa2ef1f1f Mon Sep 17 00:00:00 2001
From: James Y Knight <jyknight@google.com>
Date: Tue, 9 Jul 2019 15:03:03 -0400
Subject: [PATCH] Define NULL as __null in C++ mode when using GCC or Clang.
Both GCC and Clang ship their own stddef.h which does this (musl's
stddef.h is simply ignored). But, musl also defines the macro in a
number of other headers. Thus, depending on which header you include
last, you'll end up with a different definition of NULL.
Mostly, getting musl's definition simply degrades warning diagnostics
in C++ slightly -- e.g. GCC can no longer emit this warning:
warning: passing NULL to non-pointer argument 1 of 'int foo(long int)' [-Wconversion-null]
If you're using Clang's modules support, it can also break
compilation. In that case, the conflicting definitions may be detected
as a module incompatibility.
A different (potentially better) fix would be to always retrieve the
definition of NULL from the compiler's stddef.h (via #define
__need_NULL #include <stddef.h>). It may also be best to delete the
musl stddef.h entirely for clarity, since it's currently ignored,
anyhow.
But, this seemed the more minimal fix.
---
include/locale.h | 4 ++++
include/stddef.h | 4 ++++
include/stdio.h | 4 ++++
include/stdlib.h | 4 ++++
include/string.h | 4 ++++
include/time.h | 4 ++++
include/unistd.h | 4 ++++
include/wchar.h | 4 ++++
8 files changed, 32 insertions(+)
diff --git a/include/locale.h b/include/locale.h
index ce384381..80c2d2db 100644
--- a/include/locale.h
+++ b/include/locale.h
@@ -8,7 +8,11 @@ extern "C" {
#include <features.h>
#ifdef __cplusplus
+#ifdef __GNUC__
+#define NULL __null
+#else
#define NULL 0L
+#endif
#else
#define NULL ((void*)0)
#endif
diff --git a/include/stddef.h b/include/stddef.h
index bd753853..415a2d91 100644
--- a/include/stddef.h
+++ b/include/stddef.h
@@ -2,7 +2,11 @@
#define _STDDEF_H
#ifdef __cplusplus
+#ifdef __GNUC__
+#define NULL __null
+#else
#define NULL 0L
+#endif
#else
#define NULL ((void*)0)
#endif
diff --git a/include/stdio.h b/include/stdio.h
index 3604198c..9e30d1ad 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -26,7 +26,11 @@ extern "C" {
#include <bits/alltypes.h>
#ifdef __cplusplus
+#ifdef __GNUC__
+#define NULL __null
+#else
#define NULL 0L
+#endif
#else
#define NULL ((void*)0)
#endif
diff --git a/include/stdlib.h b/include/stdlib.h
index 42ca8336..a272a4f4 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -8,7 +8,11 @@ extern "C" {
#include <features.h>
#ifdef __cplusplus
+#ifdef __GNUC__
+#define NULL __null
+#else
#define NULL 0L
+#endif
#else
#define NULL ((void*)0)
#endif
diff --git a/include/string.h b/include/string.h
index 795a2abc..4d344d72 100644
--- a/include/string.h
+++ b/include/string.h
@@ -8,7 +8,11 @@ extern "C" {
#include <features.h>
#ifdef __cplusplus
+#ifdef __GNUC__
+#define NULL __null
+#else
#define NULL 0L
+#endif
#else
#define NULL ((void*)0)
#endif
diff --git a/include/time.h b/include/time.h
index 672b3fc3..0eec373c 100644
--- a/include/time.h
+++ b/include/time.h
@@ -8,7 +8,11 @@ extern "C" {
#include <features.h>
#ifdef __cplusplus
+#ifdef __GNUC__
+#define NULL __null
+#else
#define NULL 0L
+#endif
#else
#define NULL ((void*)0)
#endif
diff --git a/include/unistd.h b/include/unistd.h
index 9485da7a..391b58ba 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -16,7 +16,11 @@ extern "C" {
#define SEEK_END 2
#ifdef __cplusplus
+#ifdef __GNUC__
+#define NULL __null
+#else
#define NULL 0L
+#endif
#else
#define NULL ((void*)0)
#endif
diff --git a/include/wchar.h b/include/wchar.h
index 88eb55b1..bfdbaebb 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -39,7 +39,11 @@ extern "C" {
#endif
#ifdef __cplusplus
+#ifdef __GNUC__
+#define NULL __null
+#else
#define NULL 0L
+#endif
#else
#define NULL ((void*)0)
#endif
--
2.22.0.410.gd8fdbe21b5-goog
next reply other threads:[~2019-07-09 19:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-09 19:19 James Y Knight [this message]
2019-07-09 19:38 ` Rich Felker
2019-07-09 23:04 ` James Y Knight
2019-07-10 2:03 ` Szabolcs Nagy
2019-07-10 6:34 ` Florian Weimer
2019-07-10 8:46 ` Szabolcs Nagy
2019-07-10 16:18 ` James Y Knight
2019-07-10 16:44 ` Rich Felker
2019-07-10 17:35 ` James Y Knight
2019-07-10 20:11 ` A. Wilcox
2019-07-10 20:19 ` Michael Everitt
2019-07-10 20:45 ` Rich Felker
2019-07-10 20:48 ` Rich Felker
2019-07-10 21:11 ` Szabolcs Nagy
2019-07-10 21:16 ` Rich Felker
2019-07-10 21:44 ` Szabolcs Nagy
2019-07-10 16:01 ` James Y Knight
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAA2zVHpkNJ_2yxfUU6B73JuGC4iygtcvjzKUobO05_GqWJ2wJg@mail.gmail.com \
--to=jyknight@google.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).