]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
pgindent: Fix spacing after != when member name matches typedef.
authorNathan Bossart <nathan@postgresql.org>
Wed, 13 May 2026 14:10:50 +0000 (09:10 -0500)
committerNathan Bossart <nathan@postgresql.org>
Wed, 13 May 2026 14:10:50 +0000 (09:10 -0500)
When a struct member name matches a registered typedef, pgindent
removes the space after "!=" (and some other operators), like so:

    entry->dsh.dsa_handle !=DSA_HANDLE_INVALID

The problem is that the related code in lexi.c sets last_u_d to
true before jumping to found_typename, causing the next operator to
be classified as unary and suppressing the following space.  This
is correct for type names, but not for struct members.  For
example, "Datum *x" needs "*" to be unary to suppress the space
before "x".  To fix, only set last_u_d before jumping to
found_typename if the typedef name doesn't appear after "." or
"->".

Note that this does not bump INDENT_VERSION.  We'll do that just
once after some other changes to pg_bsd_indent are committed.

Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/aS9hkwnkWf3dZIA_%40nathan

src/tools/pg_bsd_indent/lexi.c

index 943bf7ce6b0ab0d8936695d094509865a6fd0695..e846188d6f41697bf24c50450483af54e34553cd 100644 (file)
@@ -363,7 +363,8 @@ lexi(struct parser_state *state)
                  bsearch(s_token, typenames, typename_top + 1,
                    sizeof(typenames[0]), strcmp_type))) {
                state->keyword = 4;     /* a type name */
-               state->last_u_d = true;
+               if (state->last_token != period && state->last_token != unary_op)
+                   state->last_u_d = true;
                goto found_typename;
            }
        } else {                        /* we have a keyword */