postgres.git / summary / log / commit / refs

commit    884f82ae2621cc8d983bb745ce6c8c1c9a971764
Author:   Peter Eisentraut <peter@eisentraut.org>
Date:     Wed Sep 16 06:59:47 2026 +0000

    pgindent: Fix indentation of alignas() in struct members
    
    pg_bsd_indent doesn't know about alignas(), so a struct member
    declared with it is misindented unless it's the first member.
    
    Disguise each alignas(...) call as a plain identifier while
    indenting, restoring it afterward.  Stash the call's original text
    by index rather than embedding it in the placeholder: embedding only
    works for a single-token argument, and fails to match at all against
    nested parens (e.g. alignas(sizeof(x))) or a line break, silently
    skipping the disguise.
    
    There is currently no code affected by this, but there are some
    pending patches that would be.
    
    Co-authored-by: Peter Eisentraut <peter@eisentraut.org>
    Co-authored-by: Andrew Dunstan <andrew@dunslane.net>
    Discussion: https://postgr.es/m/94a128da-bf3e-46bd-9e2d-609573c484da@eisentraut.org


src/tools/pgindent/pgindent | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent index 004b8fcab00..eea6c0ad734 100755 --- a/src/tools/pgindent/pgindent +++ b/src/tools/pgindent/pgindent @@ -235,6 +235,10 @@ sub write_source return; } +# Text of each alignas(...) call, stashed by pre_indent() and restored +# by post_indent(). +my @alignas_stash; + sub pre_indent { my $source = shift; @@ -263,6 +267,19 @@ 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 = (); + $source =~ s! + \b alignas \s* + ( \( (?: [^()]++ | (?1) )*+ \) ) + ! + push(@alignas_stash, "alignas" . $1); + "alignas_" . $#alignas_stash . "_"; + !gex; + return $source; } @@ -270,6 +287,9 @@ sub post_indent { my $source = shift; + # Restore alignas(...) + $source =~ s!\balignas_(\d+)_!$alignas_stash[$1]!g; + # Restore CATALOG lines $source =~ s!^/\*(CATALOG\(.*)\*/$!$1!gm;