From cad45b07a4070556fc0df2ee4ad13d521f34a091 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@partin.io>
Date: Wed, 23 Sep 2026 06:12:21 +0000
Subject: [PATCH v2 3/8] Keep the alignas() placeholder the same width in
 pgindent

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 <tristan@partin.io>
Signed-off-by: Tristan Partin <tristan@partin.io>
---
 src/tools/pgindent/pgindent | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index eea6c0ad734..6f4b7cbc92a 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -239,6 +239,17 @@ sub write_source
 # by post_indent().
 my @alignas_stash;
 
+sub stash_alignas
+{
+	my $text = shift;
+
+	push(@alignas_stash, $text);
+	my $tag = 'alignas_' . $#alignas_stash;
+	$tag .= '_' x (length($text) - length($tag))
+	  if length($text) > length($tag);
+	return $tag;
+}
+
 sub pre_indent
 {
 	my $source = shift;
@@ -276,8 +287,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 +298,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;
-- 
Tristan Partin
https://tristan.partin.io

