Hi Bruno, Bruno Haible <br...@clisp.org> writes:
> Also, I see that MSVC is not well covered by this default in stdbit.in.h: > > #else > /* This platform is so old that it lacks typeof, so _Generic is likely > missing or unreliable. The C23 standard seems to allow yielding B > (which is always unsigned long long int), so do that. */ > # define _GL_STDBIT_TYPEOF_CAST(a, b) (b) > #endif > > Can it be improved? Good point. I see that MSVC supports both typeof and __typeof__ since Visual Studio 17.9. The difference is 'typeof' requires compiling with the latest language standard, but '__typeof__' can be used with any language version [1]. I've applied the two attached patches to detect them in stdbit-h and intprops using the _MSC_VER [2]. Collin [1] https://learn.microsoft.com/en-us/cpp/c-language/typeof-c?view=msvc-170 [2] https://learn.microsoft.com/en-us/cpp/overview/compiler-versions?view=msvc-170#version-macros
>From 1a9d52aadabd3862168da43926ab4518bd7ae02f Mon Sep 17 00:00:00 2001 From: Collin Funk <collin.fu...@gmail.com> Date: Thu, 19 Dec 2024 17:53:48 -0800 Subject: [PATCH 1/2] stdbit-h: Detect MSVC __typeof__ support. * lib/stdbit.in.h (_GL_STDBIT_TYPEOF_CAST): Use __typeof__ on Visual Studio 2022 version 17.9 and later. --- ChangeLog | 6 ++++++ lib/stdbit.in.h | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index cf98e92c62..59fa232bd7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2024-12-19 Collin Funk <collin.fu...@gmail.com> + + stdbit-h: Detect MSVC __typeof__ support. + * lib/stdbit.in.h (_GL_STDBIT_TYPEOF_CAST): Use __typeof__ on Visual + Studio 2022 version 17.9 and later. + 2024-12-18 Pádraig Brady <p...@draigbrady.com> crc-x86_64: fix build failure due to indentation diff --git a/lib/stdbit.in.h b/lib/stdbit.in.h index 20b9f4f466..91d237d7ad 100644 --- a/lib/stdbit.in.h +++ b/lib/stdbit.in.h @@ -77,7 +77,8 @@ _GL_INLINE_HEADER_BEGIN #if ((defined __GNUC__ && 2 <= __GNUC__) \ || (defined __clang_major__ && 4 <= __clang_major__) \ || (defined __IBMC__ && 1210 <= __IBMC__ && defined __IBM__TYPEOF__) \ - || (defined __SUNPRO_C && 0x5110 <= __SUNPRO_C && !__STDC__)) + || (defined __SUNPRO_C && 0x5110 <= __SUNPRO_C && !__STDC__) \ + || (defined _MSC_VER && 1939 <= _MSC_VER)) # define _GL_STDBIT_TYPEOF_CAST(a, b) ((__typeof__ (a)) (b)) #elif 202311 <= __STDC_VERSION__ # define _GL_STDBIT_TYPEOF_CAST(a, b) ((typeof (a)) (b)) -- 2.47.1
>From 9e301775ffce832647850c1103008303e64688c9 Mon Sep 17 00:00:00 2001 From: Collin Funk <collin.fu...@gmail.com> Date: Thu, 19 Dec 2024 17:59:57 -0800 Subject: [PATCH 2/2] intprops: Detect MSVC __typeof__ support. * lib/intprops-internal.h (_GL_HAVE___TYPEOF__): Copy condition from lib/stdbit.in.h. --- ChangeLog | 4 ++++ lib/intprops-internal.h | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 59fa232bd7..4a453a39f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2024-12-19 Collin Funk <collin.fu...@gmail.com> + intprops: Detect MSVC __typeof__ support. + * lib/intprops-internal.h (_GL_HAVE___TYPEOF__): Copy condition from + lib/stdbit.in.h. + stdbit-h: Detect MSVC __typeof__ support. * lib/stdbit.in.h (_GL_STDBIT_TYPEOF_CAST): Use __typeof__ on Visual Studio 2022 version 17.9 and later. diff --git a/lib/intprops-internal.h b/lib/intprops-internal.h index c8cc0e2019..0b7e1f539a 100644 --- a/lib/intprops-internal.h +++ b/lib/intprops-internal.h @@ -77,10 +77,11 @@ /* Does the __typeof__ keyword work? This could be done by 'configure', but for now it's easier to do it by hand. */ -#if (2 <= __GNUC__ \ - || (4 <= __clang_major__) \ - || (1210 <= __IBMC__ && defined __IBM__TYPEOF__) \ - || (0x5110 <= __SUNPRO_C && !__STDC__)) +#if ((defined __GNUC__ && 2 <= __GNUC__) \ + || (defined __clang_major__ && 4 <= __clang_major__) \ + || (defined __IBMC__ && 1210 <= __IBMC__ && defined __IBM__TYPEOF__) \ + || (defined __SUNPRO_C && 0x5110 <= __SUNPRO_C && !__STDC__) \ + || (defined _MSC_VER && 1939 <= _MSC_VER)) # define _GL_HAVE___TYPEOF__ 1 #else # define _GL_HAVE___TYPEOF__ 0 -- 2.47.1