On Sat, Mar 07, 2020 at 04:44:48PM -0500, Tom Lane wrote: > cfbot reports this doesn't work with MSVC. Not sure why --- maybe > it defines __cpp_static_assert differently than you're expecting?
I don't think that's the issue. The CF bot uses MSVC 12.0 which refers to the 2013. __cpp_static_assert being introduced in MSVC 2017, this error is visibly telling us that this environment does not like the C++ fallback implementation, which is actually what my previous version of the patch was using (I can reproduce the error with my MSVC 2015 VM as well). I think that this points to an error in the patch: for the refactoring, the fallback implementation of C and C++ should use the fallback implementation for C that we have currently on HEAD. With the updated patch attached, the error goes away for me. Let's see what Mr. Robot thinks. The patch was marked as ready for committer, I am switching it back to "Needs review". -- Michael
From 562926d03172332457a328c5329cdac61cf7d99d Mon Sep 17 00:00:00 2001 From: Michael Paquier <mich...@paquier.xyz> Date: Tue, 4 Feb 2020 17:09:59 +0900 Subject: [PATCH v2] Refactor assertion definitions in c.h This unifies the C and C++ fallback implementations. --- src/include/c.h | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/include/c.h b/src/include/c.h index 831c89f473..9f318e16d0 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -840,39 +840,32 @@ extern void ExceptionalCondition(const char *conditionName, * about a negative width for a struct bit-field. This will not include a * helpful error message, but it beats not getting an error at all. */ -#ifndef __cplusplus -#ifdef HAVE__STATIC_ASSERT +#if !defined(__cplusplus) && defined(HAVE__STATIC_ASSERT) +/* Default C implementation */ #define StaticAssertStmt(condition, errmessage) \ do { _Static_assert(condition, errmessage); } while(0) #define StaticAssertExpr(condition, errmessage) \ ((void) ({ StaticAssertStmt(condition, errmessage); true; })) #define StaticAssertDecl(condition, errmessage) \ _Static_assert(condition, errmessage) -#else /* !HAVE__STATIC_ASSERT */ -#define StaticAssertStmt(condition, errmessage) \ - ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; })) -#define StaticAssertExpr(condition, errmessage) \ - StaticAssertStmt(condition, errmessage) -#define StaticAssertDecl(condition, errmessage) \ - extern void static_assert_func(int static_assert_failure[(condition) ? 1 : -1]) -#endif /* HAVE__STATIC_ASSERT */ -#else /* C++ */ -#if defined(__cpp_static_assert) && __cpp_static_assert >= 200410 +#elif defined(__cplusplus) && \ + defined(__cpp_static_assert) && __cpp_static_assert >= 200410 +/* Default C++ implementation */ #define StaticAssertStmt(condition, errmessage) \ static_assert(condition, errmessage) #define StaticAssertExpr(condition, errmessage) \ ({ static_assert(condition, errmessage); }) #define StaticAssertDecl(condition, errmessage) \ static_assert(condition, errmessage) -#else /* !__cpp_static_assert */ +#else +/* Fallback implementation for C and C++ */ #define StaticAssertStmt(condition, errmessage) \ - do { struct static_assert_struct { int static_assert_failure : (condition) ? 1 : -1; }; } while(0) + ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; })) #define StaticAssertExpr(condition, errmessage) \ - ((void) ({ StaticAssertStmt(condition, errmessage); })) + StaticAssertStmt(condition, errmessage) #define StaticAssertDecl(condition, errmessage) \ extern void static_assert_func(int static_assert_failure[(condition) ? 1 : -1]) -#endif /* __cpp_static_assert */ -#endif /* C++ */ +#endif /* -- 2.25.1
signature.asc
Description: PGP signature