Re: recent nullptr related changes
Paul Eggert wrote:
> +typedef struct context_t *context_t;
This is a syntax error in C++ mode, because in C++ a struct tag names the
struct type, and a type cannot be a struct and a pointer at the same time:
../gllib/selinux/context.h:46:27: error: conflicting declaration ‘typedef
struct context_t* context_t’
46 | typedef struct context_t *context_t;
| ^
../gllib/selinux/context.h:46:16: note: previous declaration as ‘struct
context_t’
46 | typedef struct context_t *context_t;
|^
Somehow we missed to add a C++ test for the 'selinux-h' module. This patch
does it, and makes the module C++ safe.
2026-01-16 Bruno Haible
selinux-h: Add tests.
* tests/test-selinux-context-h.c: New file.
* tests/test-selinux-label-h.c: New file.
* tests/test-selinux-selinux-h.c: New file.
* modules/selinux-h-tests: New file.
* tests/test-selinux-context-h-c++.cc: New file.
* tests/test-selinux-label-h-c++.cc: New file.
* tests/test-selinux-selinux-h-c++.cc: New file.
* modules/selinux-h-c++-tests: New file.
2026-01-16 Bruno Haible
selinux-h: Fix compilation errors and link errors in C++ mode.
* lib/se-selinux.in.h: Mark the functions as 'extern "C"'.
* lib/se-label.in.h: Mark the functions as 'extern "C"'. Avoid implicit
casts from 'void *' to other pointer types.
* lib/se-context.in.h: Likewise.
(context_t): Don't use 'struct context_t'.
>From 144b720464f562e878fb0dadbee2071345cdb61d Mon Sep 17 00:00:00 2001
From: Bruno Haible
Date: Sat, 17 Jan 2026 01:52:09 +0100
Subject: [PATCH 1/2] selinux-h: Fix compilation errors and link errors in C++
mode.
* lib/se-selinux.in.h: Mark the functions as 'extern "C"'.
* lib/se-label.in.h: Mark the functions as 'extern "C"'. Avoid implicit
casts from 'void *' to other pointer types.
* lib/se-context.in.h: Likewise.
(context_t): Don't use 'struct context_t'.
---
ChangeLog | 9 +
lib/se-context.in.h | 23 ---
lib/se-label.in.h | 12 +++-
lib/se-selinux.in.h | 10 ++
4 files changed, 46 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e104502a27..a8555e59e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2026-01-16 Bruno Haible
+
+ selinux-h: Fix compilation errors and link errors in C++ mode.
+ * lib/se-selinux.in.h: Mark the functions as 'extern "C"'.
+ * lib/se-label.in.h: Mark the functions as 'extern "C"'. Avoid implicit
+ casts from 'void *' to other pointer types.
+ * lib/se-context.in.h: Likewise.
+ (context_t): Don't use 'struct context_t'.
+
2026-01-16 Paul Eggert
manywarnings: omit new C warning for GCC < 15
diff --git a/lib/se-context.in.h b/lib/se-context.in.h
index 37cc7a6dff..ca6e97a14f 100644
--- a/lib/se-context.in.h
+++ b/lib/se-context.in.h
@@ -41,14 +41,18 @@ _GL_INLINE_HEADER_BEGIN
# endif
#endif
+#ifdef __cplusplus
+extern "C" {
+#endif
+
-typedef struct context_t *context_t;
+typedef struct selinux_context_t *context_t;
SE_CONTEXT_INLINE context_t
context_new (char const *_GL_UNNAMED (s))
- { errno = ENOTSUP; return (void *) 0; }
+ { errno = ENOTSUP; return (context_t) 0; }
SE_CONTEXT_INLINE char *
context_str (context_t _GL_UNNAMED (con))
- { errno = ENOTSUP; return (void *) 0; }
+ { errno = ENOTSUP; return (char *) 0; }
SE_CONTEXT_INLINE void context_free (context_t _GL_UNNAMED (c)) {}
SE_CONTEXT_INLINE int
@@ -65,16 +69,21 @@ context_type_set (context_t _GL_UNNAMED (sc), char const *_GL_UNNAMED (s))
{ errno = ENOTSUP; return -1; }
SE_CONTEXT_INLINE char *
context_type_get (context_t _GL_UNNAMED (sc))
- { errno = ENOTSUP; return (void *) 0; }
+ { errno = ENOTSUP; return (char *) 0; }
SE_CONTEXT_INLINE char *
context_range_get (context_t _GL_UNNAMED (sc))
- { errno = ENOTSUP; return (void *) 0; }
+ { errno = ENOTSUP; return (char *) 0; }
SE_CONTEXT_INLINE char *
context_role_get (context_t _GL_UNNAMED (sc))
- { errno = ENOTSUP; return (void *) 0; }
+ { errno = ENOTSUP; return (char *) 0; }
SE_CONTEXT_INLINE char *
context_user_get (context_t _GL_UNNAMED (sc))
- { errno = ENOTSUP; return (void *) 0; }
+ { errno = ENOTSUP; return (char *) 0; }
+
+
+#ifdef __cplusplus
+}
+#endif
_GL_INLINE_HEADER_END
diff --git a/lib/se-label.in.h b/lib/se-label.in.h
index 159adb6693..f1f6d2dbad 100644
--- a/lib/se-label.in.h
+++ b/lib/se-label.in.h
@@ -42,6 +42,11 @@ _GL_INLINE_HEADER_BEGIN
# endif
#endif
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
#define SELABEL_CTX_FILE 0
struct selabel_handle;
@@ -64,12 +69,17 @@ SE_LABEL_INLINE struct selabel_handle *
selabel_open (int _GL_UNNAMED (backend),
struct selinux_opt *_GL_UNNAMED (options),
unsigned _GL_UNNAMED (nopt))
-{ errno = ENOTSUP; return (void *) 0; }
+{ errno = ENOTSUP; return (struct selabel_handle *) 0; }
SE_LABEL_INLINE void
selabel_c
Re: recent nullptr related changes
On 2026-01-16 03:47, Pádraig Brady wrote:
cc1: error: command-line option '-Wzero-as-null-pointer-constant'
is valid for C++/ObjC++ but not for C [-Werror]
That's because the option is accepted, but always gives a warning.
I wonder should the gnulib manywarnings compat checking
always have -Werror enabled to auto remove such options
from use on unsupporting compilers?
That might be one way to go, though you'd need to test whether -Werror
works I suppose. I took a simpler way out, by looking at the GCC version
(which this code already does for other reasons) in the attached. This
patch also ports to Ubuntu GCC.
The implication of that is, the sc_prohibit_NULL syntax check will fail.
I'll probably remove the syntax check anyway,
and possibly s/nullptr/NULL/ everywhere for consistency.
Both sound good to me, thanks.From 73e6357e410c70a12ebedac4fc9d48f97e2c0ad4 Mon Sep 17 00:00:00 2001
From: Paul Eggert
Date: Fri, 16 Jan 2026 12:26:22 -0800
Subject: [PATCH] manywarnings: omit new C warning for GCC < 15
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Problem reported by Pádraig Brady in:
https://lists.gnu.org/r/bug-gnulib/2026-01/msg00135.html
* m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC(C)):
Do not add -Wzero-as-null-pointer-constant for GCC < 15.
Also, accept strings like "gcc-14 (Ubuntu 14.3.0-8ubuntu1) 14.3.0"
as specifying GCC versions like 14.3.0.
---
ChangeLog | 8
m4/manywarnings.m4 | 20 ++--
2 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index bd77658a74..c880440831 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2026-01-16 Paul Eggert
+ manywarnings: omit new C warning for GCC < 15
+ Problem reported by Pádraig Brady in:
+ https://lists.gnu.org/r/bug-gnulib/2026-01/msg00135.html
+ * m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC(C)):
+ Do not add -Wzero-as-null-pointer-constant for GCC < 15.
+ Also, accept strings like "gcc-14 (Ubuntu 14.3.0-8ubuntu1) 14.3.0"
+ as specifying GCC versions like 14.3.0.
+
selinux-h: pacify -Wzero-as-null-pointer-constant
* lib/se-context.in.h (context_t): Make it a pointer to an
incomplete type rather than an int, so that callers can initialize
diff --git a/m4/manywarnings.m4 b/m4/manywarnings.m4
index 97567b2530..4cb17a689a 100644
--- a/m4/manywarnings.m4
+++ b/m4/manywarnings.m4
@@ -1,5 +1,5 @@
# manywarnings.m4
-# serial 30
+# serial 31
dnl Copyright (C) 2008-2026 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -150,7 +150,6 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC(C)],
-Wvector-operation-performance \
-Wvla \
-Wwrite-strings \
--Wzero-as-null-pointer-constant \
; do
AS_VAR_APPEND([$1], [" $gl_manywarn_item"])
done
@@ -169,20 +168,29 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC(C)],
AS_VAR_APPEND([$1], [' -Wunused-const-variable=2'])
AS_VAR_APPEND([$1], [' -Wvla-larger-than=4031'])
- # These are needed for older GCC versions.
+ # These depend on the GCC version.
if test -n "$GCC" && gl_gcc_version=`($CC --version) 2>/dev/null`; then
case $gl_gcc_version in
- 'gcc (GCC) '[[0-3]].* | \
- 'gcc (GCC) '4.[[0-7]].*)
+ gcc*' ('*') '[[0-3]].* | \
+ gcc*' ('*') '4.[[0-7]].*)
AS_VAR_APPEND([$1], [' -fdiagnostics-show-option'])
AS_VAR_APPEND([$1], [' -funit-at-a-time'])
;;
esac
case $gl_gcc_version in
- 'gcc (GCC) '[[0-9]].*)
+ gcc*' ('*') '[[0-9]].*)
AS_VAR_APPEND([$1], [' -fno-common'])
;;
esac
+case $gl_gcc_version in
+ gcc*' ('*') '?.* | gcc*' ('*') '1[[1-4]].*)
+ # In GCC < 15 the option either does not exist,
+ # or is accepted but always warns.
+ ;;
+ *)
+ AS_VAR_APPEND([$1], [' -Wzero-as-null-pointer-constant'])
+ ;;
+esac
fi
# These options are not supported by gcc, but are useful with clang.
--
2.51.0
Re: recent nullptr related changes
On 2026-01-16 04:10, Pádraig Brady wrote:
I see there is another issue triggered by the coreutils change:
https://github.com/coreutils/coreutils/issues/173
I.e., the conflict between `typedef int context_t`
in the gnulib selinux shim, and the new assignment to NULL.
Thanks for reporting that. Fixed by installing the attached to Gnulib
(afterwards, I corrected the spelling of "whether" in ChangeLog).From 0d733c1cbcaa72e2e28699087a09aa5bdea8d246 Mon Sep 17 00:00:00 2001
From: Paul Eggert
Date: Fri, 16 Jan 2026 11:17:26 -0800
Subject: [PATCH] selinux-h: pacify -Wzero-as-null-pointer-constant
* lib/se-context.in.h (context_t): Make it a pointer to an
incomplete type rather than an int, so that callers can initialize
it with NULL regardless of whehter --with-selinux is used.
* lib/se-context.in.h (context_new):
* lib/se-label.in.h (selabel_open): Use the equivalent of
NULL (not NULL, since that would require including ).
---
ChangeLog | 10 ++
lib/se-context.in.h | 4 ++--
lib/se-label.in.h | 2 +-
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index db4ae7ff31..bd77658a74 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2026-01-16 Paul Eggert
+
+ selinux-h: pacify -Wzero-as-null-pointer-constant
+ * lib/se-context.in.h (context_t): Make it a pointer to an
+ incomplete type rather than an int, so that callers can initialize
+ it with NULL regardless of whehter --with-selinux is used.
+ * lib/se-context.in.h (context_new):
+ * lib/se-label.in.h (selabel_open): Use the equivalent of
+ NULL (not NULL, since that would require including ).
+
2026-01-15 Paul Eggert
manywarnings: -Wzero-as-null-pointer-constant in C
diff --git a/lib/se-context.in.h b/lib/se-context.in.h
index ecc42032c9..37cc7a6dff 100644
--- a/lib/se-context.in.h
+++ b/lib/se-context.in.h
@@ -42,10 +42,10 @@ _GL_INLINE_HEADER_BEGIN
#endif
-typedef int context_t;
+typedef struct context_t *context_t;
SE_CONTEXT_INLINE context_t
context_new (char const *_GL_UNNAMED (s))
- { errno = ENOTSUP; return 0; }
+ { errno = ENOTSUP; return (void *) 0; }
SE_CONTEXT_INLINE char *
context_str (context_t _GL_UNNAMED (con))
{ errno = ENOTSUP; return (void *) 0; }
diff --git a/lib/se-label.in.h b/lib/se-label.in.h
index 19b5f26aa6..159adb6693 100644
--- a/lib/se-label.in.h
+++ b/lib/se-label.in.h
@@ -64,7 +64,7 @@ SE_LABEL_INLINE struct selabel_handle *
selabel_open (int _GL_UNNAMED (backend),
struct selinux_opt *_GL_UNNAMED (options),
unsigned _GL_UNNAMED (nopt))
-{ errno = ENOTSUP; return 0; }
+{ errno = ENOTSUP; return (void *) 0; }
SE_LABEL_INLINE void
selabel_close (struct selabel_handle *_GL_UNNAMED (hnd))
--
2.51.0
