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/teststl.cpp
+18-1Lines changed: 18 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2093,7 +2093,6 @@ class TestStl : public TestFixture {
2093
2093
" std::string errmsg;\n"
2094
2094
" return errmsg.c_str();\n"
2095
2095
"}");
2096
-
2097
2096
ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout.str());
2098
2097
2099
2098
check("const char *get_msg() {\n"
@@ -2142,6 +2141,15 @@ class TestStl : public TestFixture {
2142
2141
"}");
2143
2142
ASSERT_EQUALS("[test.cpp:6]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout.str());
2144
2143
2144
+
check("class Foo {\n"
2145
+
" std::string GetVal() const;\n"
2146
+
"};\n"
2147
+
"const char *f() {\n"
2148
+
" Foo f;\n"
2149
+
" return f.GetVal().c_str();\n"
2150
+
"}");
2151
+
ASSERT_EQUALS("[test.cpp:6]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.\n", errout.str());
2152
+
2145
2153
check("const char* foo() {\n"
2146
2154
" static std::string text;\n"
2147
2155
" text = \"hello world\n\";\n"
@@ -2162,6 +2170,15 @@ class TestStl : public TestFixture {
2162
2170
"}");
2163
2171
ASSERT_EQUALS("[test.cpp:3]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant.\n", errout.str());
2164
2172
2173
+
check("class Foo {\n"
2174
+
" std::string GetVal() const;\n"
2175
+
"};\n"
2176
+
"std::string f() {\n"
2177
+
" Foo f;\n"
2178
+
" return f.GetVal().c_str();\n"
2179
+
"}");
2180
+
ASSERT_EQUALS("[test.cpp:6]: (performance) Returning the result of c_str() in a function that returns std::string is slow and redundant.\n", errout.str());
0 commit comments