Commit ac54b8de authored by Alex Light's avatar Alex Light Committed by LUCI CQ

Add support for c++17 tuple destructuring (#487)

C++17 adds support for tuple destructuring. This allow one to write
code such as:

```
std::pair<int, int> span = getSpan();
auto [start, end] = span;

// Use start as span.first and end as span.second
```

This makes cpplint recognize and allow a space before the '[' in this
situation.

This is a purposeful divergence from the internal version where the
entire whitespace/braces category was removed. It was decided to leave
the checks in since this is sometimes used without other formatting
tools.

Test: manual

(cherry picked from commit 26470f9ccb354ff2f6d098f831271a1833701b28
 from https://github.com/google/styleguide)

Bug: 1287491
Change-Id: Ib61a75853e19316b1bacf8dc56528f94c17e30a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3389431Reviewed-by: 's avatarAnthony Polito <apolito@google.com>
Commit-Queue: Victor Boivie <boivie@google.com>
parent a657331e
......@@ -3162,10 +3162,10 @@ def CheckSpacing(filename, clean_lines, linenum, nesting_state, error):
line = clean_lines.elided[linenum]
# You shouldn't have spaces before your brackets, except maybe after
# 'delete []' or 'return []() {};', or in the case of c++ attributes
# like 'class [[clang::lto_visibility_public]] MyClass'.
# 'delete []', 'return []() {};', 'auto [abc, ...] = ...;' or in the case of
# c++ attributes like 'class [[clang::lto_visibility_public]] MyClass'.
if (Search(r'\w\s+\[', line)
and not Search(r'(?:delete|return)\s+\[', line)
and not Search(r'(?:auto&?|delete|return)\s+\[', line)
and not Search(r'\s+\[\[', line)):
error(filename, linenum, 'whitespace/braces', 5,
'Extra space before [')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment