From 84f0a180536ad91a55e1079b29015b89cf6fdbb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 8 Jun 2018 10:19:02 +0200 Subject: [PATCH] passedByReference: avoid false positives for std::pair --- lib/checkother.cpp | 2 +- test/testother.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 27822c01a..f8aadc015 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|function")) { + } 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|pair")) { ; } 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 59b129f49..a1a6ab5be 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1384,6 +1384,14 @@ private: check("void f(const std::function ptr) {}"); ASSERT_EQUALS("", errout.str()); + { + check("void f(const std::pair x) {}"); + ASSERT_EQUALS("", errout.str()); + + check("void f(const std::pair x) {}"); + TODO_ASSERT_EQUALS("error", "", errout.str()); + } + check("void f(const std::string::size_type x) {}"); ASSERT_EQUALS("", errout.str());