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
{{ message }}
Repository navigation
Commit 26e0795
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: test/teststl.cpp
+30-11Lines changed: 30 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -7487,45 +7487,58 @@ class TestStl : public TestFixture {
7487
7487
" if (m.count(1) != 0)\n"
7488
7488
" m[1] = true;\n"
7489
7489
"}\n");
7490
-
ASSERT_EQUALS("[test.cpp:4:16]: (performance) Searching before modification is not necessary. Instead of 'm[1]=true' consider assigning the value through the iterator returned by 'm.find(1)'. [stlFindInsert]\n", errout_str());
7490
+
ASSERT_EQUALS(
7491
+
"[test.cpp:4:16]: (performance) Searching before modification is not necessary. Instead of 'm[1]=true' consider assigning the value through the iterator returned by 'm.find(1)'. [stlFindInsert]\n",
7492
+
errout_str());
7491
7493
7492
7494
check("void f(std::map<unsigned, unsigned>& m, unsigned x) {\n"
7493
7495
" if (m.find(x) != m.end())\n"
7494
7496
" m[x] = 1;\n"
7495
7497
"}\n");
7496
-
ASSERT_EQUALS("[test.cpp:3:16]: (performance) Searching before modification is not necessary. Instead of 'm[x]=1' consider assigning the value through the iterator returned by 'm.find(x)'. [stlFindInsert]\n", errout_str());
7498
+
ASSERT_EQUALS(
7499
+
"[test.cpp:3:16]: (performance) Searching before modification is not necessary. Instead of 'm[x]=1' consider assigning the value through the iterator returned by 'm.find(x)'. [stlFindInsert]\n",
7500
+
errout_str());
7497
7501
7498
7502
check("void f(std::map<unsigned, unsigned>& m, unsigned x) {\n"
7499
7503
" if (m.count(x) > 0)\n"
7500
7504
" m[x] = 1;\n"
7501
7505
"}\n");
7502
-
ASSERT_EQUALS("[test.cpp:3:16]: (performance) Searching before modification is not necessary. Instead of 'm[x]=1' consider assigning the value through the iterator returned by 'm.find(x)'. [stlFindInsert]\n", errout_str());
7506
+
ASSERT_EQUALS(
7507
+
"[test.cpp:3:16]: (performance) Searching before modification is not necessary. Instead of 'm[x]=1' consider assigning the value through the iterator returned by 'm.find(x)'. [stlFindInsert]\n",
7508
+
errout_str());
7503
7509
7504
7510
check("void f(std::map<unsigned, unsigned>& m, unsigned x) {\n"
7505
7511
" if (m.count(x) == 1)\n"
7506
7512
" m[x] = 1;\n"
7507
7513
"}\n");
7508
-
ASSERT_EQUALS("[test.cpp:3:16]: (performance) Searching before modification is not necessary. Instead of 'm[x]=1' consider assigning the value through the iterator returned by 'm.find(x)'. [stlFindInsert]\n", errout_str());
7514
+
ASSERT_EQUALS(
7515
+
"[test.cpp:3:16]: (performance) Searching before modification is not necessary. Instead of 'm[x]=1' consider assigning the value through the iterator returned by 'm.find(x)'. [stlFindInsert]\n",
7516
+
errout_str());
7509
7517
7510
7518
// The key is not found => try_emplace()
7511
7519
check("void f(std::map<unsigned, unsigned>& m, unsigned x) {\n"
7512
7520
" if (m.count(x) == 0)\n"
7513
7521
" m[x] = 1;\n"
7514
7522
"}\n");
7515
-
ASSERT_EQUALS("[test.cpp:3:16]: (performance) Searching before insertion is not necessary. Instead of 'm[x]=1' consider using 'm.try_emplace(x, 1);'. [stlFindInsert]\n", errout_str());
7523
+
ASSERT_EQUALS(
7524
+
"[test.cpp:3:16]: (performance) Searching before insertion is not necessary. Instead of 'm[x]=1' consider using 'm.try_emplace(x, 1);'. [stlFindInsert]\n",
7525
+
errout_str());
7516
7526
7517
7527
check("void f(std::map<unsigned, unsigned>& m, unsigned x) {\n"
7518
7528
" if (m.count(x) < 1)\n"
7519
7529
" m[x] = 1;\n"
7520
7530
"}\n");
7521
-
ASSERT_EQUALS("[test.cpp:3:16]: (performance) Searching before insertion is not necessary. Instead of 'm[x]=1' consider using 'm.try_emplace(x, 1);'. [stlFindInsert]\n", errout_str());
7531
+
ASSERT_EQUALS(
7532
+
"[test.cpp:3:16]: (performance) Searching before insertion is not necessary. Instead of 'm[x]=1' consider using 'm.try_emplace(x, 1);'. [stlFindInsert]\n",
7533
+
errout_str());
7522
7534
7523
7535
// Unknown condition => no suggestion
7524
7536
check("void f(std::map<unsigned, unsigned>& m, unsigned x, unsigned y) {\n"
7525
7537
" if (m.count(x) == y)\n"
7526
7538
" m[x] = 1;\n"
7527
7539
"}\n");
7528
-
ASSERT_EQUALS("[test.cpp:3:16]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n", errout_str());
7540
+
ASSERT_EQUALS("[test.cpp:3:16]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n",
7541
+
errout_str());
7529
7542
7530
7543
// Both branches set the value => no suggestion
7531
7544
check("void f(std::map<unsigned, unsigned>& m, unsigned x) {\n"
@@ -7534,15 +7547,17 @@ class TestStl : public TestFixture {
7534
7547
" else\n"
7535
7548
" m[x] = 1;\n"
7536
7549
"}\n");
7537
-
ASSERT_EQUALS("[test.cpp:3:16]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n", errout_str());
7550
+
ASSERT_EQUALS("[test.cpp:3:16]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n",
7551
+
errout_str());
7538
7552
7539
7553
check("void f(std::map<unsigned, unsigned>& m, unsigned x) {\n"
7540
7554
" if (m.find(x) != m.end())\n"
7541
7555
" m[x] = 1;\n"
7542
7556
" else\n"
7543
7557
" m.emplace(x, 1);\n"
7544
7558
"}\n");
7545
-
ASSERT_EQUALS("[test.cpp:3:16]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n", errout_str());
7559
+
ASSERT_EQUALS("[test.cpp:3:16]: (performance) Searching before insertion is not necessary. [stlFindInsert]\n",
7560
+
errout_str());
7546
7561
7547
7562
// The suggestion for a found key does not depend on the C++ standard
7548
7563
{
@@ -7553,10 +7568,14 @@ class TestStl : public TestFixture {
7553
7568
"}\n";
7554
7569
s.standards.cpp = Standards::CPP03;
7555
7570
check(code, s);
7556
-
ASSERT_EQUALS("[test.cpp:3:16]: (performance) Searching before modification is not necessary. Instead of 'm[x]=1' consider assigning the value through the iterator returned by 'm.find(x)'. [stlFindInsert]\n", errout_str());
7571
+
ASSERT_EQUALS(
7572
+
"[test.cpp:3:16]: (performance) Searching before modification is not necessary. Instead of 'm[x]=1' consider assigning the value through the iterator returned by 'm.find(x)'. [stlFindInsert]\n",
7573
+
errout_str());
7557
7574
s.standards.cpp = Standards::CPP11;
7558
7575
check(code, s);
7559
-
ASSERT_EQUALS("[test.cpp:3:16]: (performance) Searching before modification is not necessary. Instead of 'm[x]=1' consider assigning the value through the iterator returned by 'm.find(x)'. [stlFindInsert]\n", errout_str());
7576
+
ASSERT_EQUALS(
7577
+
"[test.cpp:3:16]: (performance) Searching before modification is not necessary. Instead of 'm[x]=1' consider assigning the value through the iterator returned by 'm.find(x)'. [stlFindInsert]\n",
0 commit comments