You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
False positive [whitespace/indent] "Closing brace should be aligned with beginning of struct X" for multi-line signatures with multiple struct parameters #486
[whitespace/indent] false positive: Closing brace should be aligned with beginning of struct X is reported for the closing brace of a function definition whenever its multi-line parameter list contains two or more parameters of struct type on their own lines. cpplint mistakes the parameter declarations for struct type definitions.
$ cpplint --filter=-legal/copyright test.ctest.c:15: Closing brace should be aligned with beginning of struct context [whitespace/indent] [3]
Reproduced with cpplint 1.5.5 (Ubuntu 22.04 package) and with current master (1.7.0, cpplint.py as of 2025-12).
Expected behavior
No diagnostic — the closing brace at column 0 correctly terminates the function definition.
Root cause analysis
I traced this through NestingState.Update():
self.stack starts empty at file scope; blocks are pushed only when { is seen.
The parenthesis guard that is supposed to protect parameter lists —
if (class_decl_matchand
(notself.stackorself.stack[-1].open_parentheses==0)):
— never engages here, because open_parentheses is only counted when self.stack is non-empty, and at file scope (before the function body's {) the stack is empty. So every parameter-list line starting with struct X (after optional whitespace) is pushed as a phantom _ClassInfo.
There is a corrective mechanism further down — when a ; or ) token is encountered and the innermost block has not yet seen its opening brace, the phantom is popped as "function arguments with extra class/struct keywords". But it pops only one phantom per ) token, while a parameter list produces one phantom per struct-typed parameter line and has only a single closing ).
With two or more struct parameters, one phantom survives. The function body's { is then attributed to it (seen_open_brace = True), so the phantom is treated as a real struct whose body spans the entire function body, and when the function's closing } at indent 0 is reached, CheckEnd reports the indent mismatch against the phantom's class_indent of 4.
Note this also affects real-world C code formatted with AlignAfterOpenBracket: AlwaysBreak + BinPackParameters: false (one parameter per line), which makes struct-leading parameter lines unavoidable. A single struct parameter escapes because the lone ) pops the only phantom.
Prior art
PR #189 ("Fix issue when function arguments with multiply class or struct keywords", Feb 2022) identified and attempted to fix this exact bug, but was closed unmerged while waiting for a unit test. The analysis above may help whoever picks it up — happy to test any proposed fix against my codebase.
Workaround
} // NOLINT(whitespace/indent) on the affected function's closing brace.
Activity