关于GNU indent(2.2.12)在void函数体后不添加空行是否为Bug的技术问询
Yes, this absolutely looks like a bug in GNU indent 2.2.12, specifically tied to how it processes void functions without an explicit return statement when using the Kernighan & Ritchie (-kr) formatting style.
Let's break down what's happening here:
The problematic case
When you run this command:$ echo 'void B(int *b) { *b += 2; } void C(int *c) { *c += 3; }' | indent -krYou get this unformatted output (no blank line between functions):
void B(int *b) { *b += 2; } void C(int *c) { *c += 3; }
This is clearly wrong—
indent -kris supposed to insert a blank line between top-level functions, per K&R style conventions.The working case
Add an explicitreturn;to the void function, and suddenly it works as expected:$ echo 'void B(int *b) { *b += 2; return; } void C(int *c) { *c += 3; }' | indent -krOutput:
void B(int *b) { *b += 2; return; }
void C(int *c) { *c += 3; }
What's causing this?
It seems like the indent parser in 2.2.12 is relying on the presence of a return statement (even a void one) to correctly detect the end of a function. Without that explicit return, it fails to recognize that the closing } of B() marks the end of the function body, so it doesn't insert the required blank line before C().
This is inconsistent behavior—void functions don't require an explicit return in C, and indent should handle both cases uniformly for the -kr style.
Fix options
If you can, upgrading to a newer version of GNU indent (2.2.13 or later) resolves this issue. The bug was addressed in subsequent releases to properly parse function boundaries regardless of whether a void function has an explicit return.
内容的提问来源于stack exchange,提问作者uncleremus

