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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
+
+ 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 <[email protected]>
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_close (struct selabel_handle *_GL_UNNAMED (hnd))
{ errno = ENOTSUP; }
+
+#ifdef __cplusplus
+}
+#endif
+
_GL_INLINE_HEADER_END
#endif
diff --git a/lib/se-selinux.in.h b/lib/se-selinux.in.h
index a62de9c9df..8094bc13aa 100644
--- a/lib/se-selinux.in.h
+++ b/lib/se-selinux.in.h
@@ -50,6 +50,11 @@ _GL_INLINE_HEADER_BEGIN
# endif
# endif
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+
# if !GNULIB_defined_security_types
typedef unsigned short security_class_t;
@@ -153,6 +158,11 @@ matchpathcon_init_prefix (char const *_GL_UNNAMED (path),
# define GNULIB_defined_security_types 1
# endif
+
+# ifdef __cplusplus
+}
+# endif
+
_GL_INLINE_HEADER_END
# endif /* _@GUARD_PREFIX@_SELINUX_SELINUX_H */
--
2.52.0
>From bf1bfd47520b561bb913e0fa41f951fb66acb6d3 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sat, 17 Jan 2026 01:52:50 +0100
Subject: [PATCH 2/2] 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.
---
ChangeLog | 12 +++++++++
modules/selinux-h-c++-tests | 30 +++++++++++++++++++++
modules/selinux-h-tests | 22 +++++++++++++++
tests/test-selinux-context-h-c++.cc | 19 +++++++++++++
tests/test-selinux-context-h.c | 42 +++++++++++++++++++++++++++++
tests/test-selinux-label-h-c++.cc | 19 +++++++++++++
tests/test-selinux-label-h.c | 33 +++++++++++++++++++++++
tests/test-selinux-selinux-h-c++.cc | 19 +++++++++++++
tests/test-selinux-selinux-h.c | 33 +++++++++++++++++++++++
9 files changed, 229 insertions(+)
create mode 100644 modules/selinux-h-c++-tests
create mode 100644 modules/selinux-h-tests
create mode 100644 tests/test-selinux-context-h-c++.cc
create mode 100644 tests/test-selinux-context-h.c
create mode 100644 tests/test-selinux-label-h-c++.cc
create mode 100644 tests/test-selinux-label-h.c
create mode 100644 tests/test-selinux-selinux-h-c++.cc
create mode 100644 tests/test-selinux-selinux-h.c
diff --git a/ChangeLog b/ChangeLog
index a8555e59e9..b393e61cfe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2026-01-16 Bruno Haible <[email protected]>
+
+ 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 <[email protected]>
selinux-h: Fix compilation errors and link errors in C++ mode.
diff --git a/modules/selinux-h-c++-tests b/modules/selinux-h-c++-tests
new file mode 100644
index 0000000000..6e5240967e
--- /dev/null
+++ b/modules/selinux-h-c++-tests
@@ -0,0 +1,30 @@
+Files:
+tests/test-selinux-context-h-c++.cc
+tests/test-selinux-label-h-c++.cc
+tests/test-selinux-selinux-h-c++.cc
+
+Status:
+c++-test
+
+Depends-on:
+ansi-c++-opt
+
+configure.ac:
+
+Makefile.am:
+if ANSICXX
+TESTS += \
+ test-selinux-context-h-c++ \
+ test-selinux-label-h-c++ \
+ test-selinux-selinux-h-c++
+check_PROGRAMS += \
+ test-selinux-context-h-c++ \
+ test-selinux-label-h-c++ \
+ test-selinux-selinux-h-c++
+test_selinux_context_h_c___SOURCES = test-selinux-context-h-c++.cc
+test_selinux_context_h_c___LDADD = $(LDADD) @LIB_SELINUX@
+test_selinux_label_h_c___SOURCES = test-selinux-label-h-c++.cc
+test_selinux_label_h_c___LDADD = $(LDADD) @LIB_SELINUX@
+test_selinux_selinux_h_c___SOURCES = test-selinux-selinux-h-c++.cc
+test_selinux_selinux_h_c___LDADD = $(LDADD) @LIB_SELINUX@
+endif
diff --git a/modules/selinux-h-tests b/modules/selinux-h-tests
new file mode 100644
index 0000000000..b2cd5702ad
--- /dev/null
+++ b/modules/selinux-h-tests
@@ -0,0 +1,22 @@
+Files:
+tests/test-selinux-context-h.c
+tests/test-selinux-label-h.c
+tests/test-selinux-selinux-h.c
+
+Depends-on:
+selinux-h-c++-tests
+
+configure.ac:
+
+Makefile.am:
+TESTS += \
+ test-selinux-context-h \
+ test-selinux-label-h \
+ test-selinux-selinux-h
+check_PROGRAMS += \
+ test-selinux-context-h \
+ test-selinux-label-h \
+ test-selinux-selinux-h
+test_selinux_context_h_LDADD = $(LDADD) @LIB_SELINUX@
+test_selinux_label_h_LDADD = $(LDADD) @LIB_SELINUX@
+test_selinux_selinux_h_LDADD = $(LDADD) @LIB_SELINUX@
diff --git a/tests/test-selinux-context-h-c++.cc b/tests/test-selinux-context-h-c++.cc
new file mode 100644
index 0000000000..62f0045263
--- /dev/null
+++ b/tests/test-selinux-context-h-c++.cc
@@ -0,0 +1,19 @@
+/* Test of <selinux/context.h> substitute in C++ mode.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <[email protected]>, 2026. */
+
+#include "test-selinux-context-h.c"
diff --git a/tests/test-selinux-context-h.c b/tests/test-selinux-context-h.c
new file mode 100644
index 0000000000..34c4a0aec4
--- /dev/null
+++ b/tests/test-selinux-context-h.c
@@ -0,0 +1,42 @@
+/* Test of <selinux/context.h> substitute.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <[email protected]>, 2026. */
+
+#include <config.h>
+
+#include <selinux/context.h>
+
+/* Check that context_t is defined. */
+context_t t1;
+
+int
+main ()
+{
+ context_t c = context_new ("system_u:system_r:init_t:s0");
+ context_type_set (c, "bar");
+ context_range_set (c, "bar");
+ context_role_set (c, "bar");
+ context_user_set (c, "bar");
+ (void) context_type_get (c);
+ (void) context_range_get (c);
+ (void) context_role_get (c);
+ (void) context_user_get (c);
+ (void) context_str (c);
+ context_free (c);
+
+ return 0;
+}
diff --git a/tests/test-selinux-label-h-c++.cc b/tests/test-selinux-label-h-c++.cc
new file mode 100644
index 0000000000..bb51e945e5
--- /dev/null
+++ b/tests/test-selinux-label-h-c++.cc
@@ -0,0 +1,19 @@
+/* Test of <selinux/label.h> substitute in C++ mode.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <[email protected]>, 2026. */
+
+#include "test-selinux-label-h.c"
diff --git a/tests/test-selinux-label-h.c b/tests/test-selinux-label-h.c
new file mode 100644
index 0000000000..0fd4064e2d
--- /dev/null
+++ b/tests/test-selinux-label-h.c
@@ -0,0 +1,33 @@
+/* Test of <selinux/label.h> substitute.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <[email protected]>, 2026. */
+
+#include <config.h>
+
+#include <selinux/label.h>
+
+#include <stddef.h>
+
+int
+main ()
+{
+ struct selabel_handle *l = selabel_open (SELABEL_CTX_FILE, NULL, 0);
+ if (l)
+ selabel_close (l);
+
+ return 0;
+}
diff --git a/tests/test-selinux-selinux-h-c++.cc b/tests/test-selinux-selinux-h-c++.cc
new file mode 100644
index 0000000000..fdea56ea0c
--- /dev/null
+++ b/tests/test-selinux-selinux-h-c++.cc
@@ -0,0 +1,19 @@
+/* Test of <selinux/selinux.h> substitute in C++ mode.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <[email protected]>, 2026. */
+
+#include "test-selinux-selinux-h.c"
diff --git a/tests/test-selinux-selinux-h.c b/tests/test-selinux-selinux-h.c
new file mode 100644
index 0000000000..57156726df
--- /dev/null
+++ b/tests/test-selinux-selinux-h.c
@@ -0,0 +1,33 @@
+/* Test of <selinux/selinux.h> substitute.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <[email protected]>, 2026. */
+
+#include <config.h>
+
+#include <selinux/selinux.h>
+
+int
+main ()
+{
+ /* The people at the NSA who created this API obviously did not know
+ French. */
+ char *con;
+ if (getcon (&con) == 0)
+ freecon (con);
+
+ return 0;
+}
--
2.52.0