Skip to content

Commit 5e805eb

Browse files
authored
Merge pull request #47 from xuchenhan-tri/if-constexpr
Fix false positive cpplint
2 parents ddcc3fc + 7c29621 commit 5e805eb

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

cpplint/cpplint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3884,11 +3884,11 @@ def CheckBraces(filename, clean_lines, linenum, error):
38843884
# its line, and the line after that should have an indent level equal to or
38853885
# lower than the if. We also check for ambiguous if/else nesting without
38863886
# braces.
3887-
if_else_match = Search(r'\b(if\s*\(|else\b)', line)
3887+
if_else_match = Search(r'\b(if\s*(|constexpr)\s*\(|else\b)', line)
38883888
if if_else_match and not Match(r'\s*#', line):
38893889
if_indent = GetIndentLevel(line)
38903890
endline, endlinenum, endpos = line, linenum, if_else_match.end()
3891-
if_match = Search(r'\bif\s*\(', line)
3891+
if_match = Search(r'\bif\s*(|constexpr)\s*\(', line)
38923892
if if_match:
38933893
# This could be a multiline if condition, so find the end first.
38943894
pos = if_match.end() - 1

cpplint/cpplint_unittest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3708,6 +3708,21 @@ def testConditionals(self):
37083708
goto fail;""",
37093709
'If/else bodies with multiple statements require braces'
37103710
' [readability/braces] [4]')
3711+
self.TestMultiLineLint(
3712+
"""
3713+
if constexpr (foo)
3714+
goto fail;
3715+
goto fail;""",
3716+
'If/else bodies with multiple statements require braces'
3717+
' [readability/braces] [4]')
3718+
self.TestMultiLineLint(
3719+
"""
3720+
if constexpr (foo) {
3721+
bar;
3722+
} else if constexpr (baz) {
3723+
qux;
3724+
}""",
3725+
'')
37113726
self.TestMultiLineLint(
37123727
"""
37133728
if (foo)

0 commit comments

Comments
 (0)