Re: Refactor compile-time assertion checks for C/C++

2020-03-25 Thread Michael Paquier
On Mon, Mar 23, 2020 at 12:22:48AM -0400, Tom Lane wrote: > Yeah, the comment needs an update; but if we have four implementations > then it ought to describe each of them, IMO. I got an idea as per the attached. Perhaps you have a better idea? -- Michael diff --git a/src/include/c.h b/src/includ

Re: Refactor compile-time assertion checks for C/C++

2020-03-22 Thread Tom Lane
Michael Paquier writes: > On Sat, Mar 21, 2020 at 07:22:41PM -0400, Tom Lane wrote: >> Maybe we should just revert b7f64c64d instead of putting more time >> into this. It's looking like we're going to end up with four or so >> implementations no matter what, so it's getting hard to see any >> rea

Re: Refactor compile-time assertion checks for C/C++

2020-03-22 Thread Michael Paquier
On Sat, Mar 21, 2020 at 07:22:41PM -0400, Tom Lane wrote: > which of course is pointing at > > StaticAssertStmt(((int64) -1 >> 1) == (int64) -1, > "arithmetic right shift is needed"); > > so the existing "C and C++" fallback StaticAssertStmt doesn't work for > older g++.

Re: Refactor compile-time assertion checks for C/C++

2020-03-21 Thread Tom Lane
Michael Paquier writes: > The fun does not stop here. gcc is fine when using that for C and > C++: > #define StaticAssertStmt(condition, errmessage) \ >do { struct static_assert_struct { int static_assert_failure : (condition) > ? 1 : -1; }; } while(0) > #define StaticAssertExpr(condition, e

Re: Refactor compile-time assertion checks for C/C++

