From 44c78d1770b41caf788adb4cd3dbb8fc42bec715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 8 Jun 2018 08:40:14 +0200 Subject: [PATCH] passedByReference: avoid false positives for std::function --- lib/checkother.cpp | 2 +- test/testother.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 0ffa71838..27822c01a 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1427,7 +1427,7 @@ void CheckOther::checkPassByReference() const Token* const tok = var->typeStartToken(); if (var->isStlStringType()) { ; - } else if (var->isStlType() && Token::Match(tok, "std :: %type% <") && !Token::simpleMatch(tok->linkAt(3), "> ::") && !Token::Match(tok->tokAt(2), "initializer_list|weak_ptr|auto_ptr|unique_ptr|shared_ptr")) { + } else if (var->isStlType() && Token::Match(tok, "std :: %type% <") && !Token::simpleMatch(tok->linkAt(3), "> ::") && !Token::Match(tok->tokAt(2), "initializer_list|weak_ptr|auto_ptr|unique_ptr|shared_ptr|function")) { ; } else if (var->type() && !var->type()->isEnumType()) { // Check if type is a struct or class. // Ensure that it is a large object. diff --git a/test/testother.cpp b/test/testother.cpp index 8cbecb852..59b129f49 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1381,6 +1381,9 @@ private: check("void f(const std::shared_ptr ptr) {}"); ASSERT_EQUALS("", errout.str()); + check("void f(const std::function ptr) {}"); + ASSERT_EQUALS("", errout.str()); + check("void f(const std::string::size_type x) {}"); ASSERT_EQUALS("", errout.str());