From 305cbed95d197dfa2ea946678c0abd26113654eb Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 2 Oct 2026 07:36:55 +0200 Subject: [PATCH] pgindent: Keep the alignas() placeholder the same width pre_indent() hides each alignas(...) call from pg_bsd_indent behind a plain identifier, because pg_bsd_indent has a fixed table of declaration keywords and lexes anything else followed by "(" as the start of an expression. The placeholder was not the same width as the text it stood in for, though, and pg_bsd_indent decides where to put a trailing comment from the width of the code preceding it. A member declared with alignas() and carrying a trailing comment therefore got the comment separated by a tab where the real width calls for a single space, or the other way round. Pad the placeholder out to the original width so that the decision is made on the real width. No member currently declared with alignas() has a trailing comment, so this changes nothing in the tree today; it is a correctness fix for the helper. Author: Tristan Partin Co-authored-by: Peter Eisentraut Discussion: https://www.postgresql.org/message-id/flat/DKBEBF32QLUA.3L2DJRPUYNKHZ%40partin.io --- src/tools/pgindent/pgindent | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent index eea6c0ad734..ae11a5b7dde 100755 --- a/src/tools/pgindent/pgindent +++ b/src/tools/pgindent/pgindent @@ -239,6 +239,24 @@ sub write_source # by post_indent(). my @alignas_stash; +sub stash_alignas +{ + my $text = shift; + + push(@alignas_stash, $text); + my $index = $#alignas_stash; + + # Pad the placeholder with underscores so that it is as wide as + # the text it stands in for, so that trailing comments on the line + # are placed correctly. The padding goes before the index, so + # that the placeholder ends in a digit and doesn't accidentally + # swallow a following token. + my $pad = length($text) - length('alignas') - length($index); + $pad = 1 if $pad < 1; + + return 'alignas' . '_' x $pad . $index; +} + sub pre_indent { my $source = shift; @@ -276,8 +294,7 @@ sub pre_indent \b alignas \s* ( \( (?: [^()]++ | (?1) )*+ \) ) ! - push(@alignas_stash, "alignas" . $1); - "alignas_" . $#alignas_stash . "_"; + stash_alignas("alignas" . $1); !gex; return $source; @@ -288,7 +305,7 @@ sub post_indent my $source = shift; # Restore alignas(...) - $source =~ s!\balignas_(\d+)_!$alignas_stash[$1]!g; + $source =~ s!\balignas_+(\d+)!$alignas_stash[$1]!g; # Restore CATALOG lines $source =~ s!^/\*(CATALOG\(.*)\*/$!$1!gm;