From 327ac661c763b140979c54714b915e6c80d64da9 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@partin.io>
Date: Wed, 23 Sep 2026 06:24:51 +0000
Subject: [PATCH v2 4/8] Generalize the alignas() workaround to a list

alignas() may not be the only syntax that needs to be worked around, so
make the change more generic.

Author: Tristan Partin <tristan@partin.io>
Signed-off-by: Tristan Partin <tristan@partin.io>
---
 src/tools/pgindent/pgindent | 37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index 6f4b7cbc92a..67e76549f05 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -235,16 +235,21 @@ sub write_source
 	return;
 }
 
-# Text of each alignas(...) call, stashed by pre_indent() and restored
-# by post_indent().
-my @alignas_stash;
+# Declaration attributes that pg_bsd_indent doesn't know how to handle.
+my @declaration_attributes = qw(
+  alignas
+);
 
-sub stash_alignas
+# Text of each declaration attribute, stashed by pre_indent() and restored
+# by post_indent().
+my @attribute_stash;
+
+sub stash_attribute
 {
 	my $text = shift;
 
-	push(@alignas_stash, $text);
-	my $tag = 'alignas_' . $#alignas_stash;
+	push(@attribute_stash, $text);
+	my $tag = '_pgattr' . $#attribute_stash;
 	$tag .= '_' x (length($text) - length($tag))
 	  if length($text) > length($tag);
 	return $tag;
@@ -278,16 +283,16 @@ sub pre_indent
 	# Protect wrapping in CATALOG()
 	$source =~ s!^(CATALOG\(.*)$!/*$1*/!gm;
 
-	# pg_bsd_indent doesn't know about alignas(), so a non-first struct
-	# member declared with it gets misindented.  Disguise each call as
-	# a plain identifier; stash the original text rather than embed it,
-	# so nested parens or line breaks in the argument aren't a problem.
-	@alignas_stash = ();
+	# Disguise each declaration attribute as a plain identifier; stash the
+	# original text rather than embed it, so nested parens or line breaks in
+	# the argument aren't a problem.
+	@attribute_stash = ();
+	my $attribute = join('|', @declaration_attributes);
 	$source =~ s!
-		\b alignas \s*
-		( \( (?: [^()]++ | (?1) )*+ \) )
+		\b ($attribute) \s*
+		( \( (?: [^()]++ | (?2) )*+ \) )
 	!
-		stash_alignas("alignas" . $1);
+		stash_attribute($1 . $2);
 	!gex;
 
 	return $source;
@@ -297,8 +302,8 @@ sub post_indent
 {
 	my $source = shift;
 
-	# Restore alignas(...)
-	$source =~ s!\balignas_(\d+)_*!$alignas_stash[$1]!g;
+	# Restore declaration attributes
+	$source =~ s!\b_pgattr(\d+)_*!$attribute_stash[$1]!g;
 
 	# Restore CATALOG lines
 	$source =~ s!^/\*(CATALOG\(.*)\*/$!$1!gm;
-- 
Tristan Partin
https://tristan.partin.io

