Repository navigation
fix: don't end an unbraced if body at a semicolon in a nested header - #1
Open
captainurist wants to merge 1 commit into
Open
captainurist wants to merge 1 commit into
captainurist wants to merge 1 commit into
Conversation
The readability/braces check for unbraced if and else bodies takes the first semicolon after the condition as the end of the body. When the body is a for loop with a classic header, or an if with an init-statement, that semicolon sits inside the nested header. The rest of the header then reads as a second statement, and the check reports "If/else bodies with multiple statements require braces" for what is a single statement. The check now steps over the parenthesized header of a nested if, for, while or switch before it looks for the semicolon, repeatedly, so a chain like `if (a) for (...) if (b) x;` works too. Two statements under such a header are still reported. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The readability/braces check for unbraced if and else bodies takes the first semicolon after the condition as the end of the body. With
if (foo)overfor (int i = 0; i < n; ++i), that semicolon is inside the for header, so cpplint reports "If/else bodies with multiple statements require braces" for a single statement. The same happens for an if with an init-statement.The check now steps over the header of a nested if, for, while or switch before looking for the semicolon. Two statements under such a header are still reported. New cases in
testConditionalscover both. On OpenEnroth, lintingsrcandtestgives identical output before and after, and the 13 sites that need braces only because of this false positive lint clean once unbraced.🤖 Generated with Claude Code