On Solaris 11 OpenIndiana, I see two test compilation failures:
gmake[4]: Entering directory
'/export/home/bruno/testdir-all2/build-64-gcc/gltests'
gcc -m64 -O2 -std=gnu23 -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -I.
-I../../gltests -I.. -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I.
-I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib
-I../../gltests/from-glibc -DGNULIB_TEST_STDBIT
-I/export/home/bruno/prefix64gcc/include -Wall -D_REENTRANT -Wno-error
-Wno-error -g -O2 -MT from-glibc/test_stdc_bit_ceil-tst-stdc_bit_ceil.o -MD -MP
-MF from-glibc/.deps/test_stdc_bit_ceil-tst-stdc_bit_ceil.Tpo -c -o
from-glibc/test_stdc_bit_ceil-tst-stdc_bit_ceil.o `test -f
'from-glibc/tst-stdc_bit_ceil.c' || echo
'../../gltests/'`from-glibc/tst-stdc_bit_ceil.c
In file included from ../../gltests/../gllib/libc-config.h:36,
from ../../gltests/from-glibc/tst-stdbit.h:23,
from ../../gltests/from-glibc/tst-stdc_bit_ceil.c:19:
../config.h:9751:25: error: static assertion failed
9751 | #define static_assert _Static_assert
| ^~~~~~~~~~~~~~
../../gltests/from-glibc/tst-stdbit.h:58:5: note: in expansion of macro
'static_assert'
58 | static_assert (_Generic (EXPR, TYPE: 1, default: 0))
| ^~~~~~~~~~~~~
../../gltests/from-glibc/tst-stdbit.h:220:3: note: in expansion of macro
'TEST_TYPE'
220 | TEST_TYPE (FUNC (0UL), unsigned long int); \
| ^~~~~~~~~
../../gltests/from-glibc/tst-stdc_bit_ceil.c:79:1: note: in expansion of macro
'TEST_STDBIT_SAME_TOPLEVEL'
79 | TEST_STDBIT_SAME_TOPLEVEL (stdc_bit_ceil);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
../../gltests/from-glibc/tst-stdc_bit_ceil.c: In function 'do_test':
../config.h:9751:25: error: static assertion failed
9751 | #define static_assert _Static_assert
| ^~~~~~~~~~~~~~
../../gltests/from-glibc/tst-stdbit.h:58:5: note: in expansion of macro
'static_assert'
58 | static_assert (_Generic (EXPR, TYPE: 1, default: 0))
| ^~~~~~~~~~~~~
../../gltests/from-glibc/tst-stdbit.h:93:7: note: in expansion of macro
'TEST_TYPE'
93 | TEST_TYPE (FUNC ((TYPE) {(X)}), TTYPE);
\
| ^~~~~~~~~
../../gltests/from-glibc/tst-stdbit.h:181:9: note: in expansion of macro
'TEST_STDBIT_T'
181 | TEST_STDBIT_T (FUNC, x, res_l, unsigned long int, \
| ^~~~~~~~~~~~~
../../gltests/from-glibc/tst-stdc_bit_ceil.c:84:3: note: in expansion of macro
'TEST_STDBIT_SAME'
84 | TEST_STDBIT_SAME (stdc_bit_ceil, inputs);
| ^~~~~~~~~~~~~~~~
gmake[4]: *** [Makefile:29933:
from-glibc/test_stdc_bit_ceil-tst-stdc_bit_ceil.o] Error 1
gcc -m64 -O2 -std=gnu23 -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -I.
-I../../gltests -I.. -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I.
-I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib
-I../../gltests/from-glibc -DGNULIB_TEST_STDBIT
-I/export/home/bruno/prefix64gcc/include -Wall -D_REENTRANT -Wno-error
-Wno-error -g -O2 -MT from-glibc/test_stdc_bit_floor-tst-stdc_bit_floor.o -MD
-MP -MF from-glibc/.deps/test_stdc_bit_floor-tst-stdc_bit_floor.Tpo -c -o
from-glibc/test_stdc_bit_floor-tst-stdc_bit_floor.o `test -f
'from-glibc/tst-stdc_bit_floor.c' || echo
'../../gltests/'`from-glibc/tst-stdc_bit_floor.c
In file included from ../../gltests/../gllib/libc-config.h:36,
from ../../gltests/from-glibc/tst-stdbit.h:23,
from ../../gltests/from-glibc/tst-stdc_bit_floor.c:19:
../config.h:9751:25: error: static assertion failed
9751 | #define static_assert _Static_assert
| ^~~~~~~~~~~~~~
../../gltests/from-glibc/tst-stdbit.h:58:5: note: in expansion of macro
'static_assert'
58 | static_assert (_Generic (EXPR, TYPE: 1, default: 0))
| ^~~~~~~~~~~~~
../../gltests/from-glibc/tst-stdbit.h:220:3: note: in expansion of macro
'TEST_TYPE'
220 | TEST_TYPE (FUNC (0UL), unsigned long int); \
| ^~~~~~~~~
../../gltests/from-glibc/tst-stdc_bit_floor.c:79:1: note: in expansion of macro
'TEST_STDBIT_SAME_TOPLEVEL'
79 | TEST_STDBIT_SAME_TOPLEVEL (stdc_bit_floor);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
../../gltests/from-glibc/tst-stdc_bit_floor.c: In function 'do_test':
../config.h:9751:25: error: static assertion failed
9751 | #define static_assert _Static_assert
| ^~~~~~~~~~~~~~
../../gltests/from-glibc/tst-stdbit.h:58:5: note: in expansion of macro
'static_assert'
58 | static_assert (_Generic (EXPR, TYPE: 1, default: 0))
| ^~~~~~~~~~~~~
../../gltests/from-glibc/tst-stdbit.h:93:7: note: in expansion of macro
'TEST_TYPE'
93 | TEST_TYPE (FUNC ((TYPE) {(X)}), TTYPE);
\
| ^~~~~~~~~
../../gltests/from-glibc/tst-stdbit.h:181:9: note: in expansion of macro
'TEST_STDBIT_T'
181 | TEST_STDBIT_T (FUNC, x, res_l, unsigned long int, \
| ^~~~~~~~~~~~~
../../gltests/from-glibc/tst-stdc_bit_floor.c:84:3: note: in expansion of macro
'TEST_STDBIT_SAME'
84 | TEST_STDBIT_SAME (stdc_bit_floor, inputs);
| ^~~~~~~~~~~~~~~~
gmake[4]: *** [Makefile:29947:
from-glibc/test_stdc_bit_floor-tst-stdc_bit_floor.o] Error 1
The cause is that on this platform, which has <stdbit.h> that #includes
<sys/stdbit.h>, stdc_bit_floor and stdc_bit_ceil don't implement the requirement
that the result type must be the same as the argument type:
https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/common/sys/stdbit.h#L327
It maps 'unsigned long' to 'unsigned int' in 32-bit builds and to
'unsigned long long' in 64-bit builds.
This patch fixes it.
2026-05-12 Bruno Haible <[email protected]>
stdc_bit_floor, stdc_bit_ceil: Work around Solaris 11 OpenIndiana bug.
* lib/stdbit.in.h (stdc_bit_floor, stdc_bit_ceil): Override the macro
definition from Solaris 11.
* doc/posix-functions/stdc_bit_floor.texi: Mention the Solaris 11
OpenIndiana bug.
* doc/posix-functions/stdc_bit_ceil.texi: Likewise.
diff --git a/doc/posix-functions/stdc_bit_ceil.texi
b/doc/posix-functions/stdc_bit_ceil.texi
index 265302b584..eee6c46610 100644
--- a/doc/posix-functions/stdc_bit_ceil.texi
+++ b/doc/posix-functions/stdc_bit_ceil.texi
@@ -15,6 +15,11 @@
@item
This macro is missing on many platforms:
glibc 2.38, macOS 14, FreeBSD 14.0, NetBSD 10.0, OpenBSD 7.5, AIX 7.3.1, HP-UX
11.31, Solaris 11.4, Cygwin 3.5.3, mingw, MSVC 17, Android 15.
+@item
+This macro returns a value of the wrong type
+(e.g.@: @code{unsigned long long} instead of @code{unsigned long})
+on some platforms:
+Solaris 11 OpenIndiana.
@end itemize
Portability problems not fixed by Gnulib:
diff --git a/doc/posix-functions/stdc_bit_floor.texi
b/doc/posix-functions/stdc_bit_floor.texi
index d78feb1b88..58ed7ef64a 100644
--- a/doc/posix-functions/stdc_bit_floor.texi
+++ b/doc/posix-functions/stdc_bit_floor.texi
@@ -15,6 +15,11 @@
@item
This macro is missing on many platforms:
glibc 2.38, macOS 14, FreeBSD 14.0, NetBSD 10.0, OpenBSD 7.5, AIX 7.3.1, HP-UX
11.31, Solaris 11.4, Cygwin 3.5.3, mingw, MSVC 17, Android 15.
+@item
+This macro returns a value of the wrong type
+(e.g.@: @code{unsigned long long} instead of @code{unsigned long})
+on some platforms:
+Solaris 11 OpenIndiana.
@end itemize
Portability problems not fixed by Gnulib:
diff --git a/lib/stdbit.in.h b/lib/stdbit.in.h
index 990f3edfde..92749487fa 100644
--- a/lib/stdbit.in.h
+++ b/lib/stdbit.in.h
@@ -205,7 +205,7 @@ extern "C" {
# define __STDC_ENDIAN_NATIVE__ __STDC_ENDIAN_LITTLE__
#endif
-#endif
+#endif /* !__STDC_VERSION_STDBIT_H__ */
/* Some systems are only missing C2y features in stdbit.h. */
@@ -1153,12 +1153,15 @@ stdc_bit_width_ull (unsigned long long int n)
#endif
+#endif /* !__STDC_VERSION_STDBIT_H__ */
+
/* ISO C 23 § 7.18.15 Bit Floor */
#if @GNULIB_STDC_BIT_FLOOR@
-# if !GNULIB_defined_stdc_bit_floor_functions
+# if !defined __STDC_VERSION_STDBIT_H__
+# if !GNULIB_defined_stdc_bit_floor_functions
_GL_STDC_BIT_FLOOR_INLINE unsigned char
stdc_bit_floor_uc (unsigned char n)
@@ -1190,17 +1193,22 @@ stdc_bit_floor_ull (unsigned long long int n)
return n ? 1ull << (stdc_bit_width_ull (n) - 1) : 0;
}
-# define GNULIB_defined_stdc_bit_floor_functions 1
+# define GNULIB_defined_stdc_bit_floor_functions 1
+# endif
# endif
-# define stdc_bit_floor(n) \
- (_GL_STDBIT_TYPEOF_CAST \
- (n, \
- (sizeof (n) == 1 ? stdc_bit_floor_uc (n) \
- : sizeof (n) == sizeof (unsigned short int) ? stdc_bit_floor_us (n) \
- : sizeof (n) == sizeof 0u ? stdc_bit_floor_ui (n) \
- : sizeof (n) == sizeof 0ul ? stdc_bit_floor_ul (n) \
- : stdc_bit_floor_ull (n))))
+# if !defined __STDC_VERSION_STDBIT_H__ \
+ || (defined __sun && defined _SYS_STDBIT_H)
+# undef stdc_bit_floor
+# define stdc_bit_floor(n) \
+ (_GL_STDBIT_TYPEOF_CAST \
+ (n, \
+ (sizeof (n) == 1 ? stdc_bit_floor_uc (n) \
+ : sizeof (n) == sizeof (unsigned short int) ? stdc_bit_floor_us (n) \
+ : sizeof (n) == sizeof 0u ? stdc_bit_floor_ui (n) \
+ : sizeof (n) == sizeof 0ul ? stdc_bit_floor_ul (n) \
+ : stdc_bit_floor_ull (n))))
+# endif
#endif
@@ -1209,7 +1217,8 @@ stdc_bit_floor_ull (unsigned long long int n)
#if @GNULIB_STDC_BIT_CEIL@
-# if !GNULIB_defined_stdc_bit_ceil_functions
+# if !defined __STDC_VERSION_STDBIT_H__
+# if !GNULIB_defined_stdc_bit_ceil_functions
_GL_STDC_BIT_CEIL_INLINE unsigned char
stdc_bit_ceil_uc (unsigned char n)
@@ -1241,22 +1250,25 @@ stdc_bit_ceil_ull (unsigned long long int n)
return n <= 1 ? 1 : 2ull << (stdc_bit_width_ull (n - 1) - 1);
}
-# define GNULIB_defined_stdc_bit_ceil_functions 1
+# define GNULIB_defined_stdc_bit_ceil_functions 1
+# endif
# endif
-# define stdc_bit_ceil(n) \
- (_GL_STDBIT_TYPEOF_CAST \
- (n, \
- (sizeof (n) == 1 ? stdc_bit_ceil_uc (n) \
- : sizeof (n) == sizeof (unsigned short int) ? stdc_bit_ceil_us (n) \
- : sizeof (n) == sizeof 0u ? stdc_bit_ceil_ui (n) \
- : sizeof (n) == sizeof 0ul ? stdc_bit_ceil_ul (n) \
- : stdc_bit_ceil_ull (n))))
+# if !defined __STDC_VERSION_STDBIT_H__ \
+ || (defined __sun && defined _SYS_STDBIT_H)
+# undef stdc_bit_ceil
+# define stdc_bit_ceil(n) \
+ (_GL_STDBIT_TYPEOF_CAST \
+ (n, \
+ (sizeof (n) == 1 ? stdc_bit_ceil_uc (n) \
+ : sizeof (n) == sizeof (unsigned short int) ? stdc_bit_ceil_us (n) \
+ : sizeof (n) == sizeof 0u ? stdc_bit_ceil_ui (n) \
+ : sizeof (n) == sizeof 0ul ? stdc_bit_ceil_ul (n) \
+ : stdc_bit_ceil_ull (n))))
+# endif
#endif
-#endif /* !__STDC_VERSION_STDBIT_H__ */
-
/* ISO C2y § 7.18.17 Rotate Left */