Re: Gnulib's use of _Atomic, and hamt

Bruno Haible via Gnulib discussion list <[email protected]>
Newsgroups gmane.comp.lib.gnulib.bugs
Message-ID <4680138.tiCG3LdiiZ@cagnes>
Paul Eggert wrote:
> I attempted to fix these problems by installing the attached patches.

This also produces a compilation error on MSVC:

/cygdrive/d/a/ci-testdir-check/ci-testdir-check/compile cl -nologo -std:c11 -DHAVE_CONFIG_H -DEXEEXT=\".exe\" -DEXEEXT=\".exe\" -DNO_XMALLOC -DEXEEXT=\".exe\" -I. -I../../gllib -I..  -DGNULIB_STRICT_CHECKING=1 -D_WIN32_WINNT=_WIN32_WINNT_WINXP -I/usr/local/msvc32/include -DCONTINUE_AFTER_ASSERT  -MD -c -o hamt.obj `cygpath -w '../../gllib/hamt.c'`
hamt.c
D:\a\ci-testdir-check\ci-testdir-check\testdir-all\gllib\hamt.h(71): fatal error C1012: unmatched parenthesis: missing ')'
make[4]: *** [Makefile:12128: hamt.obj] Error 2

MSVC apparently has a problem parsing nested conditional expressions inside #if.
(I had already noticed this some time ago.)

This patch fixes it:


2026-08-12  Bruno Haible  <[email protected]>

	hamt: Fix compilation error on MSVC (regression 2026-08-10).
	* lib/hamt.h (HAVE_C11__ATOMIC): Add parentheses to #if expression.

diff --git a/lib/hamt.h b/lib/hamt.h
index 8430313811..0e4ccc603e 100644
--- a/lib/hamt.h
+++ b/lib/hamt.h
@@ -68,13 +68,14 @@ _GL_INLINE_HEADER_BEGIN
 #ifndef HAVE_C11__ATOMIC
 # if (!defined __STDC_NO_ATOMICS__ && !defined __cplusplus \
       && (defined __apple_build_version__ ? 8000000 <= __apple_build_version__ \
-          : defined __clang__ ? 4 <= __clang_major__ \
-          : defined _MSC_VER ? 1935 <= _MSC_VER \
-          : defined __NVCOMPILER \
-          ? 21 < __NVCOMPILER_MAJOR__ + (3 <= __NVCOMPILER_MINOR__) \
-          : defined __GNUC__ ? 4 < __GNUC__ + (9 <= __GNUC_MINOR__) \
-          : (!defined __xlC__ && !defined __PGI \
-             && defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__)))
+          : (defined __clang__ ? 4 <= __clang_major__ \
+             : (defined _MSC_VER ? 1935 <= _MSC_VER \
+                : (defined __NVCOMPILER \
+                   ? 21 < __NVCOMPILER_MAJOR__ + (3 <= __NVCOMPILER_MINOR__) \
+                   : (defined __GNUC__ ? 4 < __GNUC__ + (9 <= __GNUC_MINOR__) \
+                      : (!defined __xlC__ && !defined __PGI \
+                         && defined __STDC_VERSION__ \
+                         && 201112 <= __STDC_VERSION__)))))))
 #  define HAVE_C11__ATOMIC 1
 # else
 #  define HAVE_C11__ATOMIC 0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.