From fd0866463b8cd4d1eb3e73a8a53c073294d03c8b Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 25 Sep 2022 00:38:15 +0200 Subject: [PATCH] stdalign: Fix compilation error with MSVC in C++ mode. * lib/stdalign.in.h: Treat MSVC in C++ mode like C++11 compliant compilers. * tests/test-stdalign-c++.cc: Include some other header files. --- ChangeLog | 5 +++++ lib/stdalign.in.h | 12 +++++++----- tests/test-stdalign-c++.cc | 4 ++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index b0223bba7e..f3468e241f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2022-09-24 Bruno Haible + stdalign: Fix compilation error with MSVC in C++ mode. + * lib/stdalign.in.h: Treat MSVC in C++ mode like C++11 compliant + compilers. + * tests/test-stdalign-c++.cc: Include some other header files. + stdalign: Avoid namespace pollution. * lib/stdalign.in.h (_GL_STDALIGN_NEEDS_STDDEF): New macro. Include only when needed. diff --git a/lib/stdalign.in.h b/lib/stdalign.in.h index 9ba40e2c45..58fd245c62 100644 --- a/lib/stdalign.in.h +++ b/lib/stdalign.in.h @@ -58,7 +58,7 @@ && !defined __clang__) \ || (defined __clang__ && __clang_major__ < 8)) # ifdef __cplusplus -# if 201103 <= __cplusplus +# if (201103 <= __cplusplus || defined _MSC_VER) # define _Alignof(type) alignof (type) # else template struct __alignof_helper { char __a; __t __b; }; @@ -70,7 +70,7 @@ # define _GL_STDALIGN_NEEDS_STDDEF 1 # endif #endif -#if ! (defined __cplusplus && 201103 <= __cplusplus) +#if ! (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER)) # define alignof _Alignof #endif #define __alignof_is_defined 1 @@ -101,7 +101,7 @@ */ #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 -# if defined __cplusplus && 201103 <= __cplusplus +# if defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER) # define _Alignas(a) alignas (a) # elif (!defined __attribute__ \ && ((defined __APPLE__ && defined __MACH__ \ @@ -115,11 +115,13 @@ # define _Alignas(a) __declspec (align (a)) # endif #endif -#if ((defined _Alignas && ! (defined __cplusplus && 201103 <= __cplusplus)) \ +#if ((defined _Alignas \ + && !(defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))) \ || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__)) # define alignas _Alignas #endif -#if defined alignas || (defined __cplusplus && 201103 <= __cplusplus) +#if (defined alignas \ + || (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))) # define __alignas_is_defined 1 #endif diff --git a/tests/test-stdalign-c++.cc b/tests/test-stdalign-c++.cc index 8d5258e5f9..598b3c1da4 100644 --- a/tests/test-stdalign-c++.cc +++ b/tests/test-stdalign-c++.cc @@ -21,6 +21,10 @@ #include +/* Check against conflicts between and the C++ header files. */ +#include +#include + int main () -- 2.39.5