From b3b581502dbf2804bc16fc99089d53811f5ef7ee Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 20 Jun 2017 15:45:41 -0400 Subject: [PATCH] Adjust in_decl logic to avoid messing up enum declarations. 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 | 2 +- tests/declarations.0.stdout | 2 +- tests/enum.0 | 6 ++++++ tests/enum.0.stdout | 5 +++++ 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/enum.0 create mode 100644 tests/enum.0.stdout diff --git a/indent.c b/indent.c index e6560af..9faf57a 100644 --- 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; diff --git a/tests/declarations.0.stdout b/tests/declarations.0.stdout index a164ec2..e97e447 100644 --- a/tests/declarations.0.stdout +++ b/tests/declarations.0.stdout @@ -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 index 0000000..15057dc --- /dev/null +++ b/tests/enum.0 @@ -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 index 0000000..fd4653b --- /dev/null +++ b/tests/enum.0.stdout @@ -0,0 +1,5 @@ +typedef enum { + PREWARM_PREFETCH, /* comment */ + PREWARM_READ, /* more comment */ + PREWARM_BUFFER /* more comment */ +} PrewarmType; -- 2.39.5