Skip to content

Commit

Permalink
Merge pull request #47 from xuchenhan-tri/if-constexpr
Browse files Browse the repository at this point in the history
Fix false positive cpplint
  • Loading branch information
jwnimmer-tri authored Jul 13, 2021
2 parents ddcc3fc + 7c29621 commit 5e805eb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cpplint/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3884,11 +3884,11 @@ def CheckBraces(filename, clean_lines, linenum, error):
# its line, and the line after that should have an indent level equal to or
# lower than the if. We also check for ambiguous if/else nesting without
# braces.
if_else_match = Search(r'\b(if\s*\(|else\b)', line)
if_else_match = Search(r'\b(if\s*(|constexpr)\s*\(|else\b)', line)
if if_else_match and not Match(r'\s*#', line):
if_indent = GetIndentLevel(line)
endline, endlinenum, endpos = line, linenum, if_else_match.end()
if_match = Search(r'\bif\s*\(', line)
if_match = Search(r'\bif\s*(|constexpr)\s*\(', line)
if if_match:
# This could be a multiline if condition, so find the end first.
pos = if_match.end() - 1
Expand Down
15 changes: 15 additions & 0 deletions cpplint/cpplint_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3708,6 +3708,21 @@ def testConditionals(self):
goto fail;""",
'If/else bodies with multiple statements require braces'
' [readability/braces] [4]')
self.TestMultiLineLint(
"""
if constexpr (foo)
goto fail;
goto fail;""",
'If/else bodies with multiple statements require braces'
' [readability/braces] [4]')
self.TestMultiLineLint(
"""
if constexpr (foo) {
bar;
} else if constexpr (baz) {
qux;
}""",
'')
self.TestMultiLineLint(
"""
if (foo)
Expand Down

0 comments on commit 5e805eb

Please sign in to comment.