From ef450545989522c22f8ea64787f4ff4134c54f22 Mon Sep 17 00:00:00 2001 From: Geoffrey Viola Date: Sat, 31 Dec 2022 11:21:14 -0500 Subject: [PATCH] avoid false positives on transform issue27 --- cpplint.py | 2 +- cpplint_unittest.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cpplint.py b/cpplint.py index 42673f3..125a735 100755 --- a/cpplint.py +++ b/cpplint.py @@ -5962,7 +5962,7 @@ def ExpectingFunctionArgs(clean_lines, linenum): # Match max(..., ...), max(..., ...), but not foo->max, foo.max or # 'type::max()'. _re_pattern_headers_maybe_templates.append( - (re.compile(r'[^>.]\b' + _template + r'(<.*?>)?\([^\)]'), + (re.compile(r'std\b\::' + _template + r'(<.*?>)?\([^\)]'), _template, _header)) # Match set, but not foo->set, foo.set diff --git a/cpplint_unittest.py b/cpplint_unittest.py index e0ad860..c61b7f7 100755 --- a/cpplint_unittest.py +++ b/cpplint_unittest.py @@ -1030,7 +1030,7 @@ def testIncludeWhatYouUse(self): ' [build/include_what_you_use] [4]') self.TestIncludeWhatYouUse( """#include "base/foobar.h" - bool foobar = min(0,1); + bool foobar = std::min(0,1); """, 'Add #include for min [build/include_what_you_use] [4]') self.TestIncludeWhatYouUse( @@ -1044,18 +1044,23 @@ def testIncludeWhatYouUse(self): '') # Avoid false positives on strings in other namespaces. self.TestIncludeWhatYouUse( """#include "base/foobar.h" - bool foobar = swap(0,1); + bool foobar = std::swap(0,1); """, 'Add #include for swap [build/include_what_you_use] [4]') self.TestIncludeWhatYouUse( """#include "base/foobar.h" - bool foobar = transform(a.begin(), a.end(), b.start(), Foo); + bool foobar = std::transform(a.begin(), a.end(), b.start(), Foo); """, 'Add #include for transform ' '[build/include_what_you_use] [4]') self.TestIncludeWhatYouUse( """#include "base/foobar.h" - bool foobar = min_element(a.begin(), a.end()); + boost::range::transform(input, std::back_inserter(output), square); + """, + '') # Avoid false positives on transform in other namespaces. + self.TestIncludeWhatYouUse( + """#include "base/foobar.h" + bool foobar = std::min_element(a.begin(), a.end()); """, 'Add #include for min_element ' '[build/include_what_you_use] [4]')