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
+34-10Lines changed: 34 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -5153,16 +5153,40 @@ class TestStl : public TestFixture {
5153
5153
ASSERT_EQUALS("[test.cpp:3]: (performance) Searching before insertion is not necessary.\n", errout.str());
5154
5154
}
5155
5155
5156
-
check("void foo() {\n"
5157
-
" std::map<int, int> x;\n"
5158
-
" int data = 0;\n"
5159
-
" for(int i=0; i<10; ++i) {\n"
5160
-
" data += 123;\n"
5161
-
" if(x.find(5) == x.end())\n"
5162
-
" x[5] = data;\n"
5163
-
" }\n"
5164
-
"}");
5165
-
ASSERT_EQUALS("[test.cpp:7]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'.\n", errout.str());
5156
+
{ // #10558
5157
+
check("void foo() {\n"
5158
+
" std::map<int, int> x;\n"
5159
+
" int data = 0;\n"
5160
+
" for(int i=0; i<10; ++i) {\n"
5161
+
" data += 123;\n"
5162
+
" if(x.find(5) == x.end())\n"
5163
+
" x[5] = data;\n"
5164
+
" }\n"
5165
+
"}", false, Standards::CPP03);
5166
+
ASSERT_EQUALS("", errout.str());
5167
+
5168
+
check("void foo() {\n"
5169
+
" std::map<int, int> x;\n"
5170
+
" int data = 0;\n"
5171
+
" for(int i=0; i<10; ++i) {\n"
5172
+
" data += 123;\n"
5173
+
" if(x.find(5) == x.end())\n"
5174
+
" x[5] = data;\n"
5175
+
" }\n"
5176
+
"}", false, Standards::CPP11);
5177
+
ASSERT_EQUALS("[test.cpp:7]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.emplace(5, data);'.\n", errout.str());
5178
+
5179
+
check("void foo() {\n"
5180
+
" std::map<int, int> x;\n"
5181
+
" int data = 0;\n"
5182
+
" for(int i=0; i<10; ++i) {\n"
5183
+
" data += 123;\n"
5184
+
" if(x.find(5) == x.end())\n"
5185
+
" x[5] = data;\n"
5186
+
" }\n"
5187
+
"}");
5188
+
ASSERT_EQUALS("[test.cpp:7]: (performance) Searching before insertion is not necessary. Instead of 'x[5]=data' consider using 'x.try_emplace(5, data);'.\n", errout.str());
0 commit comments