2020-03-16 Thread Michael Paquier
On Mon, Mar 16, 2020 at 10:35:05PM -0400, Tom Lane wrote: > Michael Paquier writes: >> C++ does not allow defining a struct inside a sizeof() call, so in >> this case StaticAssertExpr() does not work with the previous extension >> in C++. StaticAssertStmt() does the work though. > > [ scratches

Re: Refactor compile-time assertion checks for C/C++

2020-03-16 Thread Tom Lane
Michael Paquier writes: > On Mon, Mar 16, 2020 at 10:32:36AM -0400, Tom Lane wrote: >> Sorry for being unclear --- I just meant that we could use do{} >> in StaticAssertStmt for both C and C++. Although now I notice >> that the code is trying to use StaticAssertStmt for StaticAssertExpr, >> which

Re: Refactor compile-time assertion checks for C/C++

2020-03-16 Thread Michael Paquier
On Mon, Mar 16, 2020 at 10:32:36AM -0400, Tom Lane wrote: > Sorry for being unclear --- I just meant that we could use do{} > in StaticAssertStmt for both C and C++. Although now I notice > that the code is trying to use StaticAssertStmt for StaticAssertExpr, > which you're right isn't going to do

Re: Refactor compile-time assertion checks for C/C++

2020-03-16 Thread Tom Lane
Michael Paquier writes: > On Fri, Mar 13, 2020 at 11:00:33AM -0400, Tom Lane wrote: >> If we do need to change it, I'd be inclined to just use the do{} >> block everywhere, not bothering with the extra #if test. > Not sure what you mean here because we cannot use the do{} flavor > either for the

Re: Refactor compile-time assertion checks for C/C++

2020-03-15 Thread Michael Paquier
On Fri, Mar 13, 2020 at 11:00:33AM -0400, Tom Lane wrote: > Michael Paquier writes: >> Hmm. v3 actually broke the C++ fallback of StaticAssertExpr() and >> StaticAssertStmt() (v1 did not), a simple fix being something like >> the attached. > > The buildfarm seems happy, so why do you think it's

Re: Refactor compile-time assertion checks for C/C++

2020-03-13 Thread Tom Lane
Michael Paquier writes: > Hmm. v3 actually broke the C++ fallback of StaticAssertExpr() and > StaticAssertStmt() (v1 did not), a simple fix being something like > the attached. The buildfarm seems happy, so why do you think it's broken? If we do need to change it, I'd be inclined to just use th

Re: Refactor compile-time assertion checks for C/C++

2020-03-13 Thread Michael Paquier
On Fri, Mar 13, 2020 at 03:12:34PM +0900, Michael Paquier wrote: > On Thu, Mar 12, 2020 at 09:43:54AM -0400, Tom Lane wrote: >> I don't feel a need to expend a whole lot of sweat there. The existing >> text is fine, it just bugged me that the code deals with three cases >> while the comment block

Re: Refactor compile-time assertion checks for C/C++

2020-03-12 Thread Michael Paquier
On Thu, Mar 12, 2020 at 09:43:54AM -0400, Tom Lane wrote: > I don't feel a need to expend a whole lot of sweat there. The existing > text is fine, it just bugged me that the code deals with three cases > while the comment block only acknowledged two. So I'd just go with > what you have in v3. Th

Re: Refactor compile-time assertion checks for C/C++

2020-03-12 Thread Tom Lane
Michael Paquier writes: > So, should we add a reference about both in the new comment? I would > actually not add them, so I have used your suggestion in the attached, > but the comment block above does that for _Static_assert(). Do you > think it is better to add some references to some of thos

Re: Refactor compile-time assertion checks for C/C++

2020-03-12 Thread Michael Paquier
On Thu, Mar 12, 2020 at 12:33:21AM -0400, Tom Lane wrote: > I looked at this and tried it on an old (non HAVE__STATIC_ASSERT) > gcc version. Seems to work, but I have a couple cosmetic suggestions: Thanks for the review. > 1. The comment block above this was never updated to mention that > we're

Re: Refactor compile-time assertion checks for C/C++

2020-03-11 Thread Tom Lane
Michael Paquier writes: > Indeed the bot is happy now. By looking at the patch, one would note > that what it just does is unifying the fallback "hack-ish" > implementations so as C and C++ use the same thing, which is the > fallback implementation for C of HEAD. I would prefer hear first from >

Re: Refactor compile-time assertion checks for C/C++

2020-03-11 Thread Michael Paquier
On Wed, Mar 11, 2020 at 12:31:19PM +, Georgios Kokolatos wrote: > For whatever is worth, my previous comment that the patch improves > readability also applies to the updated version of the patch. v2 has actually less diffs for the C++ part. > The CF bot seems happy now, which means that your

Re: Refactor compile-time assertion checks for C/C++

2020-03-11 Thread Georgios Kokolatos
Thank you for updating the status of the issue. I have to admit that I completely missed the CF bot. Lesson learned. For whatever is worth, my previous comment that the patch improves readability also applies to the updated version of the patch. The CF bot seems happy now, which means that your

Re: Refactor compile-time assertion checks for C/C++

2020-03-11 Thread Michael Paquier
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_asse

Re: Refactor compile-time assertion checks for C/C++

2020-03-07 Thread Tom Lane
Michael Paquier writes: > As of [1], I have been playing with the compile time assertions that > we have for expressions, declarations and statements. And it happens > that it is visibly possible to consolidate the fallback > implementations for C and C++. Attached is the result of what I am > g

Re: Refactor compile-time assertion checks for C/C++

2020-03-04 Thread Georgios Kokolatos
The following review has been posted through the commitfest application: make installcheck-world: not tested Implements feature: not tested Spec compliant: not tested Documentation:not tested In my humble opinion the patch improves readability, hence gets my +1. No fu

Refactor compile-time assertion checks for C/C++

2020-02-04 Thread Michael Paquier
Hi all, As of [1], I have been playing with the compile time assertions that we have for expressions, declarations and statements. And it happens that it is visibly possible to consolidate the fallback implementations for C and C++. Attached is the result of what I am getting at. I am adding th