Allow passing std::string_view by value (#3817)
This commit is contained in:
parent
cd7532df21
commit
2535bf984b
|
@ -1300,7 +1300,7 @@ void CheckOther::checkPassByReference()
|
||||||
|
|
||||||
bool inconclusive = false;
|
bool inconclusive = false;
|
||||||
|
|
||||||
if (var->valueType() && var->valueType()->type == ValueType::Type::CONTAINER) {} else if (var->type() && !var->type()->isEnumType()) { // Check if type is a struct or class.
|
if (var->valueType() && var->valueType()->type == ValueType::Type::CONTAINER && !var->valueType()->container->view) {} else if (var->type() && !var->type()->isEnumType()) { // Check if type is a struct or class.
|
||||||
// Ensure that it is a large object.
|
// Ensure that it is a large object.
|
||||||
if (!var->type()->classScope)
|
if (!var->type()->classScope)
|
||||||
inconclusive = true;
|
inconclusive = true;
|
||||||
|
|
|
@ -1650,6 +1650,16 @@ private:
|
||||||
check("void f(const std::string &str) {}");
|
check("void f(const std::string &str) {}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// The idiomatic way of passing a std::string_view is by value
|
||||||
|
check("void f(const std::string_view str) {}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f(std::string_view str) {}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f(const std::string_view &str) {}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f(const std::vector<int> v) {}");
|
check("void f(const std::vector<int> v) {}");
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' should be passed by const reference.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'v' should be passed by const reference.\n", errout.str());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue