[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
stdbool, stdbool-c99 tests: Fix compilation error with clang/MSVC
From: |
Bruno Haible |
Subject: |
stdbool, stdbool-c99 tests: Fix compilation error with clang/MSVC |
Date: |
Mon, 19 Sep 2022 21:44:54 +0200 |
On native Windows, with clang compiler and MSVC header files, I get this
compilation errors:
source='../../gltests/test-stdbool-c99.c' object='test-stdbool-c99.obj'
libtool=no \
DEPDIR=.deps depmode=msvc7 /bin/sh ../../build-aux/depcomp \
/home/bruno/msvc/compile clang-cl -ferror-limit=0 -DHAVE_CONFIG_H
-DEXEEXT=\".exe\" -I. -I../../gltests -I.. -DGNULIB_STRICT_CHECKING=1
-DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. -I../../gltests/.. -I../gllib
-I../../gltests/../gllib -D_WIN32_WINNT=_WIN32_WINNT_WIN7
-I/usr/local/msvcclang64/include -Wall -Wno-extra-semi-stmt
-Wno-unused-function -Wno-inconsistent-dllimport -Wno-reserved-id-macro
-Wno-undef -Wno-missing-field-initializers -Wno-unused-parameter
-Wno-gnu-include-next -Wno-implicit-int-conversion -Wno-sign-compare
-Wno-sign-conversion -Wno-comma -Wno-unused-macros
-Wno-nonportable-system-include-path -Wno-format-nonliteral
-Wno-deprecated-declarations -Wno-tautological-unsigned-zero-compare
-Wno-used-but-marked-unused -Wno-parentheses-equality -Wno-error -MD -O2 -c -o
test-stdbool-c99.obj `cygpath -w '../../gltests/test-stdbool-c99.c'`
In file included from
C:\cygwin64\home\bruno\testdir-all-windows\gltests\test-stdbool-c99.c:2:
In file included from ../../gltests/test-stdbool.c:34:
In file included from ..\config.h:7740:
../gllib\assert.h(276,12): warning: keyword is hidden by macro definition
[-Wkeyword-macro]
# define static_assert _Static_assert /* C11 requires this #define. */
^
In file included from
C:\cygwin64\home\bruno\testdir-all-windows\gltests\test-stdbool-c99.c:2:
../../gltests/test-stdbool.c(63,8): error: 'd' declared as an array with a
negative size
char d[(bool) 0.5 == true ? 1 : -1];
^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../gltests/test-stdbool.c(69,6): warning: incompatible pointer to integer
conversion initializing 'signed char' with an expression of type 'struct s *'
[-Wint-conversion]
bool e = &s;
^ ~~
../../gltests/test-stdbool.c(69,10): error: initializer element is not a
compile-time constant
bool e = &s;
^~
16 warnings and 2 errors generated.
make[4]: *** [Makefile:23273: test-stdbool-c99.obj] Error 1
source='../../gltests/test-stdbool.c' object='test-stdbool.obj' libtool=no \
DEPDIR=.deps depmode=msvc7 /bin/sh ../../build-aux/depcomp \
/home/bruno/msvc/compile clang-cl -ferror-limit=0 -DHAVE_CONFIG_H
-DEXEEXT=\".exe\" -I. -I../../gltests -I.. -DGNULIB_STRICT_CHECKING=1
-DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. -I../../gltests/.. -I../gllib
-I../../gltests/../gllib -D_WIN32_WINNT=_WIN32_WINNT_WIN7
-I/usr/local/msvcclang64/include -Wall -Wno-extra-semi-stmt
-Wno-unused-function -Wno-inconsistent-dllimport -Wno-reserved-id-macro
-Wno-undef -Wno-missing-field-initializers -Wno-unused-parameter
-Wno-gnu-include-next -Wno-implicit-int-conversion -Wno-sign-compare
-Wno-sign-conversion -Wno-comma -Wno-unused-macros
-Wno-nonportable-system-include-path -Wno-format-nonliteral
-Wno-deprecated-declarations -Wno-tautological-unsigned-zero-compare
-Wno-used-but-marked-unused -Wno-parentheses-equality -Wno-error -MD -O2 -c -o
test-stdbool.obj `cygpath -w '../../gltests/test-stdbool.c'`
In file included from
C:\cygwin64\home\bruno\testdir-all-windows\gltests\test-stdbool.c:34:
In file included from ..\config.h:7740:
../gllib\assert.h(276,12): warning: keyword is hidden by macro definition
[-Wkeyword-macro]
# define static_assert _Static_assert /* C11 requires this #define. */
^
C:\cygwin64\home\bruno\testdir-all-windows\gltests\test-stdbool.c(63,8): error:
'd' declared as an array with a negative size
char d[(bool) 0.5 == true ? 1 : -1];
^~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\cygwin64\home\bruno\testdir-all-windows\gltests\test-stdbool.c(69,6):
warning: incompatible pointer to integer conversion initializing 'signed char'
with an expression of type 'struct s *' [-Wint-conversion]
bool e = &s;
^ ~~
C:\cygwin64\home\bruno\testdir-all-windows\gltests\test-stdbool.c(69,10):
error: initializer element is not a compile-time constant
bool e = &s;
^~
16 warnings and 2 errors generated.
make[4]: *** [Makefile:23273: test-stdbool.obj] Error 1
Apparently, this version of clang disguises so well as MSVC (it defines
both __clang_major__ and _MSC_VER !) that it emulates MSVC's bool-related
non-compliance.
This patch fixes the compilation error.
2022-09-19 Bruno Haible <bruno@clisp.org>
stdbool, stdbool-c99 tests: Fix compilation error with clang/MSVC.
* tests/test-stdbool.c (WORKING_BOOL): Define to 0 on compilers that
define _MSC_VER.
diff --git a/tests/test-stdbool.c b/tests/test-stdbool.c
index 73c871e869..923a2cd302 100644
--- a/tests/test-stdbool.c
+++ b/tests/test-stdbool.c
@@ -46,8 +46,9 @@
/* Several tests cannot be guaranteed with gnulib's <stdbool.h>, at
least, not for all compilers and compiler options. */
-#if (HAVE_C_BOOL || defined __cplusplus \
- || HAVE_STDBOOL_H || 3 <= __GNUC__ || 4 <= __clang_major__)
+#if ((HAVE_C_BOOL || defined __cplusplus \
+ || HAVE_STDBOOL_H || 3 <= __GNUC__ || 4 <= __clang_major__) \
+ && !defined _MSC_VER)
# define WORKING_BOOL 1
#else
# define WORKING_BOOL 0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- stdbool, stdbool-c99 tests: Fix compilation error with clang/MSVC,
Bruno Haible <=