You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/testother.cpp
+40-1Lines changed: 40 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2702,7 +2702,9 @@ class TestOther : public TestFixture {
2702
2702
check("void f(std::string str) {\n"
2703
2703
" std::string s2 = str;\n"
2704
2704
"}");
2705
-
ASSERT_EQUALS("[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n", errout_str());
2705
+
ASSERT_EQUALS("[test.cpp:2:17]: (performance, inconclusive) Use const reference for 's2' to avoid unnecessary data copying. [redundantCopyLocalConst]\n"
2706
+
"[test.cpp:1:20]: (performance) Function parameter 'str' should be passed by const reference. [passedByValue]\n",
2707
+
errout_str());
2706
2708
2707
2709
check("void f(std::string str) {\n"
2708
2710
" std::string& s2 = str;\n"
@@ -9905,6 +9907,43 @@ class TestOther : public TestFixture {
9905
9907
" if (s.empty()) {}\n"
9906
9908
"}\n");
9907
9909
ASSERT_EQUALS("[test.cpp:6:16]: (performance, inconclusive) Use const reference for 's' to avoid unnecessary data copying. [redundantCopyLocalConst]\n", errout_str());
9910
+
9911
+
check("void f1(const std::string& s) {\n"
9912
+
" std::string s1 = s;\n"
9913
+
" (void)s1;\n"
9914
+
"}\n"
9915
+
"void f2() {\n"
9916
+
" const std::string s;\n"
9917
+
" std::string s1 = s;\n"
9918
+
" (void)s1;\n"
9919
+
"}\n");
9920
+
ASSERT_EQUALS("[test.cpp:2:17]: (performance, inconclusive) Use const reference for 's1' to avoid unnecessary data copying. [redundantCopyLocalConst]\n"
9921
+
"[test.cpp:7:17]: (performance, inconclusive) Use const reference for 's1' to avoid unnecessary data copying. [redundantCopyLocalConst]\n",
9922
+
errout_str());
9923
+
9924
+
check("struct S {\n"
9925
+
" std::string m;\n"
9926
+
" int f(const std::string& s);\n"
9927
+
"};\n"
9928
+
"int S::f(const std::string& s) {\n"
9929
+
" std::string c = s;\n"
9930
+
" m.clear();\n"
9931
+
" return c.size();\n"
9932
+
"}\n");
9933
+
ASSERT_EQUALS("", errout_str());
9934
+
9935
+
check("struct S {\n"
9936
+
" std::string m;\n"
9937
+
" int f(std::string s);\n"
9938
+
"};\n"
9939
+
"int S::f(std::string s) {\n"
9940
+
" s += m;\n"
9941
+
" std::string c = s;\n"
9942
+
" m.clear();\n"
9943
+
" return c.size();\n"
9944
+
"}\n");
9945
+
ASSERT_EQUALS("[test.cpp:7:17]: (performance, inconclusive) Use const reference for 'c' to avoid unnecessary data copying. [redundantCopyLocalConst]\n",
0 commit comments