Like for the other *.in.h files, it makes sense to add a unit test for this .h file. Done through the second patch below.
It uncovers a compilation error: g++ -ftrapv -DHAVE_CONFIG_H -I. -I../../gltests -I.. -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib -I/media/develdata/devel/inst-x86_64-64/include -Wall -Wno-error -O0 -fno-omit-frame-pointer -ggdb -MT test-stdbit-h-c++.o -MD -MP -MF .deps/test-stdbit-h-c++.Tpo -c -o test-stdbit-h-c++.o ../../gltests/test-stdbit-h-c++.cc In file included from /usr/include/c++/11/bits/stringfwd.h:40, from /usr/include/c++/11/iosfwd:39, from /usr/include/c++/11/ios:38, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from ../../gltests/test-stdbit-h-c++.cc:26: /usr/include/c++/11/bits/memoryfwd.h:63:3: error: template with C linkage 63 | template<typename> | ^~~~~~~~ In file included from ../../gltests/test-stdbit-h-c++.cc:22: ../gllib/stdbit.h:78:1: note: ‘extern "C"’ linkage started here 78 | extern "C" { | ^~~~~~~~~~ In file included from /usr/include/c++/11/bits/stringfwd.h:40, from /usr/include/c++/11/iosfwd:39, from /usr/include/c++/11/ios:38, from /usr/include/c++/11/ostream:38, from /usr/include/c++/11/iostream:39, from ../../gltests/test-stdbit-h-c++.cc:26: ... The first patch below fixes it. 2024-05-15 Bruno Haible <br...@clisp.org> stdbit-h: Add tests. * tests/test-stdbit-h.c: New file. * tests/test-stdbit-h-c++.cc: New file. * modules/stdbit-h-tests: New file. * modules/stdbit-h-c++-tests: New file. 2024-05-15 Bruno Haible <br...@clisp.org> stdbit-h: Make it work in C++ mode. * lib/stdbit.in.h: Remove extraneous 'extern "C" {' marker.
>From 182c7eb43345f26178f9a3f794c85e684e96c370 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Thu, 16 May 2024 01:20:08 +0200 Subject: [PATCH 1/2] stdbit-h: Make it work in C++ mode. * lib/stdbit.in.h: Remove extraneous 'extern "C" {' marker. --- ChangeLog | 5 +++++ lib/stdbit.in.h | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 377dbe99bb..9ce6d303c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2024-05-15 Bruno Haible <br...@clisp.org> + + stdbit-h: Make it work in C++ mode. + * lib/stdbit.in.h: Remove extraneous 'extern "C" {' marker. + 2024-05-15 Bruno Haible <br...@clisp.org> stdbit-h, stdc_*: New modules, part of the stdbit module. diff --git a/lib/stdbit.in.h b/lib/stdbit.in.h index 73b234791d..f241a5c573 100644 --- a/lib/stdbit.in.h +++ b/lib/stdbit.in.h @@ -73,10 +73,6 @@ _GL_INLINE_HEADER_BEGIN # define _GL_STDC_BIT_CEIL_INLINE _GL_INLINE #endif -#ifdef __cplusplus -extern "C" { -#endif - /* An expression, preferably with the type of A, that has the value of B. */ #if ((defined __GNUC__ && 2 <= __GNUC__) \ || (defined __clang_major__ && 4 <= __clang_major__) \ -- 2.34.1
>From 1a016b72a9ea5d48c6eab35494282ec657db6e18 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Thu, 16 May 2024 01:23:39 +0200 Subject: [PATCH 2/2] stdbit-h: Add tests. * tests/test-stdbit-h.c: New file. * tests/test-stdbit-h-c++.cc: New file. * modules/stdbit-h-tests: New file. * modules/stdbit-h-c++-tests: New file. --- ChangeLog | 8 ++++++++ modules/stdbit-h-c++-tests | 17 ++++++++++++++++ modules/stdbit-h-tests | 12 ++++++++++++ tests/test-stdbit-h-c++.cc | 32 ++++++++++++++++++++++++++++++ tests/test-stdbit-h.c | 40 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 109 insertions(+) create mode 100644 modules/stdbit-h-c++-tests create mode 100644 modules/stdbit-h-tests create mode 100644 tests/test-stdbit-h-c++.cc create mode 100644 tests/test-stdbit-h.c diff --git a/ChangeLog b/ChangeLog index 9ce6d303c6..9a69d7e2aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2024-05-15 Bruno Haible <br...@clisp.org> + + stdbit-h: Add tests. + * tests/test-stdbit-h.c: New file. + * tests/test-stdbit-h-c++.cc: New file. + * modules/stdbit-h-tests: New file. + * modules/stdbit-h-c++-tests: New file. + 2024-05-15 Bruno Haible <br...@clisp.org> stdbit-h: Make it work in C++ mode. diff --git a/modules/stdbit-h-c++-tests b/modules/stdbit-h-c++-tests new file mode 100644 index 0000000000..aad80e4f8d --- /dev/null +++ b/modules/stdbit-h-c++-tests @@ -0,0 +1,17 @@ +Files: +tests/test-stdbit-h-c++.cc + +Status: +c++-test + +Depends-on: +ansi-c++-opt + +configure.ac: + +Makefile.am: +if ANSICXX +TESTS += test-stdbit-h-c++ +check_PROGRAMS += test-stdbit-h-c++ +test_stdbit_h_c___SOURCES = test-stdbit-h-c++.cc +endif diff --git a/modules/stdbit-h-tests b/modules/stdbit-h-tests new file mode 100644 index 0000000000..67a8ff645c --- /dev/null +++ b/modules/stdbit-h-tests @@ -0,0 +1,12 @@ +Files: +tests/test-stdbit-h.c +tests/macros.h + +Depends-on: +stdbit-h-c++-tests + +configure.ac: + +Makefile.am: +TESTS += test-stdbit-h +check_PROGRAMS += test-stdbit-h diff --git a/tests/test-stdbit-h-c++.cc b/tests/test-stdbit-h-c++.cc new file mode 100644 index 0000000000..db19ea798d --- /dev/null +++ b/tests/test-stdbit-h-c++.cc @@ -0,0 +1,32 @@ +/* Test of <stdbit.h> substitute in C++ mode. + Copyright (C) 2024 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 <br...@clisp.org>, 2024. */ + +#define GNULIB_NAMESPACE gnulib +#include <config.h> + +#include <stdbit.h> + +/* Check against conflicts between <stdbit.h> and the C++ header files. */ +#include <stddef.h> +#include <iostream> + + +int +main () +{ +} diff --git a/tests/test-stdbit-h.c b/tests/test-stdbit-h.c new file mode 100644 index 0000000000..f024e4ac6f --- /dev/null +++ b/tests/test-stdbit-h.c @@ -0,0 +1,40 @@ +/* Test of <stdbit.h> substitute. + Copyright (C) 2024 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 <br...@clisp.org>, 2024. */ + +#include <config.h> + +#include <stdbit.h> + +/* Check that __STDC_ENDIAN_BIG__ and __STDC_ENDIAN_LITTLE__ are defined. */ +int a[2] = { __STDC_ENDIAN_BIG__, __STDC_ENDIAN_LITTLE__ }; + +/* Check that __STDC_ENDIAN_NATIVE__ is defined. */ +int b = __STDC_ENDIAN_NATIVE__; + +/* Check that __STDC_ENDIAN_NATIVE__ is either __STDC_ENDIAN_BIG__ or + __STDC_ENDIAN_LITTLE__. */ +#if !(__STDC_ENDIAN_NATIVE__ == __STDC_ENDIAN_BIG__ \ + || __STDC_ENDIAN_NATIVE__ == __STDC_ENDIAN_LITTLE__) +# error "unknown endianness" +#endif + +int +main (void) +{ + return 0; +} -- 2.34.1