Merge pull request #928 from APokorny/bugfix/no-pass-by-value-warning-for-unique-ptr

Do not warn when unique pointers are passed by value
This commit is contained in:
Daniel Marjamäki 2017-07-25 22:51:27 +02:00 committed by GitHub
commit 9787f2dadb
2 changed files with 4 additions and 1 deletions

View File

@ -1379,7 +1379,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")) {
} 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")) {
;
} else if (var->type() && !var->type()->isEnumType()) { // Check if type is a struct or class.
// Ensure that it is a large object.

View File

@ -1371,6 +1371,9 @@ private:
check("void f(const std::string str) {}");
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'str' should be passed by reference.\n", errout.str());
check("void f(std::unique_ptr<std::string> ptr) {}");
ASSERT_EQUALS("", errout.str());
check("void f(const std::string::size_type x) {}");
ASSERT_EQUALS("", errout.str());