Work around buggy alignas in older g++ master github/master
authorPeter Eisentraut <peter@eisentraut.org>
Sun, 25 Jan 2026 10:16:58 +0000 (11:16 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Sun, 25 Jan 2026 10:32:47 +0000 (11:32 +0100)
Older g++ (<9.3) mishandle the alignas specifier (raise warnings that
the alignment is too large), but the more or less equivalent attribute
works.  So as a workaround, #define alignas to that attribute for
those versions.

see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89357>

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/3119480.1769189606%40sss.pgh.pa.us

src/include/c.h

index c0be07a45663c1883d0f120681ebda615120be1b..17afaef9a6a1b9943a21ece685e53c13cb74cbc3 100644 (file)
  */
 #endif
 
+/*
+ * alignas is buggy in g++ < 9, but the more or less equivalent attribute
+ * works.
+ *
+ * <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89357>
+ */
+#if defined(__cplusplus) && defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 9
+#define alignas(a) __attribute__((aligned(a)))
+#endif
+
 /*
  * Use "pg_attribute_always_inline" in place of "inline" for functions that
  * we wish to force inlining of, even when the compiler's heuristics would