| From: | Peter Eisentraut <peter(at)eisentraut(dot)org> |
|---|---|
| To: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Portable StaticAssertExpr |
| Date: | 2026-02-23 07:00:35 |
| Message-ID: | 5fa3a9f5-eb9a-4408-9baf-403d281f8b10@eisentraut.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
The current implementation of StaticAssertExpr() uses the GCC extension
statement expressions.
In this patch, I'm proposing a different implementation that doesn't
require nonstandard extensions. The trick is to put the static_assert()
into a struct definition. This appears to be a common way to do this.
(See [0] for references.)
Unfortunately, MSVC before version 19.33 fails to compile this, but
since it was fixed later, I think this was just a bug that was later
fixed. I'm keeping the old workaround code as a fallback for this case,
but eventually we can remove that.
For C++, the struct trick doesn't work, but I found a different
implementation that works on all supported compilers, using lambda
expressions. I found this at [1].
[0]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3715.pdf
[1]: https://stackoverflow.com/questions/31311748
| Attachment | Content-Type | Size |
|---|---|---|
| 0001-Portable-StaticAssertExpr.patch | text/plain | 5.7 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Peter Eisentraut | 2026-02-23 07:12:41 | Check for memset_explicit() and explicit_memset() |
| Previous Message | Daniel Westermann (DWE) | 2026-02-23 06:58:17 | Re: 2026-02-26 release announcement draft |