Re: alignas (C11)
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Eisentraut <peter@eisentraut.org>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2026-01-23T17:33:26Z
Lists: pgsql-hackers
Peter Eisentraut <peter@eisentraut.org> writes:
> This patch set has been committed, it looks like without buildfarm
> complaints.
Things were fine until test_cplusplusext was added, but now
some older compilers seem to reject this in C++ mode.
For example at [1]:
make[1]: Entering directory '/home/debian/20-chimaera/buildroot/HEAD/pgsql.build/src/test/modules/test_cplusplusext'
g++ -Wall -Wpointer-arith -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O2 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -I. -I/home/debian/20-chimaera/buildroot/HEAD/pgsql.build/../pgsql/src/test/modules/test_cplusplusext -I../../../../src/include -I/home/debian/20-chimaera/buildroot/HEAD/pgsql.build/../pgsql/src/include -D_GNU_SOURCE -I/usr/include/libxml2 -c -o test_cplusplusext.o /home/debian/20-chimaera/buildroot/HEAD/pgsql.build/../pgsql/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
In file included from /home/debian/20-chimaera/buildroot/HEAD/pgsql.build/../pgsql/src/include/postgres.h:48:0,
from /home/debian/20-chimaera/buildroot/HEAD/pgsql.build/../pgsql/src/test/modules/test_cplusplusext/test_cplusplusext.cpp:18:
/home/debian/20-chimaera/buildroot/HEAD/pgsql.build/../pgsql/src/include/c.h:1126:44: warning: requested alignment 4096 is larger than 128 [-Wattributes]
alignas(PG_IO_ALIGN_SIZE) char data[BLCKSZ];
^
/home/debian/20-chimaera/buildroot/HEAD/pgsql.build/../pgsql/src/include/c.h:1132:49: warning: requested alignment 4096 is larger than 128 [-Wattributes]
alignas(PG_IO_ALIGN_SIZE) char data[XLOG_BLCKSZ];
^
Not sure what to do about that, but I do read it as indicating that we
cannot put any faith in the compiler to honor such large alignment
demands.
A possible short-term(?) workaround is to wrap those two declarations
in "#ifndef __cplusplus", so that C++ code can't declare such
variables.
regards, tom lane
[1] https://buildfarm.postgresql.org/cgi-bin/show_stage_log.pl?nm=chimaera&dt=2026-01-23%2011%3A44%3A01&stg=make-testmodules
Commits
-
Further fix extended alignment for older g++.
- bd9dfac8b121 19 (unreleased) landed
-
Disable extended alignment uses on older g++
- 6ceef9408c26 19 (unreleased) landed
-
Work around buggy alignas in older g++
- a9bdb63bba8a 19 (unreleased) landed
-
Use C11 alignas in pg_atomic_uint64 definitions
- e7075a3405cc 19 (unreleased) landed
-
C11 alignas instead of unions -- extended alignments
- d4c0f91f7d57 19 (unreleased) landed
-
C11 alignas instead of unions
- 97e04c74bedb 19 (unreleased) landed
-
Add <stdalign.h> to c.h
- 300c8f532478 19 (unreleased) landed