Adjust in_decl logic to avoid messing up enum declarations.
authorTom Lane <[email protected]>
Tue, 20 Jun 2017 19:45:41 +0000 (15:45 -0400)
committerTom Lane <[email protected]>
Tue, 20 Jun 2017 19:45:41 +0000 (15:45 -0400)
This is a workaround for an acknowledged upstream bug; it basically
reverts this logic to the way it was in NetBSD indent.  While there
may eventually be a different upstream fix, this will do for our
purposes.  Add a regression test case that illustrates the problem,
and tweak declarations.0.stdout for slightly different formatting
produced for a function pointer typedef.

indent.c
tests/declarations.0.stdout
tests/enum.0 [new file with mode: 0644]
tests/enum.0.stdout [new file with mode: 0644]

index e6560af2a63da1c228a10ffdc20cbaac628baf2d..9faf57a97057cb3d8011bb24e617630750f6a524 100644 (file)
--- a/indent.c
+++ b/indent.c
@@ -931,7 +931,7 @@ check_type:
            }
            ps.in_or_st = true; /* this might be a structure or initialization
                                 * declaration */
-           ps.in_decl = ps.decl_on_line = ps.last_token != type_def;
+           ps.in_decl = ps.decl_on_line = true;
            if ( /* !ps.in_or_st && */ ps.dec_nest <= 0)
                ps.just_saw_decl = 2;
            prefix_blankline_requested = 0;
index a164ec2753c8dff53f296003a0bd14e6c00be4e6..e97e447c2b7396b32be1c1f7f4903eb90a0e97ce 100644 (file)
@@ -1,7 +1,7 @@
 /* $FreeBSD$ */
 /* See r303570 */
 
-typedef void (*voidptr) (int *);
+typedef void   (*voidptr) (int *);
 
 static const struct {
        double          x;
diff --git a/tests/enum.0 b/tests/enum.0
new file mode 100644 (file)
index 0000000..15057dc
--- /dev/null
@@ -0,0 +1,6 @@
+typedef enum
+{
+PREWARM_PREFETCH,                              /* comment */
+PREWARM_READ,                                  /* more comment */
+PREWARM_BUFFER                                 /* more comment */
+} PrewarmType;
diff --git a/tests/enum.0.stdout b/tests/enum.0.stdout
new file mode 100644 (file)
index 0000000..fd4653b
--- /dev/null
@@ -0,0 +1,5 @@
+typedef enum {
+       PREWARM_PREFETCH,       /* comment */
+       PREWARM_READ,           /* more comment */
+       PREWARM_BUFFER          /* more comment */
+}              PrewarmType;