GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: handle multiline function templates in namespaces · cpplint/cpplint@cd67aa7

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • CHANGELOG.rst
  • cpplint.py
  • cpplint_unittest.py
  • samples/boost-sample
    • simple.def
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎CHANGELOG.rst‎

Copy file name to clipboardExpand all lines: CHANGELOG.rst
+2Lines changed: 2 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Changelog
55
TBA
66
===
77

8+
* Function template declarations with multiline template parameters no longer trigger ``whitespace/indent_namespace`` on their continuation lines.
9+
810
2.0.2 (2025-04-08)
911
===========
1012

Collapse file

‎cpplint.py‎

Copy file name to clipboardExpand all lines: cpplint.py
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4161,6 +4161,9 @@ def CheckForNamespaceIndentation(filename, nesting_state, clean_lines, line, err
41614161
or (isinstance(nesting_state.previous_stack_top, _NamespaceInfo))
41624162
)
41634163

4164+
if IsMultilineFunctionTemplateDeclaration(clean_lines, line):
4165+
return
4166+
41644167
if ShouldCheckNamespaceIndentation(
41654168
nesting_state, is_namespace_indent_item, clean_lines.elided, line
41664169
):
@@ -7384,6 +7387,36 @@ def IsBlockInNameSpace(nesting_state: NestingState, is_forward_declaration: bool
73847387
return False
73857388

73867389

7390+
def IsMultilineFunctionTemplateDeclaration(clean_lines, linenum):
7391+
"""Checks whether a line continues a function template declaration."""
7392+
for start_line in range(linenum - 1, -1, -1):
7393+
line = clean_lines.elided[start_line]
7394+
if re.search(r"[;{}]", line):
7395+
return False
7396+
7397+
if template := re.search(r"\btemplate\s*<", line):
7398+
_, end_line, end_pos = CloseExpression(clean_lines, start_line, template.end() - 1)
7399+
if not start_line < linenum <= end_line or end_pos < 0:
7400+
return False
7401+
7402+
declaration = clean_lines.elided[end_line][end_pos:]
7403+
for next_line in range(end_line + 1, clean_lines.NumLines()):
7404+
declaration += " " + clean_lines.elided[next_line].strip()
7405+
if re.search(r"[;{}]", declaration):
7406+
break
7407+
7408+
declaration = declaration.strip()
7409+
if not declaration or "{" in declaration.split(";", 1)[0]:
7410+
return False
7411+
if re.match(r"(?:class|enum|struct|using)\b", declaration):
7412+
return False
7413+
7414+
function = re.search(r"\b(?:operator\s*\S+|~?[A-Za-z_]\w*)\s*\(", declaration)
7415+
return function is not None and "=" not in declaration[: function.start()]
7416+
7417+
return False
7418+
7419+
73877420
def ShouldCheckNamespaceIndentation(
73887421
nesting_state: NestingState, is_namespace_indent_item, raw_lines_no_comments, linenum
73897422
):
Collapse file

‎cpplint_unittest.py‎

Copy file name to clipboardExpand all lines: cpplint_unittest.py
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,38 @@ def testNamespaceIndentationIndentedParameter(self):
323323
results = self.GetNamespaceResults(lines)
324324
assert results == ""
325325

326+
def testNamespaceIndentationMultilineFunctionTemplateDeclaration(self):
327+
lines = [
328+
"namespace Test {",
329+
"template <typename Type1,",
330+
" typename Type2>",
331+
"void TestFunc(const Type1 &var1, Type2 &var2);",
332+
"} // namespace Test",
333+
]
334+
assert self.GetNamespaceResults(lines) == ""
335+
336+
lines = [
337+
"namespace Test {",
338+
"template <typename T,",
339+
" typename Callback = void (*)(T)>",
340+
"void Register(Callback callback);",
341+
"} // namespace Test",
342+
]
343+
assert self.GetNamespaceResults(lines) == ""
344+
345+
def testNamespaceIndentationIndentedMultilineFunctionTemplateDeclaration(self):
346+
lines = [
347+
"namespace Test {",
348+
" template <typename Type1,",
349+
" typename Type2>",
350+
" void TestFunc(const Type1 &var1, Type2 &var2);",
351+
"} // namespace Test",
352+
]
353+
assert self.GetNamespaceResults(lines) == [
354+
"Do not indent within a namespace. [whitespace/indent_namespace] [4]",
355+
"Do not indent within a namespace. [whitespace/indent_namespace] [4]",
356+
]
357+
326358
def testNamespaceIndentationMemberInitializerList(self):
327359
lines = [
328360
"namespace Opossum {",
Collapse file

‎samples/boost-sample/simple.def‎

Copy file name to clipboardExpand all lines: samples/boost-sample/simple.def
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ include/boost/math/*
22
1
33
3
44
Done processing include/boost/math/octonion.hpp
5-
Total errors found: 2900
5+
Total errors found: 2898
66

77
include/boost/math/octonion.hpp:11: #ifndef header guard has wrong style, please use: SAMPLES_BOOST_SAMPLE_INCLUDE_BOOST_MATH_OCTONION_HPP_ [build/header_guard] [5]
88
include/boost/math/octonion.hpp:4250: #endif line should be "#endif // SAMPLES_BOOST_SAMPLE_INCLUDE_BOOST_MATH_OCTONION_HPP_" [build/header_guard] [5]
@@ -290,8 +290,6 @@ include/boost/math/octonion.hpp:672: { should almost always be at the end of th
290290
include/boost/math/octonion.hpp:673: Do not indent within a namespace. [whitespace/indent_namespace] [4]
291291
include/boost/math/octonion.hpp:673: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]
292292
include/boost/math/octonion.hpp:674: Do not indent within a namespace. [whitespace/indent_namespace] [4]
293-
include/boost/math/octonion.hpp:675: Do not indent within a namespace. [whitespace/indent_namespace] [4]
294-
include/boost/math/octonion.hpp:676: Do not indent within a namespace. [whitespace/indent_namespace] [4]
295293
include/boost/math/octonion.hpp:677: Do not indent within a namespace. [whitespace/indent_namespace] [4]
296294
include/boost/math/octonion.hpp:678: Do not indent within a namespace. [whitespace/indent_namespace] [4]
297295
include/boost/math/octonion.hpp:679: Do not indent within a namespace. [whitespace/indent_namespace] [4]

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.