File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed
Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -2082,7 +2082,7 @@ void CheckStl::string_c_str()
20822082 const Token* strm = tok;
20832083 while (Token::simpleMatch (strm, " <<" ))
20842084 strm = strm->astOperand1 ();
2085- if (strm && strm->variable () && strm->variable ()->isStlType ())
2085+ if (strm && (( strm->variable () && strm->variable ()->isStlType ()) || Token::Match (strm-> tokAt (- 1 ), " std :: cout|cerr " ) ))
20862086 string_c_strStream (tok);
20872087 }
20882088 }
Original file line number Diff line number Diff line change @@ -4568,6 +4568,14 @@ class TestStl : public TestFixture {
45684568 " [test.cpp:14:10]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\n " ,
45694569 errout_str ());
45704570
4571+ check (" void f(const std::string& s) {\n "
4572+ " std::cout << s.c_str();\n "
4573+ " std::cerr << s.c_str();\n "
4574+ " }\n " );
4575+ ASSERT_EQUALS (" [test.cpp:2:15]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\n "
4576+ " [test.cpp:3:15]: (performance) Passing the result of c_str() to a stream is slow and redundant. [stlcstrStream]\n " ,
4577+ errout_str ());
4578+
45714579 check (" struct S { std::string str; };\n "
45724580 " struct T { S s; };\n "
45734581 " struct U { T t[1]; };\n "
You can’t perform that action at this time.
0 commit comments