From ac54b8de82ddde0ad9749d161d65a23bdf4c4246 Mon Sep 17 00:00:00 2001 From: Alex Light Date: Thu, 20 Jan 2022 13:02:48 +0000 Subject: [PATCH] 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 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/+/3389431 Reviewed-by: Anthony Polito Commit-Queue: Victor Boivie --- cpplint.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpplint.py b/cpplint.py index 0d4a799d5..2e95327a2 100755 --- a/cpplint.py +++ b/cpplint.py @@ -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 [')