diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index d991e61fd..6f651a2d6 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -1171,7 +1171,7 @@ void CmdLineParser::printHelp() " --report-progress Report progress messages while checking a file.\n" #ifdef HAVE_RULES " --rule= Match regular expression.\n" - " --rule-file= Use given rule file. For more information, see: \n" + " --rule-file= Use given rule file. For more information, see:\n" " http://sourceforge.net/projects/cppcheck/files/Articles/\n" #endif " --std= Set standard.\n" diff --git a/test/test64bit.cpp b/test/test64bit.cpp index e0ba18401..8b66d36d7 100644 --- a/test/test64bit.cpp +++ b/test/test64bit.cpp @@ -248,7 +248,7 @@ private: // #7451: Lambdas check("const int* test(std::vector outputs, const std::string& text) {\n" - " auto it = std::find_if(outputs.begin(), outputs.end(), \n" + " auto it = std::find_if(outputs.begin(), outputs.end(),\n" " [&](int ele) { return \"test\" == text; });\n" " return nullptr;\n" "}"); diff --git a/test/testassert.cpp b/test/testassert.cpp index efe957997..9cef5f3d6 100644 --- a/test/testassert.cpp +++ b/test/testassert.cpp @@ -63,8 +63,7 @@ private: " if (b) { a = 1+2 };\n" " return a;\n" "}\n" - "assert(foo() == 3); \n" - ); + "assert(foo() == 3);"); ASSERT_EQUALS("", errout.str()); check( @@ -72,8 +71,7 @@ private: " int b=a+1;\n" " return b;\n" "}\n" - "assert(foo(1) == 2); \n" - ); + "assert(foo(1) == 2);"); ASSERT_EQUALS("", errout.str()); } @@ -84,8 +82,7 @@ private: " a = 1+2;\n" " return a;\n" "}\n" - "assert(foo() == 3); \n" - ); + "assert(foo() == 3);"); ASSERT_EQUALS("[test.cpp:6]: (warning) Assert statement calls a function which may have desired side effects: 'foo'.\n", errout.str()); // Ticket #4937 "false positive: Assert calls a function which may have desired side effects" @@ -97,7 +94,7 @@ private: "};\n" "void foo() {\n" " assert( !SquarePack::isRank1Or8(push2) );\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct SquarePack {\n" @@ -108,7 +105,7 @@ private: "};\n" "void foo() {\n" " assert( !SquarePack::isRank1Or8(push2) );\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (warning) Assert statement calls a function which may have desired side effects: 'isRank1Or8'.\n", errout.str()); check("struct SquarePack {\n" @@ -119,7 +116,7 @@ private: "};\n" "void foo() {\n" " assert( !SquarePack::isRank1Or8(push2) );\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (warning) Assert statement calls a function which may have desired side effects: 'isRank1Or8'.\n", errout.str()); check("struct SquarePack {\n" @@ -130,7 +127,7 @@ private: "};\n" "void foo() {\n" " assert( !SquarePack::isRank1Or8(push2) );\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -172,60 +169,54 @@ private: " int a; a = 0;\n" " assert(a = 2);\n" " return a;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str()); check("void f(int a) {\n" " assert(a == 2);\n" " return a;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int a, int b) {\n" " assert(a == 2 && (b = 1));\n" " return a;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Assert statement modifies 'b'.\n", errout.str()); check("void f() {\n" " int a; a = 0;\n" " assert(a += 2);\n" " return a;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str()); check("void f() {\n" " int a; a = 0;\n" " assert(a *= 2);\n" " return a;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str()); check("void f() {\n" " int a; a = 0;\n" " assert(a -= 2);\n" " return a;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str()); check("void f() {\n" " int a = 0;\n" " assert(a--);\n" " return a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str()); check("void f() {\n" " int a = 0;\n" " assert(--a);\n" " return a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str()); check("void f() {\n" @@ -234,7 +225,7 @@ private: " auto const expected = someOtherValue;\n" " return tmp == expected;\n" " }));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index eec7ea87d..a67dbb8c0 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -450,7 +450,7 @@ private: " ~FileManager() {\n" " delete &UniqueRealDirs;\n" " }\n" - "};\n"); + "};"); } void testautovar14() { // Ticket #4776 @@ -731,7 +731,7 @@ private: " if (data_size > sizeof (stack)) data = malloc (data_size);\n" " else data = (RGNDATA *)stack;\n" " if ((char *)data != stack) free (data);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #8923 @@ -808,7 +808,7 @@ private: " ptr = &x;\n" " }\n" " int *ptr;\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Non-local variable 'ptr' will use pointer to local variable 'x'.\n", errout.str()); check("struct A {\n" @@ -818,7 +818,7 @@ private: " ptr = 0;\n" " }\n" " int *ptr;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -906,7 +906,7 @@ private: "char *p;\n" "p = &q[1];\n" "return p;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3] -> [test.cpp:6]: (error) Returning pointer to local variable 'q' that will be invalid when returning.\n", errout.str()); } @@ -953,7 +953,7 @@ private: " int s = 0;\n" " int& x = s;\n" " return x;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5]: (error) Reference to local variable returned.\n", errout.str()); check("std::string &foo()\n" @@ -1215,14 +1215,14 @@ private: " std::vector::iterator it = v.begin();\n" " int& value = *it;\n" " return value;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } void returnReference9() { check("int& f(bool b, int& x, int& y) {\n" " return b ? x : y;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1231,14 +1231,14 @@ private: "int& g() {\n" " A a;\n" " return a.f();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Reference to temporary returned.\n", errout.str()); check("class A { int& f() const; };\n" "int& g() {\n" " A a;\n" " return a.f();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1246,19 +1246,19 @@ private: check("class A { static int f(); };\n" "int& g() {\n" " return A::f();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Reference to temporary returned.\n", errout.str()); check("class A { static int& f(); };\n" "int& g() {\n" " return A::f();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("namespace A { int& f(); }\n" "int& g() {\n" " return A::f();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1266,14 +1266,14 @@ private: check("class A { static int& f(); };\n" "auto g() {\n" " return &A::f;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("class A { static int& f(); };\n" "auto g() {\n" " auto x = &A::f;\n" " return x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1282,14 +1282,14 @@ private: "void* vp = &v;\n" "int& foo(size_t i) {\n" " return ((std::vector*)vp)->at(i);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::vector v;\n" "void* vp = &v;\n" "int& foo(size_t i) {\n" " return static_cast*>(vp)->at(i);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1302,7 +1302,7 @@ private: "}\n" "void* &A::f() {\n" " return g()->m;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1315,7 +1315,7 @@ private: "template \n" "const int& f(const T&) {\n" " return f();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("template \n" @@ -1323,19 +1323,19 @@ private: "template \n" "const int& f(const T&) {\n" " return g();\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("error", "", errout.str()); } void returnReference16() { check("int& f(std::tuple& x) {\n" " return std::get<0>(x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int& f(int x) {\n" " return std::get<0>(std::make_tuple(x));\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("error", "", errout.str()); } @@ -1343,7 +1343,7 @@ private: check("auto g() -> int&;\n" "int& f() {\n" " return g();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1352,7 +1352,7 @@ private: "auto f(T& x) -> decltype(x);\n" "int& g(int* x) {\n" " return f(*x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1360,7 +1360,7 @@ private: void returnReference19() { check("struct C : B {\n" " const B &f() const { return (const B &)*this; }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1371,7 +1371,7 @@ private: "};\n" "int& b() {\n" " return a()();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("auto a() {\n" @@ -1382,13 +1382,13 @@ private: "}\n" "const int& c() {\n" " return a()();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::function a();\n" "int& b() {\n" " return a()();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9889 @@ -1414,7 +1414,7 @@ private: "int& hello() {\n" " int x = 0;\n" " return f(x);\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:1] -> [test.cpp:2] -> [test.cpp:6] -> [test.cpp:6]: (error) Reference to local variable returned.\n", errout.str()); @@ -1425,7 +1425,7 @@ private: "int* hello() {\n" " int x = 0;\n" " return &f(x);\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:1] -> [test.cpp:2] -> [test.cpp:6] -> [test.cpp:6] -> [test.cpp:5] -> [test.cpp:6]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n", errout.str()); @@ -1435,7 +1435,7 @@ private: "}\n" "int * g(int x) {\n" " return f(&x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:5] -> [test.cpp:4] -> [test.cpp:5]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n", errout.str()); check("int* f(int * x) {\n" @@ -1444,7 +1444,7 @@ private: "}\n" "int * g(int x) {\n" " return f(&x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int f(int& a) {\n" @@ -1453,7 +1453,7 @@ private: "int& hello() {\n" " int x = 0;\n" " return f(x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout.str()); check("int& f(int a) {\n" @@ -1462,7 +1462,7 @@ private: "int& hello() {\n" " int x = 0;\n" " return f(x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (error) Reference to local variable returned.\n", errout.str()); check("int f(int a) {\n" @@ -1471,14 +1471,14 @@ private: "int& hello() {\n" " int x = 0;\n" " return f(x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Reference to temporary returned.\n", errout.str()); check("template\n" "int& f(int& x, T y) {\n" " x += y;\n" " return x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1486,31 +1486,31 @@ private: check("auto& f() {\n" " std::vector x;\n" " return x[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Reference to local variable returned.\n", errout.str()); check("auto& f() {\n" " std::vector x;\n" " return x.front();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (error) Reference to local variable returned.\n", errout.str()); check("std::vector g();\n" "auto& f() {\n" " return g().front();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (error) Reference to temporary returned.\n", errout.str()); check("auto& f() {\n" " return std::vector{1}.front();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (error) Reference to temporary returned.\n", errout.str()); check("struct A { int foo; };\n" "int& f(std::vector v) {\n" " auto it = v.begin();\n" " return it->foo;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Reference to local variable returned.\n", errout.str()); check("template \n" @@ -1546,7 +1546,7 @@ private: "int& f(std::vector& v) {\n" " auto it = v.begin();\n" " return it->foo;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1673,7 +1673,7 @@ private: ASSERT_EQUALS("", errout.str()); check("int& g(int& i) { return i; }\n" - "int& f() { return g(f()); }\n"); + "int& f() { return g(f()); }"); ASSERT_EQUALS("", errout.str()); } @@ -1683,7 +1683,7 @@ private: "auto f() {\n" " const int& x = h();\n" " return [&] { return x; };\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5] -> [test.cpp:4] -> [test.cpp:5]: (error) Returning lambda that captures local variable 'x' that will be invalid when returning.\n", errout.str()); check("void g(int*);\n" @@ -1691,7 +1691,7 @@ private: "int* f() {\n" " const int& x = h();\n" " return &x;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5] -> [test.cpp:4] -> [test.cpp:5]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n", errout.str()); check("void g(int*);\n" @@ -1699,7 +1699,7 @@ private: "void f() {\n" " int& x = h();\n" " g(&x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5] -> [test.cpp:5]: (error) Using pointer to temporary.\n" "[test.cpp:4] -> [test.cpp:5]: (error) Using reference to dangling temporary.\n", errout.str()); @@ -1708,7 +1708,7 @@ private: "void f() {\n" " const int& x = h();\n" " g(&x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct Data {\n" @@ -1717,7 +1717,7 @@ private: "const char* foo() {\n" " const Data& data = getData();\n" " return data.path.c_str();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1726,7 +1726,7 @@ private: "{\n" " static int &r = k;\n" " return r;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (error) Non-local reference variable 'r' to local variable 'k'\n", errout.str()); @@ -1734,7 +1734,7 @@ private: "{\n" " static int &r = k;\n" " return r;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1831,7 +1831,7 @@ private: "{\n" " struct s *r = f();\n" " *q = &r->p;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1860,30 +1860,30 @@ private: " int a = 1;\n" " auto l = [&](){ return a; };\n" " return l;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout.str()); check("auto f() {\n" " int a = 1;\n" " return [&](){ return a; };\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout.str()); check("auto f(int a) {\n" " return [&](){ return a; };\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:1] -> [test.cpp:2]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout.str()); check("auto f(int a) {\n" " auto p = &a;\n" " return [=](){ return p; };\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout.str()); check("auto g(int& a) {\n" " int p = a;\n" " return [&](){ return p; };\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'p' that will be invalid when returning.\n", errout.str()); check("auto f() {\n" @@ -1891,7 +1891,7 @@ private: " int a = 1;\n" " return [&](){ return a; };\n" " };\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout.str()); check("auto f(int b) {\n" @@ -1899,30 +1899,30 @@ private: " a += b;\n" " return [&](){ return a; };\n" " };\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout.str()); check("auto g(int& a) {\n" " return [&](){ return a; };\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("auto g(int a) {\n" " auto p = a;\n" " return [=](){ return p; };\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("auto g(int& a) {\n" " auto p = a;\n" " return [=](){ return p; };\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("auto g(int& a) {\n" " int& p = a;\n" " return [&](){ return p; };\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("template\n" @@ -1930,7 +1930,7 @@ private: "auto f() {\n" " int x;\n" " return g([&]() { return x; });\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("auto f() {\n" @@ -1991,28 +1991,28 @@ private: check("auto f(const std::vector& x) {\n" " auto it = x.begin();\n" " return it;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("auto f() {\n" " std::vector x;\n" " auto it = x.begin();\n" " return it;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning iterator to local container 'x' that will be invalid when returning.\n", errout.str()); check("auto f() {\n" " std::vector x;\n" " auto p = x.data();\n" " return p;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'x' that will be invalid when returning.\n", errout.str()); check("auto f() {\n" " std::vector x;\n" " auto p = &x[0];\n" " return p;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning pointer to local variable 'x' that will be invalid when returning.\n", errout.str()); @@ -2021,7 +2021,7 @@ private: "int* f(std::vector v) {\n" " auto it = v.begin();\n" " return &it->foo;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n", errout.str()); @@ -2029,14 +2029,14 @@ private: check("auto f(std::vector x) {\n" " auto it = x.begin();\n" " return it;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning iterator to local container 'x' that will be invalid when returning.\n", errout.str()); check("auto f() {\n" " std::vector x;\n" " auto it = x.begin();\n" " return std::next(it);\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'x' that will be invalid when returning.\n", errout.str()); @@ -2045,7 +2045,7 @@ private: " std::vector x;\n" " auto it = x.begin();\n" " return it + 1;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning iterator to local container 'x' that will be invalid when returning.\n", errout.str()); @@ -2054,7 +2054,7 @@ private: " std::vector x;\n" " auto it = x.begin();\n" " return std::next(it + 1);\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'x' that will be invalid when returning.\n", errout.str()); @@ -2064,7 +2064,7 @@ private: " std::vector v;\n" " v.push_back(&i);\n" " return v;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:4] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:5]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", errout.str()); @@ -2076,7 +2076,7 @@ private: " v.push_back(&i);\n" " r.assign(v.begin(), v.end());\n" " return r;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:5] -> [test.cpp:5] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:7]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", errout.str()); @@ -2087,7 +2087,7 @@ private: " int i;\n" " v.push_back(&i);\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS( "[test.cpp:5] -> [test.cpp:5] -> [test.cpp:4] -> [test.cpp:5]: (error) Non-local variable 'v' will use object that points to local variable 'i'.\n", errout.str()); @@ -2099,7 +2099,7 @@ private: " int * p = &i;\n" " v.push_back(p);\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS( "[test.cpp:5] -> [test.cpp:6] -> [test.cpp:4] -> [test.cpp:6]: (error) Non-local variable 'v' will use object that points to local variable 'i'.\n", errout.str()); @@ -2112,7 +2112,7 @@ private: " v.push_back(&x);\n" " m.insert(m.end(), v.begin(), v.end());\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS( "[test.cpp:6] -> [test.cpp:6] -> [test.cpp:6] -> [test.cpp:4] -> [test.cpp:7]: (error) Non-local variable 'm' will use object that points to local variable 'x'.\n", errout.str()); @@ -2122,7 +2122,7 @@ private: " return it;\n" " }\n" " return {};\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:2] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning iterator to local container 'v' that will be invalid when returning.\n", errout.str()); @@ -2130,7 +2130,7 @@ private: check("const char * f() {\n" " std::string ba(\"hello\");\n" " return ba.c_str();\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning pointer to local variable 'ba' that will be invalid when returning.\n", errout.str()); @@ -2154,7 +2154,7 @@ private: check("std::vector g();\n" "auto f() {\n" " return g().begin();\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:3]: (error) Returning iterator that will be invalid when returning.\n", "", @@ -2164,13 +2164,13 @@ private: "auto f() {\n" " auto it = g().begin();\n" " return it;\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("error", "", errout.str()); check("std::vector f();\n" "int& f() {\n" " return *g().begin();\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("error", "", errout.str()); check("struct A {\n" @@ -2179,7 +2179,7 @@ private: " char s[3];\n" " v.push_back(s);\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); check("std::vector f() {\n" @@ -2187,46 +2187,46 @@ private: " std::vector v;\n" " v.push_back(s);\n" " return v;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("auto f() {\n" " static std::vector x;\n" " return x.begin();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::string g() {\n" " std::vector v;\n" " return v.data();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::vector::iterator f(std::vector* v) {\n" " return v->begin();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::vector::iterator f(std::vector* v) {\n" " std::vector* v = new std::vector();\n" " return v->begin();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int f(std::vector v) {\n" " return *v.begin();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int f(std::vector v) {\n" " return v.end() - v.begin();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("auto g() {\n" " std::vector v;\n" " return {v, [v]() { return v.data(); }};\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("template\n" @@ -2234,7 +2234,7 @@ private: "auto f() {\n" " std::vector v;\n" " return g([&]() { return v.data(); });\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::vector g();\n" @@ -2244,7 +2244,7 @@ private: " std::vector v = g();\n" " m.insert(m.end(), v.begin(), v.end());\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); check("void f(bool b) {\n" @@ -2254,7 +2254,7 @@ private: " v.insert(a, a+1);\n" " }\n" " return v.back() == 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("class A {\n" @@ -2265,7 +2265,7 @@ private: " struct B {};\n" " std::map< S, B > m1;\n" " std::map< S, B > m2;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); check("struct A {\n" @@ -2274,33 +2274,33 @@ private: " void f() {\n" " v.push_back(&x);\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); check("size_t f(const std::string& x) {\n" " std::string y = \"x\";\n" " return y.find(x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::string* f();\n" "const char* g() {\n" " std::string* var = f();\n" " return var->c_str();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::string f() {\n" " std::vector data{};\n" " data.push_back('a');\n" " return std::string{ data.data(), data.size() };\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::vector f() {\n" " char a = 0;\n" " return std::vector{&a};\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'a' that will be invalid when returning.\n", errout.str()); check("std::vector* g();\n" @@ -2363,20 +2363,20 @@ private: " std::vector a;\n" " auto it = a.begin();\n" " return [=](){ return it; };\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout.str()); check("auto f(std::vector a) {\n" " auto it = a.begin();\n" " return [=](){ return it; };\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3] -> [test.cpp:1] -> [test.cpp:3]: (error) Returning lambda that captures local variable 'a' that will be invalid when returning.\n", errout.str()); check("struct e {};\n" "e * j() {\n" " e c[20];\n" " return c;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:4] -> [test.cpp:3] -> [test.cpp:4]: (error) Returning pointer to local variable 'c' that will be invalid when returning.\n", errout.str()); @@ -2384,12 +2384,12 @@ private: check("auto f(std::vector& a) {\n" " auto it = a.begin();\n" " return [=](){ return it; };\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int * f(int a[]) {\n" " return a;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" @@ -2397,14 +2397,14 @@ private: " uint32_t f[6];\n" " } d;\n" " uint32_t *a = d.f;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Don't decay std::array check("std::array f() {\n" " std::array x;\n" " return x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Make sure we don't hang @@ -2412,7 +2412,7 @@ private: "void f() {\n" " using T = A[3];\n" " A &&a = T{1, 2, 3}[1];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Make sure we don't hang @@ -2420,7 +2420,7 @@ private: "void f() {\n" " using T = A[3];\n" " A &&a = T{1, 2, 3}[1]();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Make sure we don't hang @@ -2428,7 +2428,7 @@ private: "void f() {\n" " using T = A[3];\n" " A &&a = T{1, 2, 3}[1];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Make sure we don't hang @@ -2436,7 +2436,7 @@ private: "void f() {\n" " using T = A[3];\n" " A &&a = T{1, 2, 3}[1]();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Crash #8872 @@ -2444,14 +2444,14 @@ private: " void operator()(b c) override {\n" " d(c, [&] { c->e });\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); check("struct a {\n" " void operator()(b c) override {\n" " d(c, [=] { c->e });\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); check("struct a {\n" @@ -2460,7 +2460,7 @@ private: "a f() {\n" " char c[20];\n" " return c;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct a {\n" @@ -2470,7 +2470,7 @@ private: " char c[20];\n" " a d = c;\n" " return d;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" @@ -2478,14 +2478,14 @@ private: " std::vector v;\n" " auto g() { return v.end(); }\n" " };\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int * f(std::vector& v) {\n" " for(int & x : v)\n" " return &x;\n" " return nullptr;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9275 @@ -2497,7 +2497,7 @@ private: " char buf[1024];\n" " const char* msg = buf;\n" " m = msg;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9201 @@ -2505,14 +2505,14 @@ private: " struct a { int m; };\n" " static a b{0};\n" " return &b.m;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9453 check("int *ptr;\n" "void foo(int arr[]) {\n" " ptr = &arr[2];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9639 @@ -2523,7 +2523,7 @@ private: "const char * f() {\n" " const Fred &fred = getFred();\n" " return fred.s.c_str();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9534 @@ -2533,14 +2533,14 @@ private: "int* f(int i, std::vector& v) {\n" " A& y = v[i];\n" " return &y.x[i];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9712 check("std::string f(const char *str) {\n" " char value[256];\n" " return value;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9770 @@ -2603,7 +2603,7 @@ private: check("auto f() {\n" " int a;\n" " return std::ref(a);\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'a' that will be invalid when returning.\n", errout.str()); @@ -2611,7 +2611,7 @@ private: check("auto f() {\n" " int a;\n" " return std::make_tuple(std::ref(a));\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'a' that will be invalid when returning.\n", errout.str()); @@ -2623,7 +2623,7 @@ private: "auto g() {\n" " std::vector v;\n" " return by_value(v.begin());\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:7] -> [test.cpp:7] -> [test.cpp:3] -> [test.cpp:3] -> [test.cpp:6] -> [test.cpp:7]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n", errout.str()); @@ -2646,7 +2646,7 @@ private: "auto f() {\n" " int i = 0;\n" " return by_ref(i);\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:2] -> [test.cpp:1] -> [test.cpp:2] -> [test.cpp:6] -> [test.cpp:5] -> [test.cpp:6]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", errout.str()); @@ -2664,7 +2664,7 @@ private: " int a;\n" " std::tie(a) = x;\n" " return a;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::pair\n" @@ -2689,7 +2689,7 @@ private: "A f() {\n" " int i = 0;\n" " return A{i, i};\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:7] -> [test.cpp:6] -> [test.cpp:7]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", errout.str()); @@ -2701,7 +2701,7 @@ private: "A f() {\n" " int i = 0;\n" " return {i, i};\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:7] -> [test.cpp:6] -> [test.cpp:7]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", errout.str()); @@ -2714,7 +2714,7 @@ private: " int i = 0;\n" " A r{i, i};\n" " return r;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:7] -> [test.cpp:6] -> [test.cpp:8]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", errout.str()); @@ -2727,7 +2727,7 @@ private: " int i = 0;\n" " A r = {i, i};\n" " return r;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:7] -> [test.cpp:6] -> [test.cpp:8]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", errout.str()); @@ -2739,7 +2739,7 @@ private: "A f(int& x) {\n" " int i = 0;\n" " return A{i, x};\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:7] -> [test.cpp:6] -> [test.cpp:7]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", errout.str()); @@ -2751,7 +2751,7 @@ private: "A f(int& x) {\n" " int i = 0;\n" " return A{x, i};\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A {\n" @@ -2760,14 +2760,14 @@ private: "};\n" "A f(int& x) {\n" " return A{x, x};\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A { int i; const int& j; };\n" "A f(int& x) {\n" " int y = 0;\n" " return A{y, x};\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2776,7 +2776,7 @@ private: " int i = 0;\n" " std::vector v = {&i, &i};\n" " return v;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", errout.str()); @@ -2786,7 +2786,7 @@ private: " int i = 0;\n" " std::vector v{&i, &i};\n" " return v;\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", "", @@ -2795,14 +2795,14 @@ private: check("std::vector f() {\n" " int i = 0;\n" " return {&i, &i};\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'i' that will be invalid when returning.\n", errout.str()); check("std::vector f(int& x) {\n" " return {&x, &x};\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::vector f() {\n" @@ -2810,7 +2810,7 @@ private: " x.insert(\"1\");\n" " x.insert(\"2\");\n" " return { x.begin(), x.end() };\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2819,7 +2819,7 @@ private: "A f() {\n" " std::string ba(\"hello\");\n" " return ba.c_str();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A { A(const char *a); };\n" @@ -2827,7 +2827,7 @@ private: " std::string ba(\"hello\");\n" " A bp = ba.c_str();\n" " return bp;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A { A(const char *a); };\n" @@ -2836,7 +2836,7 @@ private: " std::vector v;\n" " v.push_back(ba.c_str());\n" " return v;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::string f(const std::string& x) {\n" @@ -2844,7 +2844,7 @@ private: " if (!x.empty())\n" " return x + c;\n" " return \"\";\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::string f(const std::string& x) {\n" @@ -2852,7 +2852,7 @@ private: " if (!x.empty())\n" " return c + 1;\n" " return \"\";\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2863,7 +2863,7 @@ private: "void f(int& i) {\n" " int* x = &g(0);\n" " i += *x;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:1] -> [test.cpp:2] -> [test.cpp:5] -> [test.cpp:5] -> [test.cpp:6]: (error) Using pointer to temporary.\n", errout.str()); @@ -2873,7 +2873,7 @@ private: " const char* b = a.toStdString().c_str();\n" " QString c = b;\n" " return c;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:4]: (error) Using pointer to temporary.\n", errout.str()); @@ -2882,7 +2882,7 @@ private: " const char *x = s.substr(1,2).c_str();\n" " auto i = s.substr(4,5).begin();\n" " return *i;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:4]: (error) Using iterator to temporary.\n", errout.str()); @@ -2891,7 +2891,7 @@ private: " std::stringstream tmp;\n" " const std::string &str = tmp.str();\n" " return std::string(str.c_str(), 1);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int get_value();\n" @@ -2925,7 +2925,7 @@ private: " f = [&]{ return b; };\n" " }\n" " f();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4] -> [test.cpp:7]: (error) Using lambda that captures local variable 'b' that is out of scope.\n", errout.str()); check("void f(bool b) {\n" @@ -2935,7 +2935,7 @@ private: " x = y;\n" " }\n" " x[3];\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:5] -> [test.cpp:4] -> [test.cpp:7]: (error) Using pointer to local variable 'y' that is out of scope.\n", errout.str()); @@ -2947,7 +2947,7 @@ private: " f = [&]{ return b; };\n" " f();\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct a {\n" @@ -2956,7 +2956,7 @@ private: "};\n" "void a::b() {\n" " c.end()\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void b(char f[], char c[]) {\n" @@ -2964,7 +2964,7 @@ private: " std::string e;\n" " b(f, e.c_str())\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(bool b) {\n" @@ -2974,11 +2974,11 @@ private: " s = buf;\n" " }\n" " std::cout << s;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int &a[];\n" - "void b(){int *c = a};\n"); + "void b(){int *c = a};"); ASSERT_EQUALS("", errout.str()); check("struct A {\n" @@ -2992,7 +2992,7 @@ private: " return y.x;\n" " };\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -3068,7 +3068,7 @@ private: " if(b && a)\n" " return *iPtr;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:4] -> [test.cpp:8]: (error) Using pointer to local variable 'x' that is out of scope.\n", errout.str()); } diff --git a/test/testbool.cpp b/test/testbool.cpp index ab0a0d2da..f9dde9cfc 100644 --- a/test/testbool.cpp +++ b/test/testbool.cpp @@ -127,7 +127,7 @@ private: "void f() {\n" " S s = {0};\n" " *s.p = true;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct S {\n" @@ -136,7 +136,7 @@ private: "void f() {\n" " S s = {0};\n" " s.p = true;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Boolean value assigned to pointer.\n", errout.str()); // ticket #5627 - false positive: template @@ -210,7 +210,7 @@ private: "void f() {\n" " S s = {0};\n" " s.p = true;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (style) Boolean value assigned to floating point variable.\n", errout.str()); check("struct S {\n" @@ -219,7 +219,7 @@ private: "void f() {\n" " S s = {0};\n" " *s.p[0] = true;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (style) Boolean value assigned to floating point variable.\n", errout.str()); } @@ -227,100 +227,88 @@ private: check("void f(int x) {\n" " if ((x && 0x0f)==6)\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); check("void f(int x) {\n" " if ((x && 0x0f)==0)\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x) {\n" " if ((x || 0x0f)==6)\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); check("void f(int x) {\n" " if ((x || 0x0f)==0)\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x) {\n" " if ((x & 0x0f)==6)\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x) {\n" " if ((x | 0x0f)==6)\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x) {\n" " if ((5 && x)==3)\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); check("void f(int x) {\n" " if ((5 && x)==3 || (8 && x)==9)\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); check("void f(int x) {\n" " if ((5 && x)!=3)\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); check("void f(int x) {\n" " if ((5 && x) > 3)\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); check("void f(int x) {\n" " if ((5 && x) > 0)\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x) {\n" " if ((5 && x) < 0)\n" " a++;\n" - "}\n" + "}" ); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str()); check("void f(int x) {\n" " if ((5 && x) < 1)\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x) {\n" " if ((5 && x) > 1)\n" " a++;\n" - "}\n" + "}" ); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str()); @@ -328,85 +316,75 @@ private: check("void f(int x) {\n" " if (0 < (5 && x))\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x) {\n" " if (0 > (5 && x))\n" " a++;\n" - "}\n" + "}" ); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str()); check("void f(int x) {\n" " if (1 > (5 && x))\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x) {\n" " if (1 < (5 && x))\n" " a++;\n" - "}\n" + "}" ); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str()); check("void f(bool x ) {\n" " if ( x > false )\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str()); check("void f(bool x ) {\n" " if ( false < x )\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str()); check("void f(bool x ) {\n" " if ( x < false )\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str()); check("void f(bool x ) {\n" " if ( false > x )\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str()); check("void f(bool x ) {\n" " if ( x >= false )\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str()); check("void f(bool x ) {\n" " if ( false >= x )\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str()); check("void f(bool x ) {\n" " if ( x <= false )\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str()); check("void f(bool x ) {\n" " if ( false <= x )\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str()); check("typedef int (*func)(bool invert);\n" @@ -1180,25 +1158,25 @@ private: check("bool f(void) {\n" " auto x = [](void) { return -1; };\n" " return false;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("bool f(void) {\n" " auto x = [](void) { return -1; };\n" " return 2;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout.str()); check("bool f(void) {\n" " auto x = [](void) -> int { return -1; };\n" " return false;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("bool f(void) {\n" " auto x = [](void) -> int { return -1; };\n" " return 2;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout.str()); } diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 41238ac5d..706aaf4ff 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -371,11 +371,11 @@ private: ASSERT_EQUALS("", errout.str()); check("int x[5];\n" - "int a = x[10];\n"); + "int a = x[10];"); ASSERT_EQUALS("[test.cpp:2]: (error) Array 'x[5]' accessed at index 10, which is out of bounds.\n", errout.str()); check("int x[5];\n" - "int a = (x)[10];\n"); + "int a = (x)[10];"); ASSERT_EQUALS("[test.cpp:2]: (error) Array 'x[5]' accessed at index 10, which is out of bounds.\n", errout.str()); } @@ -1323,7 +1323,7 @@ private: ASSERT_EQUALS("", errout.str()); - check("int f( ){ \n" + check("int f( ){\n" "struct Struct{\n" " int arr[ 3 ];\n" "};\n" @@ -1367,7 +1367,7 @@ private: check("struct AB { int a[10]; int b[10]; };\n" "int main() {\n" " struct AB ab;\n" - " int * p = &ab.a[10]; \n" + " int * p = &ab.a[10];\n" " return 0;\n" "}"); ASSERT_EQUALS("", errout.str()); @@ -1375,7 +1375,7 @@ private: check("struct AB { int a[10]; int b[10]; };\n" "int main() {\n" " struct AB ab[1];\n" - " int * p = &ab[0].a[10]; \n" + " int * p = &ab[0].a[10];\n" " return 0;\n" "}"); ASSERT_EQUALS("", errout.str()); @@ -1383,7 +1383,7 @@ private: check("struct AB { int a[10]; int b[10]; };\n" "int main() {\n" " struct AB ab[1];\n" - " int * p = &ab[10].a[0]; \n" + " int * p = &ab[10].a[0];\n" " return 0;\n" "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Array 'ab[1]' accessed at index 10, which is out of bounds.\n", errout.str()); @@ -1471,7 +1471,7 @@ private: check("int s[4];\n" "void f() {\n" " for (int i = 2; i < 0; i++)\n" - " s[i] = 5; \n" + " s[i] = 5;\n" "}"); ASSERT_EQUALS("", errout.str()); } @@ -1509,7 +1509,7 @@ private: " i++;\n" " }\n" " arr[k];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1521,7 +1521,7 @@ private: "void g() {\n" " f(\"12345678\");\n" " f(\"12345\");\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1640,7 +1640,7 @@ private: " vertices[i][1][2] = 4.0;\n" " vertices[i][1][3] = 5.0;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); { @@ -2137,7 +2137,7 @@ private: ASSERT_EQUALS("", errout.str()); check("class ActorSprite { static ImageSet * targetCursorImages[2][10]; };\n" - "ImageSet *ActorSprite::targetCursorImages[2][10];\n"); + "ImageSet *ActorSprite::targetCursorImages[2][10];"); ASSERT_EQUALS("", errout.str()); } @@ -2208,7 +2208,7 @@ private: check("constexpr int blockLen = 10;\n" "void foo(std::array& a) {\n" " a[2] = 2;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2546,7 +2546,7 @@ private: " const char *src = \"AAAAAAAAAAAAAAAAAAAAA\";\n" " for (size_t i = 0; i <= 4; i++)\n" " dst[i] = src[i];\n" - "} } }\n"); + "} } }"); ASSERT_EQUALS("[test.cpp:6]: (error) Array 'dst[4]' accessed at index 4, which is out of bounds.\n", errout.str()); } @@ -2595,12 +2595,11 @@ private: // #7083: false positive: typedef and initialization with strings void buffer_overrun_29() { - check("typedef char testChar[10]; \n" - "int main(){ \n" - " testChar tc1 = \"\"; \n" - " tc1[5]='a'; \n" - "} \n" - ); + check("typedef char testChar[10];\n" + "int main(){\n" + " testChar tc1 = \"\";\n" + " tc1[5]='a';\n" + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2610,8 +2609,7 @@ private: check("struct S { int m[9]; };\n" "int f(S * s) {\n" " return s->m[sizeof(s->m)];\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Array 's->m[9]' accessed at index 36, which is out of bounds.\n", errout.str()); } @@ -2873,7 +2871,7 @@ private: " const char d[] = \"0123456789\";\n" " char *cp = d + 3;\n" " return cp - d;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3389,7 +3387,7 @@ private: ASSERT_EQUALS("", errout.str()); // ticket #1659 - overflowing variable when using memcpy - check("void f(void) { \n" + check("void f(void) {\n" " char c;\n" " mymemset(&c, 0, 4);\n" "}", settings); @@ -3683,7 +3681,7 @@ private: // Test with invalid code that there is no segfault check("char baz[100];\n" - "strncpy(baz, \"var\", 100)\n"); + "strncpy(baz, \"var\", 100)"); ASSERT_EQUALS("", errout.str()); // Test that there are no duplicate error messages @@ -3725,13 +3723,13 @@ private: check("void bar() {\n" " char buf[4];\n" " strncpy(buf, \"ab\", 4);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void bar() {\n" " char buf[4];\n" " strncpy(buf, \"abcde\", 4);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'buf' may not be null-terminated after the call to strncpy().\n", errout.str()); } @@ -3819,8 +3817,8 @@ private: void crash6() { check("void start(char* name) {\n" - "char snapname[64] = { 0 }; \n" - "strncpy(snapname, \"snapshot\", arrayLength(snapname)); \n" + "char snapname[64] = { 0 };\n" + "strncpy(snapname, \"snapshot\", arrayLength(snapname));\n" "}"); } @@ -4195,7 +4193,7 @@ private: " int *a;\n" " a = new int[-1];\n" " delete [] a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", errout.str()); check("void f()\n" @@ -4203,7 +4201,7 @@ private: " int *a;\n" " a = malloc( -10 );\n" " free(a);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", errout.str()); check("void f()\n" @@ -4211,7 +4209,7 @@ private: " int *a;\n" " a = malloc( -10);\n" " free(a);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", errout.str()); check("void f()\n" @@ -4219,7 +4217,7 @@ private: " int *a;\n" " a = alloca( -10 );\n" " free(a);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", errout.str()); } @@ -4234,7 +4232,7 @@ private: check("int x, y;\n" "int a[-1];\n" "int b[x?1:-1];\n" - "int c[x?y:-1];\n"); + "int c[x?y:-1];"); ASSERT_EQUALS("", errout.str()); } @@ -4242,7 +4240,7 @@ private: check("void f() {\n" " char arr[10];\n" " p = arr + 20;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic 'arr+20' is out of bounds.\n", errout.str()); } @@ -4401,61 +4399,61 @@ private: } void objectIndex() { - check("int f() { \n" + check("int f() {\n" " int i;\n" - " return (&i)[1]; \n" - "}\n"); + " return (&i)[1];\n" + "}"); ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:3]: (error) The address of local variable 'i' is accessed at non-zero index.\n", errout.str()); - check("int f(int j) { \n" + check("int f(int j) {\n" " int i;\n" - " return (&i)[j]; \n" - "}\n"); + " return (&i)[j];\n" + "}"); ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:3]: (warning) The address of local variable 'i' might be accessed at non-zero index.\n", errout.str()); - check("int f() { \n" + check("int f() {\n" " int i;\n" - " return (&i)[0]; \n" - "}\n"); + " return (&i)[0];\n" + "}"); ASSERT_EQUALS("", errout.str()); - check("int f(int * i) { \n" - " return i[1]; \n" - "}\n"); + check("int f(int * i) {\n" + " return i[1];\n" + "}"); ASSERT_EQUALS("", errout.str()); - check("int f(std::vector i) { \n" - " return i[1]; \n" - "}\n"); + check("int f(std::vector i) {\n" + " return i[1];\n" + "}"); ASSERT_EQUALS("", errout.str()); - check("int f(std::vector i) { \n" - " return i.data()[1]; \n" - "}\n"); + check("int f(std::vector i) {\n" + " return i.data()[1];\n" + "}"); ASSERT_EQUALS("", errout.str()); - check("int* f(std::vector& i) { \n" - " return &(i[1]); \n" - "}\n"); + check("int* f(std::vector& i) {\n" + " return &(i[1]);\n" + "}"); ASSERT_EQUALS("", errout.str()); check("struct A { int i; int j; };\n" - "int f() { \n" + "int f() {\n" " A x;\n" - " return (&x.i)[0]; \n" - "}\n"); + " return (&x.i)[0];\n" + "}"); ASSERT_EQUALS("", errout.str()); check("struct A { int i; int j; };\n" - "int f() { \n" + "int f() {\n" " A x;\n" " int * i = &x.i;\n" - " return i[0]; \n" - "}\n"); + " return i[0];\n" + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" @@ -4463,7 +4461,7 @@ private: " std::map m;\n" " m[0] = &x;\n" " m[1] = &x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int f() {\n" @@ -4471,7 +4469,7 @@ private: " std::map m;\n" " m[0] = &x;\n" " return m[0][1];\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:4] -> [test.cpp:5]: (error) The address of local variable 'x' is accessed at non-zero index.\n", errout.str()); @@ -4482,7 +4480,7 @@ private: " m[0] = &x;\n" " m[1] = y;\n" " return m[1][1];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void print(char** test);\n" diff --git a/test/testclass.cpp b/test/testclass.cpp index 29ea8a45f..e6a36b35d 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -244,50 +244,50 @@ private: } void copyCtorAndEqOperator() { - checkCopyCtorAndEqOperator("class A \n" - "{ \n" - " A(const A& other) { } \n" + checkCopyCtorAndEqOperator("class A\n" + "{\n" + " A(const A& other) { }\n" " A& operator=(const A& other) { return *this; }\n" "};"); ASSERT_EQUALS("", errout.str()); - checkCopyCtorAndEqOperator("class A \n" - "{ \n" + checkCopyCtorAndEqOperator("class A\n" + "{\n" "};"); ASSERT_EQUALS("", errout.str()); - checkCopyCtorAndEqOperator("class A \n" - "{ \n" - " A(const A& other) { } \n" + checkCopyCtorAndEqOperator("class A\n" + "{\n" + " A(const A& other) { }\n" "};"); ASSERT_EQUALS("", errout.str()); - checkCopyCtorAndEqOperator("class A \n" - "{ \n" + checkCopyCtorAndEqOperator("class A\n" + "{\n" " A& operator=(const A& other) { return *this; }\n" "};"); ASSERT_EQUALS("", errout.str()); - checkCopyCtorAndEqOperator("class A \n" - "{ \n" - " A(const A& other) { } \n" + checkCopyCtorAndEqOperator("class A\n" + "{\n" + " A(const A& other) { }\n" " int x;\n" "};"); TODO_ASSERT_EQUALS("[test.cpp:1]: (warning) The class 'A' has 'copy constructor' but lack of 'operator='.\n", "", errout.str()); // TODO the error message should be clarified. It should say something like 'copy constructor is empty and will not assign i and therefore the behaviour is different to the default assignment operator' - checkCopyCtorAndEqOperator("class A \n" - "{ \n" + checkCopyCtorAndEqOperator("class A\n" + "{\n" " A& operator=(const A& other) { return *this; }\n" " int x;\n" "};"); TODO_ASSERT_EQUALS("[test.cpp:1]: (warning) The class 'A' has 'operator=' but lack of 'copy constructor'.\n", "", errout.str()); // TODO the error message should be clarified. It should say something like 'assignment operator does not assign i and therefore the behaviour is different to the default copy constructor' - checkCopyCtorAndEqOperator("class A \n" - "{ \n" + checkCopyCtorAndEqOperator("class A\n" + "{\n" " A& operator=(const int &x) { this->x = x; return *this; }\n" " int x;\n" "};"); @@ -321,7 +321,7 @@ private: " test = std::move(s.test);\n" " return *this;\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); // #8337 - False positive in copy constructor detection @@ -1126,7 +1126,7 @@ private: "class A::B\n" "{\n" " B & operator=(const B & b) { return b; }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); checkOpertorEqRetRefThis( @@ -1137,7 +1137,7 @@ private: "{\n" " B & operator=(const B &);\n" "};\n" - "A::B & A::B::operator=(const A::B & b) { return b; }\n"); + "A::B & A::B::operator=(const A::B & b) { return b; }"); ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); checkOpertorEqRetRefThis( @@ -1147,7 +1147,7 @@ private: "class A::B\n" "{\n" " A::B & operator=(const A::B & b) { return b; }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); checkOpertorEqRetRefThis( @@ -1158,7 +1158,7 @@ private: "{\n" " A::B & operator=(const A::B &);\n" "};\n" - "A::B & A::B::operator=(const A::B & b) { return b; }\n"); + "A::B & A::B::operator=(const A::B & b) { return b; }"); ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); checkOpertorEqRetRefThis( @@ -1168,7 +1168,7 @@ private: "class A::B\n" "{\n" " B & operator=(const B & b) { return b; }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); checkOpertorEqRetRefThis( @@ -1179,7 +1179,7 @@ private: "{\n" " B & operator=(const B &);\n" "};\n" - "A::B & A::B::operator=(const A::B & b) { return b; }\n"); + "A::B & A::B::operator=(const A::B & b) { return b; }"); ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); checkOpertorEqRetRefThis( @@ -1189,7 +1189,7 @@ private: "class A::B\n" "{\n" " A::B & operator=(const A::B & b) { return b; }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); checkOpertorEqRetRefThis( @@ -1200,7 +1200,7 @@ private: "{\n" " A::B & operator=(const A::B &);\n" "};\n" - "A::B & A::B::operator=(const A::B & b) { return b; }\n"); + "A::B & A::B::operator=(const A::B & b) { return b; }"); ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); } @@ -1228,7 +1228,7 @@ private: "class NS::szp\n" "{\n" " szp &operator =(int *other) {}\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str()); checkOpertorEqRetRefThis( @@ -1249,7 +1249,7 @@ private: "class NS::szp\n" "{\n" " NS::szp &operator =(int *other) {}\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str()); checkOpertorEqRetRefThis( @@ -1270,7 +1270,7 @@ private: "class A::szp\n" "{\n" " szp &operator =(int *other) {}\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str()); checkOpertorEqRetRefThis( @@ -1291,7 +1291,7 @@ private: "class A::szp\n" "{\n" " A::szp &operator =(int *other) {}\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str()); checkOpertorEqRetRefThis( @@ -1363,7 +1363,7 @@ private: " }\n" " return *this;\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -1460,7 +1460,7 @@ private: " basic_fbstring& replace() {\n" " return replaceImplDiscr();\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -2940,7 +2940,7 @@ private: "};\n" "void f() {\n" " A a;\n" - " memset(&a, 0, sizeof(a)); \n" + " memset(&a, 0, sizeof(a));\n" "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Using 'memset' on class that contains a reference.\n", errout.str()); checkNoMemset("class A {\n" @@ -2948,7 +2948,7 @@ private: "};\n" "void f() {\n" " A a;\n" - " memset(&a, 0, sizeof(a)); \n" + " memset(&a, 0, sizeof(a));\n" "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Using 'memset' on class that contains a reference.\n", errout.str()); @@ -3341,7 +3341,7 @@ private: checkThisSubtraction("; *this = *this-x ;\n" "this-x ;\n" - "this-x ;\n"); + "this-x ;"); ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\n" "[test.cpp:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\n", errout.str()); } @@ -4495,8 +4495,7 @@ private: "{return m_strVal.c_str();}\n" "private:\n" "std::string m_strVal;\n" - "};\n" - ); + "};"); ASSERT_EQUALS("", errout.str()); checkConst("class A{\n" @@ -4506,8 +4505,7 @@ private: "{return m_strVal.c_str();}\n" "private:\n" "std::string m_strVal;\n" - "};\n" - ); + "};"); ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::strGetString' can be const.\n", errout.str()); checkConst("class A{\n" @@ -4517,8 +4515,7 @@ private: "{return m_strVal.c_str();}\n" "private:\n" "std::string m_strVal;\n" - "};\n" - ); + "};"); ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const.\n", errout.str()); checkConst("class A{\n" @@ -4528,8 +4525,7 @@ private: "{return m_strVec.size();}\n" "private:\n" "std::vector m_strVec;\n" - "};\n" - ); + "};"); ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const.\n", errout.str()); checkConst("class A{\n" @@ -4539,8 +4535,7 @@ private: "{return m_strVec.empty();}\n" "private:\n" "std::vector m_strVec;\n" - "};\n" - ); + "};"); ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const.\n", errout.str()); } @@ -4551,8 +4546,7 @@ private: " std::swap(delays_[index1], delays_[index2]);\n" "}\n" "float delays_[4];\n" - "};\n" - ); + "};"); ASSERT_EQUALS("", errout.str()); checkConst("struct DelayBase {\n" @@ -4595,8 +4589,7 @@ private: " x=xPos;\n" " y=yPos;\n" " }\n" - "};\n" - ); + "};"); ASSERT_EQUALS("", errout.str()); checkConst("class AA : public P {\n" @@ -5530,7 +5523,7 @@ private: " m_ptr = new char[42];\n" " }\n" " MyString append( const MyString& str )\n" - " { return operator+=( str ); } \n" + " { return operator+=( str ); }\n" " char *m_ptr;\n" "};"); ASSERT_EQUALS("", errout.str()); @@ -5539,7 +5532,7 @@ private: " MyString() : m_ptr(0){}\n" " MyString& operator+=( const MyString& rhs );\n" " MyString append( const MyString& str )\n" - " { return operator+=( str ); } \n" + " { return operator+=( str ); }\n" " char *m_ptr;\n" "};"); ASSERT_EQUALS("", errout.str()); @@ -5672,7 +5665,7 @@ private: " TemplateClass a;\n" " TemplateClass b;\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5682,7 +5675,7 @@ private: " void f(int v) { g((char *) &v); }\n" " void g(char *) { n++; }\n" " int n;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -5696,7 +5689,7 @@ private: "public:\n" " const std::list>& get() { return m_test.m_list; }\n" " TestList> m_test;\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:8]: (style, inconclusive) Technically the member function 'Test::get' can be const.\n", errout.str()); } @@ -5814,8 +5807,7 @@ private: " {\n" " v = 0;\n" " }\n" - "};\n" - ); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -5827,8 +5819,7 @@ private: " {\n" " v[0] = \"Happy new year!\";\n" " }\n" - "};\n" - ); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -6839,16 +6830,14 @@ private: " int x;\n" " Fred(int x);\n" "};\n" - "Fred::Fred(int x) : x(x) { }\n" - ); + "Fred::Fred(int x) : x(x) { }"); ASSERT_EQUALS("", errout.str()); checkSelfInitialization("class Fred {\n" " int x;\n" " Fred(int x);\n" "};\n" - "Fred::Fred(int x) : x{x} { }\n" - ); + "Fred::Fred(int x) : x{x} { }"); ASSERT_EQUALS("", errout.str()); checkSelfInitialization("class Fred {\n" @@ -6915,21 +6904,21 @@ private: " A();\n" "};\n" "A::A()\n" - "{f();}\n"); + "{f();}"); ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (style) Virtual function 'f' is called from constructor 'A()' at line 7. Dynamic binding is not used.\n", errout.str()); checkVirtualFunctionCall("class A {\n" " virtual int f();\n" " A() {f();}\n" "};\n" - "int A::f() { return 1; }\n"); + "int A::f() { return 1; }"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used.\n", errout.str()); checkVirtualFunctionCall("class A : B {\n" " int f() override;\n" " A() {f();}\n" "};\n" - "int A::f() { return 1; }\n"); + "int A::f() { return 1; }"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (style) Virtual function 'f' is called from constructor 'A()' at line 3. Dynamic binding is not used.\n", errout.str()); checkVirtualFunctionCall("class B {\n" @@ -6939,14 +6928,14 @@ private: " int f();\n" " A() {f();}\n" "};\n" - "int A::f() { return 1; }\n"); + "int A::f() { return 1; }"); ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:5]: (style) Virtual function 'f' is called from constructor 'A()' at line 6. Dynamic binding is not used.\n", errout.str()); checkVirtualFunctionCall("class A\n" "{\n" " A() { A::f(); }\n" " virtual void f() {}\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -6957,7 +6946,7 @@ private: " A();\n" "};\n" "A::A()\n" - "{pure();}\n"); + "{pure();}"); ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in constructor.\n", errout.str()); checkVirtualFunctionCall("class A\n" @@ -6967,17 +6956,17 @@ private: " int m;\n" "};\n" "A::A():m(A::pure())\n" - "{}\n"); + "{}"); ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in constructor.\n", errout.str()); checkVirtualFunctionCall("class A\n" " {\n" - " virtual void pure()=0; \n" - " virtual ~A(); \n" - " int m; \n" + " virtual void pure()=0;\n" + " virtual ~A();\n" + " int m;\n" "};\n" "A::~A()\n" - "{pure();}\n"); + "{pure();}"); ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in destructor.\n", errout.str()); checkVirtualFunctionCall("class A\n" @@ -6985,10 +6974,10 @@ private: " virtual void pure()=0;\n" " void nonpure()\n" " {pure();}\n" - " A(); \n" + " A();\n" "};\n" "A::A()\n" - "{nonpure();}\n"); + "{nonpure();}"); ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:5] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in constructor.\n", errout.str()); checkVirtualFunctionCall("class A\n" @@ -6996,23 +6985,23 @@ private: " virtual int pure()=0;\n" " int nonpure()\n" " {return pure();}\n" - " A(); \n" + " A();\n" " int m;\n" "};\n" "A::A():m(nonpure())\n" - "{}\n"); + "{}"); TODO_ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:5] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in constructor.\n", "", errout.str()); checkVirtualFunctionCall("class A\n" " {\n" - " virtual void pure()=0; \n" + " virtual void pure()=0;\n" " void nonpure()\n" " {pure();}\n" " virtual ~A();\n" " int m;\n" "};\n" "A::~A()\n" - "{nonpure();}\n"); + "{nonpure();}"); ASSERT_EQUALS("[test.cpp:10] -> [test.cpp:5] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in destructor.\n", errout.str()); checkVirtualFunctionCall("class A\n" @@ -7021,7 +7010,7 @@ private: " A(bool b);\n" "};\n" "A::A(bool b)\n" - "{if (b) pure();}\n"); + "{if (b) pure();}"); ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in constructor.\n", errout.str()); checkVirtualFunctionCall("class A\n" @@ -7061,7 +7050,7 @@ private: " A(const A & a);\n" "};\n" "A::A(const A & a)\n" - "{a.pure();}\n"); + "{a.pure();}"); ASSERT_EQUALS("", errout.str()); checkVirtualFunctionCall("class A\n" @@ -7074,7 +7063,7 @@ private: " virtual void pure()=0;\n" "};\n" "A::A()\n" - "{B b; b.pure();}\n"); + "{B b; b.pure();}"); ASSERT_EQUALS("", errout.str()); } @@ -7087,7 +7076,7 @@ private: "A::A()\n" "{pureWithBody();}\n" "void A::pureWithBody()\n" - "{}\n"); + "{}"); ASSERT_EQUALS("", errout.str()); checkVirtualFunctionCall("class A\n" @@ -7095,12 +7084,12 @@ private: " virtual void pureWithBody()=0;\n" " void nonpure()\n" " {pureWithBody();}\n" - " A(); \n" + " A();\n" "};\n" "A::A()\n" "{nonpure();}\n" "void A::pureWithBody()\n" - "{}\n"); + "{}"); ASSERT_EQUALS("", errout.str()); } @@ -7111,10 +7100,10 @@ private: " virtual void pure()=0;\n" " void nonpure(bool bCallPure)\n" " { if (bCallPure) pure();}\n" - " A(); \n" + " A();\n" "};\n" "A::A()\n" - "{nonpure(false);}\n"); + "{nonpure(false);}"); ASSERT_EQUALS("", errout.str()); checkVirtualFunctionCall("class A\n" @@ -7122,10 +7111,10 @@ private: " virtual void pure()=0;\n" " void nonpure(bool bCallPure)\n" " { if (!bCallPure) ; else pure();}\n" - " A(); \n" + " A();\n" "};\n" "A::A()\n" - "{nonpure(false);}\n"); + "{nonpure(false);}"); ASSERT_EQUALS("", errout.str()); checkVirtualFunctionCall("class A\n" @@ -7137,10 +7126,10 @@ private: " case true: pure(); break;\n" " }\n" " }\n" - " A(); \n" + " A();\n" "};\n" "A::A()\n" - "{nonpure(false);}\n"); + "{nonpure(false);}"); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testcondition.cpp b/test/testcondition.cpp index a18a3edec..497cd1a57 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -347,7 +347,7 @@ private: " if (c == 4)\n" " c = 0;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int a) {\n" // #6662 @@ -355,7 +355,7 @@ private: " while (x <= 4) {\n" " if (x != 5) {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Mismatching assignment and comparison, comparison 'x!=5' is always true.\n", errout.str()); check("void f(int a) {\n" // #6662 @@ -363,7 +363,7 @@ private: " while ((x += 4) < 10) {\n" " if (x != 5) {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" @@ -512,7 +512,7 @@ private: check("void foo() {\n" " if (a) {}\n" " else if (!!a) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str()); } @@ -657,37 +657,37 @@ private: check("void f(bool a, bool b) {\n" " if(a && b){}\n" " else if( !!b && !!a){}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str()); check("void f(bool a, bool b) {\n" " if(a && b){}\n" " else if( !!b && a){}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str()); check("void f(bool a, bool b) {\n" " if(a && b){}\n" " else if( b && !!a){}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str()); check("void f(bool a, bool b) {\n" " if(a && b){}\n" " else if( b && !(!a)){}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str()); check("void f(bool a, bool b) {\n" " if(a && b){}\n" " else if( !!b && !(!a)){}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str()); check("void f(bool a, bool b) {\n" " if(a && b){}\n" " else if( !!(b) && !!(a+b)){}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #8168 @@ -699,7 +699,7 @@ private: "void TestFunction(int value) {\n" " if ( value & (int)Value1 ) {}\n" " else if ( value & (int)Value2 ) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(size_t x) {\n" @@ -851,94 +851,84 @@ private: check("void f(int x) {\n" " if ((x != 1) || (x != 3))\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3.\n", errout.str()); check("void f(int x) {\n" " if (1 != x || 3 != x)\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: x != 1 || x != 3.\n", errout.str()); check("void f(int x) {\n" " if (x<0 && !x) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x < 0 && !x.\n", errout.str()); check("void f(int x) {\n" " if (x==0 && x) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x == 0 && x.\n", errout.str()); check("void f(int x) {\n" // ast.. " if (y == 1 && x == 1 && x == 7) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x == 1 && x == 7.\n", errout.str()); check("void f(int x, int y) {\n" " if (x != 1 || y != 1)\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x, int y) {\n" " if ((y == 1) && (x != 1) || (x != 3))\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x, int y) {\n" " if ((x != 1) || (x != 3) && (y == 1))\n" " a++;\n" - "}\n" + "}" ); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Condition 'x!=3' is always true\n", errout.str()); check("void f(int x) {\n" " if ((x != 1) && (x != 3))\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x) {\n" " if ((x == 1) || (x == 3))\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x, int y) {\n" " if ((x != 1) || (y != 3))\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x, int y) {\n" " if ((x != hotdog) || (y != hotdog))\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x, int y) {\n" " if ((x != 5) || (y != 5))\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x) {\n" " if ((x != 5) || (x != 6))\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: x != 5 || x != 6.\n", errout.str()); check("void f(unsigned int a, unsigned int b, unsigned int c) {\n" @@ -947,8 +937,7 @@ private: " return true;\n" " }\n" " return false;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1270,7 +1259,7 @@ private: void incorrectLogicOperator9() { // #6069 "False positive incorrectLogicOperator due to dynamic_cast" check("class MyType;\n" "class OtherType;\n" - "void foo (OtherType* obj) { \n" + "void foo (OtherType* obj) {\n" " assert((!obj) || dynamic_cast(obj));\n" "}"); ASSERT_EQUALS("", errout.str()); @@ -1309,7 +1298,7 @@ private: " y.f();\n" " if (a > x && a < y)\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:6] -> [test.cpp:8]: (warning) Logical conjunction always evaluates to false: a > x && a < y.\n", errout.str()); check("struct A {\n" @@ -1321,7 +1310,7 @@ private: " y.f();\n" " if (a > x && a < y)\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(A a) {\n" @@ -1330,7 +1319,7 @@ private: " y.f();\n" " if (a > x && a < y)\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(A a) {\n" @@ -1339,7 +1328,7 @@ private: " y.f();\n" " if (a > x && a < y)\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3] -> [test.cpp:5]: (warning) Logical conjunction always evaluates to false: a > x && a < y.\n", errout.str()); } @@ -1348,13 +1337,13 @@ private: check("void f(const int &v) {\n" " const int x=v;\n" " if ((v == 1) && (x == 2)) {;}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Logical conjunction always evaluates to false: v == 1 && x == 2.\n", errout.str()); check("void f2(const int *v) {\n" " const int *x=v;\n" " if ((*v == 1) && (*x == 2)) {;}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Logical conjunction always evaluates to false: *(v) == 1 && *(x) == 2.\n", errout.str()); } @@ -1561,7 +1550,7 @@ private: " if (f && g)\n" " ;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1592,29 +1581,25 @@ private: check("void f(int x) {\n" " if (x > 5 && x != 1)\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x > 5', the comparison 'x != 1' is always true.\n", errout.str()); check("void f(int x) {\n" " if (x > 5 && x != 6)\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x) {\n" " if ((x > 5) && (x != 1))\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: If 'x > 5', the comparison 'x != 1' is always true.\n", errout.str()); check("void f(int x) {\n" " if ((x > 5) && (x != 6))\n" " a++;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x, bool& b) {\n" @@ -1991,7 +1976,7 @@ private: check("int * f(int * x, int * y) {\n" " if(!x) return x;\n" " return y;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2088,7 +2073,7 @@ private: " if(!var){}\n" " else {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // daca hyphy @@ -2298,34 +2283,34 @@ private: } void oppositeInnerCondition3() { - check("void f3(char c) { if(c=='x') if(c=='y') {}} "); + check("void f3(char c) { if(c=='x') if(c=='y') {}}"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); - check("void f4(char *p) { if(*p=='x') if(*p=='y') {}} "); + check("void f4(char *p) { if(*p=='x') if(*p=='y') {}}"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); - check("void f5(const char * const p) { if(*p=='x') if(*p=='y') {}} "); + check("void f5(const char * const p) { if(*p=='x') if(*p=='y') {}}"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); - check("void f5(const char * const p) { if('x'==*p) if('y'==*p) {}} "); + check("void f5(const char * const p) { if('x'==*p) if('y'==*p) {}}"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); - check("void f6(char * const p) { if(*p=='x') if(*p=='y') {}} "); + check("void f6(char * const p) { if(*p=='x') if(*p=='y') {}}"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); - check("void f7(const char * p) { if(*p=='x') if(*p=='y') {}} "); + check("void f7(const char * p) { if(*p=='x') if(*p=='y') {}}"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); - check("void f8(int i) { if(i==4) if(i==2) {}} "); + check("void f8(int i) { if(i==4) if(i==2) {}}"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); - check("void f9(int *p) { if (*p==4) if(*p==2) {}} "); + check("void f9(int *p) { if (*p==4) if(*p==2) {}}"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); - check("void f10(int * const p) { if (*p==4) if(*p==2) {}} "); + check("void f10(int * const p) { if (*p==4) if(*p==2) {}}"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); - check("void f11(const int *p) { if (*p==4) if(*p==2) {}} "); + check("void f11(const int *p) { if (*p==4) if(*p==2) {}}"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); check("void f12(const int * const p) { if (*p==4) if(*p==2) {}}"); @@ -2335,17 +2320,17 @@ private: " int a;\n" " int b;\n" "};\n" - "void f(foo x) { if(x.a==4) if(x.b==2) {}} "); + "void f(foo x) { if(x.a==4) if(x.b==2) {}}"); ASSERT_EQUALS("", errout.str()); check("struct foo {\n" " int a;\n" " int b;\n" "};\n" - "void f(foo x) { if(x.a==4) if(x.b==4) {}} "); + "void f(foo x) { if(x.a==4) if(x.b==4) {}}"); ASSERT_EQUALS("", errout.str()); - check("void f3(char a, char b) { if(a==b) if(a==0) {}} "); + check("void f3(char a, char b) { if(a==b) if(a==0) {}}"); ASSERT_EQUALS("", errout.str()); check("void f(int x) { if (x == 1) if (x != 1) {} }"); @@ -2368,57 +2353,57 @@ private: } void oppositeInnerConditionEmpty() { - check("void f1(const std::string &s) { if(s.size() > 42) if(s.empty()) {}} "); + check("void f1(const std::string &s) { if(s.size() > 42) if(s.empty()) {}}"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); - check("void f1(const std::string &s) { if(s.size() > 0) if(s.empty()) {}} "); + check("void f1(const std::string &s) { if(s.size() > 0) if(s.empty()) {}}"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); - check("void f1(const std::string &s) { if(s.size() < 0) if(s.empty()) {}} "); + check("void f1(const std::string &s) { if(s.size() < 0) if(s.empty()) {}}"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); - check("void f1(const std::string &s) { if(s.empty()) if(s.size() > 42) {}} "); + check("void f1(const std::string &s) { if(s.empty()) if(s.size() > 42) {}}"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); - check("template void f1(const T &s) { if(s.size() > 42) if(s.empty()) {}} "); + check("template void f1(const T &s) { if(s.size() > 42) if(s.empty()) {}}"); ASSERT_EQUALS("", errout.str()); //We don't know the type of T so we don't know the relationship between size() and empty(). e.g. s might be a 50 tonne truck with nothing in it. - check("void f2(const std::wstring &s) { if(s.empty()) if(s.size() > 42) {}} "); + check("void f2(const std::wstring &s) { if(s.empty()) if(s.size() > 42) {}}"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); - check("void f1(QString s) { if(s.isEmpty()) if(s.length() > 42) {}} "); + check("void f1(QString s) { if(s.isEmpty()) if(s.length() > 42) {}}"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (warning) Opposite inner 'if' condition leads to a dead code block.\n", errout.str()); - check("void f1(const std::string &s, bool b) { if(s.empty() || ((s.size() == 1) && b)) {}} "); + check("void f1(const std::string &s, bool b) { if(s.empty() || ((s.size() == 1) && b)) {}}"); ASSERT_EQUALS("", errout.str()); - check("void f1(const std::string &x, const std::string &y) { if(x.size() > 42) if(y.empty()) {}} "); + check("void f1(const std::string &x, const std::string &y) { if(x.size() > 42) if(y.empty()) {}}"); ASSERT_EQUALS("", errout.str()); - check("void f1(const std::string &x, const std::string &y) { if(y.empty()) if(x.size() > 42) {}} "); + check("void f1(const std::string &x, const std::string &y) { if(y.empty()) if(x.size() > 42) {}}"); ASSERT_EQUALS("", errout.str()); - check("void f1(const std::string v[10]) { if(v[0].size() > 42) if(v[1].empty()) {}} "); + check("void f1(const std::string v[10]) { if(v[0].size() > 42) if(v[1].empty()) {}}"); ASSERT_EQUALS("", errout.str()); - check("void f1(const std::string &s) { if(s.size() <= 1) if(s.empty()) {}} "); + check("void f1(const std::string &s) { if(s.size() <= 1) if(s.empty()) {}}"); ASSERT_EQUALS("", errout.str()); - check("void f1(const std::string &s) { if(s.size() <= 2) if(s.empty()) {}} "); + check("void f1(const std::string &s) { if(s.size() <= 2) if(s.empty()) {}}"); ASSERT_EQUALS("", errout.str()); - check("void f1(const std::string &s) { if(s.size() < 2) if(s.empty()) {}} "); + check("void f1(const std::string &s) { if(s.size() < 2) if(s.empty()) {}}"); ASSERT_EQUALS("", errout.str()); - check("void f1(const std::string &s) { if(s.size() >= 0) if(s.empty()) {}} "); + check("void f1(const std::string &s) { if(s.size() >= 0) if(s.empty()) {}}"); ASSERT_EQUALS("", errout.str()); // TODO: These are identical condition since size cannot be negative - check("void f1(const std::string &s) { if(s.size() <= 0) if(s.empty()) {}} "); + check("void f1(const std::string &s) { if(s.size() <= 0) if(s.empty()) {}}"); ASSERT_EQUALS("", errout.str()); // TODO: These are identical condition since size cannot be negative - check("void f1(const std::string &s) { if(s.size() < 1) if(s.empty()) {}} "); + check("void f1(const std::string &s) { if(s.size() < 1) if(s.empty()) {}}"); ASSERT_EQUALS("", errout.str()); } @@ -2464,38 +2449,38 @@ private: " if(a) {}\n" " else {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Identical inner 'if' condition is always true.\n", errout.str()); check("bool f(int a, int b) {\n" " if(a == b) { return a == b; }\n" " return false;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (warning) Identical inner 'return' condition is always true.\n", errout.str()); check("bool f(bool a) {\n" " if(a) { return a; }\n" " return false;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int* f(int* a, int * b) {\n" " if(a) { return a; }\n" " return b;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int* f(std::shared_ptr a, std::shared_ptr b) {\n" " if(a.get()) { return a.get(); }\n" " return b.get();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A { int * x; };\n" "int* f(A a, int * b) {\n" " if(a.x) { return a.x; }\n" " return b;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" @@ -2507,7 +2492,7 @@ private: " get_value (&value);\n" " if ((value >> 28) & 1) {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2570,7 +2555,7 @@ private: " return;\n" " coreTree.dostuff();\n" " if(!coreTree.build()) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct C { void f(const Tree &coreTree); };\n" @@ -2579,7 +2564,7 @@ private: " return;\n" " coreTree.dostuff();\n" " if(!coreTree.build()) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (warning) Identical condition '!coreTree.build()', second condition is always false\n", errout.str()); check("void f(int x) {\n" // daca: labplot @@ -2617,7 +2602,7 @@ private: " if (ch != '|') return;\n" " in >> ch;\n" " if (ch != '|') {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #8924 @@ -2627,8 +2612,8 @@ private: " this->FileIndex = 1 ;\n" " if (this->FileIndex < 0) return;\n" " }\n" - " int FileIndex; \n" - "};\n"); + " int FileIndex;\n" + "};"); ASSERT_EQUALS("", errout.str()); // #8858 - #if @@ -2711,31 +2696,31 @@ private: check("void f(const Token *tok) {\n" - " if (!tok->next()->function() || \n" + " if (!tok->next()->function() ||\n" " (tok->next()->function() && tok->next()->function()->isConstructor()));\n" "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: tok->next()->function(). '!A || (A && B)' is equivalent to '!A || B'\n", errout.str()); check("void f() {\n" - " if (!tok->next()->function() || \n" + " if (!tok->next()->function() ||\n" " (!tok->next()->function() && tok->next()->function()->isConstructor()));\n" "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" - " if (!tok->next()->function() || \n" + " if (!tok->next()->function() ||\n" " (!tok2->next()->function() && tok->next()->function()->isConstructor()));\n" "}"); ASSERT_EQUALS("", errout.str()); check("void f(const Token *tok) {\n" - " if (!tok->next(1)->function(1) || \n" + " if (!tok->next(1)->function(1) ||\n" " (tok->next(1)->function(1) && tok->next(1)->function(1)->isConstructor()));\n" "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: tok->next(1)->function(1). '!A || (A && B)' is equivalent to '!A || B'\n", errout.str()); check("void f() {\n" - " if (!tok->next()->function(1) || \n" + " if (!tok->next()->function(1) ||\n" " (tok->next()->function(2) && tok->next()->function()->isConstructor()));\n" "}"); ASSERT_EQUALS("", errout.str()); @@ -2764,12 +2749,12 @@ private: check("void f(bool a, bool b) {\n" " if (a || (a && b)) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: a. 'a || (a && b)' is equivalent to 'a'\n", errout.str()); check("void f(bool a, bool b) {\n" " if (a && (a || b)) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Redundant condition: a. 'a && (a || b)' is equivalent to 'a'\n", errout.str()); } @@ -2933,7 +2918,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style) Condition '!x' is always true\n", errout.str()); check("bool f(int x) {\n" - " if(x == 0) { x++; return x == 0; } \n" + " if(x == 0) { x++; return x == 0; }\n" " return false;\n" "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Condition 'x==0' is always false\n", errout.str()); @@ -2955,65 +2940,65 @@ private: "}"); ASSERT_EQUALS("", errout.str()); - check("void f1(const std::string &s) { if(s.empty()) if(s.size() == 0) {}} "); + check("void f1(const std::string &s) { if(s.empty()) if(s.size() == 0) {}}"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (style) Condition 's.size()==0' is always true\n", errout.str()); check("void f() {\n" " int buf[42];\n" " if( buf != 0) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'buf!=0' is always true\n", errout.str()); // #8924 check("void f() {\n" " int buf[42];\n" " if( !buf ) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Condition '!buf' is always false\n", errout.str()); check("void f() {\n" " int buf[42];\n" " bool b = buf;\n" " if( b ) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Condition 'b' is always true\n", errout.str()); check("void f() {\n" " int buf[42];\n" " bool b = buf;\n" " if( !b ) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Condition '!b' is always false\n", errout.str()); check("void f() {\n" " int buf[42];\n" " int * p = nullptr;\n" " if( buf == p ) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Condition 'buf==p' is always false\n", errout.str()); check("void f(bool x) {\n" " int buf[42];\n" " if( buf || x ) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'buf' is always true\n", errout.str()); check("void f(int * p) {\n" " int buf[42];\n" " if( buf == p ) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" " int buf[42];\n" " int p[42];\n" " if( buf == p ) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" " int buf[42];\n" " if( buf == 1) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Avoid FP when condition comes from macro @@ -3067,7 +3052,7 @@ private: " if (b) {\n" " if (bar(!b)) {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); @@ -3082,7 +3067,7 @@ private: " assert((int)(0==0));\n" " assert((int)(0==0) && \"bla\");\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #7750 char literals in boolean expressions @@ -3119,36 +3104,36 @@ private: " else if (!b && i == 1) {}\n" " if (b)\n" " {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Condition '!b' is always true\n", errout.str()); check("bool f() { return nullptr; }"); ASSERT_EQUALS("", errout.str()); check("enum E { A };\n" - "bool f() { return A; }\n"); + "bool f() { return A; }"); ASSERT_EQUALS("", errout.str()); - check("bool f() { \n" + check("bool f() {\n" " const int x = 0;\n" - " return x; \n" - "}\n"); + " return x;\n" + "}"); ASSERT_EQUALS("", errout.str()); check("int f(void){return 1/abs(10);}"); ASSERT_EQUALS("", errout.str()); - check("bool f() { \n" + check("bool f() {\n" " int x = 0;\n" - " return x; \n" - "}\n"); + " return x;\n" + "}"); ASSERT_EQUALS("", errout.str()); check("bool f() {\n" " const int a = 50;\n" " const int b = 52;\n" " return a+b;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int f() {\n" @@ -3157,7 +3142,7 @@ private: " a++;\n" " b++;\n" " return a+b;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("bool& g();\n" @@ -3165,7 +3150,7 @@ private: " bool & b = g();\n" " b = false;\n" " return b;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A {\n" @@ -3174,13 +3159,13 @@ private: " b = false;\n" " return b;\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); check("bool f(long maxtime) {\n" " if (std::time(0) > maxtime)\n" " return std::time(0) > maxtime;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(double param) {\n" @@ -3190,7 +3175,7 @@ private: " }\n" " if (param<0.)\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(int i) {\n" @@ -3200,7 +3185,7 @@ private: " }\n" " if (cond && (42==i))\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // 8842 crash @@ -3210,12 +3195,12 @@ private: " void f() {\n" " if (b) return;\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); check("void f(const char* x, const char* t) {\n" " if (!(strcmp(x, y) == 0)) { return; }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(const int a[]){ if (a == 0){} }"); @@ -3229,7 +3214,7 @@ private: " bool c = s [test.cpp:3]: (style) Condition 'handle' is always true\n", errout.str()); check("int f(void *handle) {\n" " if (handle == 0) return 0;\n" " if (handle) return 1;\n" " else return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Condition 'handle' is always true\n", errout.str()); check("int f(void *handle) {\n" " if (handle != 0) return 0;\n" " if (handle) return 1;\n" " else return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Identical condition 'handle!=0', second condition is always false\n", errout.str()); check("void f(void* x, void* y) {\n" @@ -3267,7 +3252,7 @@ private: " return;\n" " if (x == nullptr || y == nullptr)\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void* g();\n" @@ -3278,7 +3263,7 @@ private: " break;\n" " }\n" " if (a) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void* g();\n" @@ -3287,26 +3272,26 @@ private: " a = g();\n" " }\n" " if (a) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) Condition 'a' is always false\n", errout.str()); check("void f(int * x, bool b) {\n" " if (!x && b) {}\n" " else if (x) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" " const std::string x=\"xyz\";\n" " if(!x.empty()){}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Condition '!x.empty()' is always true\n", errout.str()); check("std::string g();\n" "void f() {\n" " const std::string msg = g();\n" " if(!msg.empty()){}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int *array, int size ) {\n" @@ -3315,7 +3300,7 @@ private: " continue;\n" " if(array){}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style) Condition 'array' is always true\n", errout.str()); check("void f(int *array, int size ) {\n" @@ -3324,7 +3309,7 @@ private: " continue;\n" " else if(array){}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style) Condition 'array' is always true\n", errout.str()); // #9277 @@ -3334,7 +3319,7 @@ private: " return 0;\n" " else\n" " return 1;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9319 @@ -3347,7 +3332,7 @@ private: " bool x = false;\n" " g({0, 1}, x);\n" " if (x) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9318 @@ -3358,7 +3343,7 @@ private: " return;\n" " auto b = dynamic_cast(x);\n" " if (b) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int foo() {\n" @@ -3376,7 +3361,7 @@ private: check("bool g();\n" "void f(bool x) {\n" " if (x) while(x) x = g();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // isLikelyStream @@ -3386,7 +3371,7 @@ private: " iss >> x;\n" " if (!iss) break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9332 @@ -3398,14 +3383,14 @@ private: " void* c = a.g();\n" " if (!c) return;\n" " bool compare = c == b;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9361 check("void f(char c) {\n" " if (c == '.') {}\n" " else if (isdigit(c) != 0) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9351 @@ -3413,7 +3398,7 @@ private: " const bool b = x < 42;\n" " if(b) return b?0:-1;\n" " return 42;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (style) Condition 'b' is always true\n", errout.str()); // #9362 @@ -3423,7 +3408,7 @@ private: " if((v != 0x00)) {\n" " if( (v & 0x01) == 0x00) {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9367 @@ -3432,25 +3417,25 @@ private: " return;\n" " if (x % 360L == 0)\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int f(int a, int b) {\n" " static const int x = 10;\n" " return x == 1 ? a : b;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("const bool x = false;\n" "void f() {\n" " if (x) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("const bool x = false;\n" "void f() {\n" " if (!x) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9709 @@ -3461,7 +3446,7 @@ private: " if (r != nullptr)\n" " ok = a != 0;\n" " if (ok) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9816 @@ -3568,7 +3553,7 @@ private: " x++;\n" " if (x == 1) {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Condition 'x==1' is always false\n", errout.str()); check("void f(int x) {\n" @@ -3576,7 +3561,7 @@ private: " x++;\n" " if (x != 1) {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Condition 'x!=1' is always true\n", errout.str()); // #6890 @@ -3584,99 +3569,99 @@ private: " int x = i;\n" " if (x >= 1) {}\n" " else {\n" - " x = 8 - x; \n" + " x = 8 - x;\n" " if (x == -1) {}\n" " else {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) Condition 'x==-1' is always false\n", errout.str()); check("void f(int i) {\n" " int x = i;\n" " if (x >= 1) {}\n" " else {\n" - " x = 8 - x; \n" + " x = 8 - x;\n" " if (x != -1) {}\n" " else {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) Condition 'x!=-1' is always true\n", errout.str()); check("void f(int i) {\n" " int x = i;\n" " if (x >= 1) {}\n" " else {\n" - " x = 8 - x; \n" + " x = 8 - x;\n" " if (x >= -1) {}\n" " else {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) Condition 'x>=-1' is always true\n", errout.str()); check("void f(int i) {\n" " int x = i;\n" " if (x >= 1) {}\n" " else {\n" - " x = 8 - x; \n" + " x = 8 - x;\n" " if (x > -1) {}\n" " else {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) Condition 'x>-1' is always true\n", errout.str()); check("void f(int i) {\n" " int x = i;\n" " if (x >= 1) {}\n" " else {\n" - " x = 8 - x; \n" + " x = 8 - x;\n" " if (x < -1) {}\n" " else {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) Condition 'x<-1' is always false\n", errout.str()); check("void f(int i) {\n" " int x = i;\n" " if (x >= 1) {}\n" " else {\n" - " x = 8 - x; \n" + " x = 8 - x;\n" " if (x <= -1) {}\n" " else {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) Condition 'x<=-1' is always false\n", errout.str()); check("void f(int i) {\n" " int x = i;\n" " if (x >= 1) {}\n" " else {\n" - " x = 8 - x; \n" + " x = 8 - x;\n" " if (x > 7) {}\n" " else {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) Condition 'x>7' is always true\n", errout.str()); check("void f(int i) {\n" " int x = i;\n" " if (x >= 1) {}\n" " else {\n" - " x = 8 - x; \n" + " x = 8 - x;\n" " if (x > 9) {}\n" " else {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int i) {\n" " int x = i;\n" " if (x >= 1) {}\n" " else {\n" - " x = 8 - x; \n" + " x = 8 - x;\n" " if (x > 10) {}\n" " else {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9541 @@ -3687,7 +3672,7 @@ private: " if(pos > 0)\n" " --pos;\n" " return pos;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (style) Condition 'pos>0' is always true\n", errout.str()); // #9721 @@ -3696,7 +3681,7 @@ private: " if ( (x>255) || (-128>x) )\n" " return;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Condition '-128>x' is always false\n", errout.str()); } @@ -3712,7 +3697,7 @@ private: " c2(g );\n" " if ( !g.empty() )\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo(int flag) {\n" @@ -3723,7 +3708,7 @@ private: " c2(g );\n" " if ( !g.empty() )\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A {\n" @@ -3743,7 +3728,7 @@ private: " int val = 0;\n" " if (val < 0) continue;\n" " if (val > 0) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" @@ -3751,7 +3736,7 @@ private: " if (val < 0) {\n" " if (val > 0) {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" @@ -3759,7 +3744,7 @@ private: " if (val < 0) {\n" " if (val < 0) {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" @@ -3767,7 +3752,7 @@ private: " int foo = 0;\n" " if (activate) {}\n" " else if (foo) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Condition 'activate' is always false\n" "[test.cpp:5]: (style) Condition 'foo' is always false\n", errout.str()); @@ -3775,7 +3760,7 @@ private: check("void f() {\n" " const int b[2] = { 1,0 };\n" " if(b[1] == 2) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'b[1]==2' is always false\n", errout.str()); // #9878 @@ -3792,40 +3777,40 @@ private: check("void f(bool x) {\n" " if(x) {}\n" " if(x) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The if condition is the same as the previous if condition\n", errout.str()); check("void f(int x) {\n" " if(x == 1) {}\n" " if(x == 1) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The if condition is the same as the previous if condition\n", errout.str()); check("void f(int x) {\n" " if(x == 1) {}\n" " if(x == 2) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x) {\n" " if(x == 1) {}\n" " if(x != 1) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(bool x) {\n" " if(x) {}\n" " g();\n" " if(x) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int x) {\n" " if(x == 1) { x++; }\n" " if(x == 1) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #8996 @@ -3837,7 +3822,7 @@ private: " g(d);\n" " if (a) {}\n" " if (b) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9311 @@ -3852,7 +3837,7 @@ private: " g(d);\n" " if (a) {}\n" " if (b) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #8993 @@ -3860,7 +3845,7 @@ private: " auto y = x;\n" " if (x.empty()) y = \"1\";\n" " if (y.empty()) return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9106 @@ -3868,7 +3853,7 @@ private: "void f(A a, int c) {\n" " if (a.b) a.b = c;\n" " if (a.b) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A {\n" @@ -4069,31 +4054,31 @@ private: void alwaysTrueFalseInLogicalOperators() { check("bool f();\n" - "void foo() { bool x = true; if(x||f()) {}}\n"); + "void foo() { bool x = true; if(x||f()) {}}"); ASSERT_EQUALS("[test.cpp:2]: (style) Condition 'x' is always true\n", errout.str()); - check("void foo(bool b) { bool x = true; if(x||b) {}}\n"); + check("void foo(bool b) { bool x = true; if(x||b) {}}"); ASSERT_EQUALS("[test.cpp:1]: (style) Condition 'x' is always true\n", errout.str()); - check("void foo(bool b) { if(true||b) {}}\n"); + check("void foo(bool b) { if(true||b) {}}"); ASSERT_EQUALS("", errout.str()); check("bool f();\n" - "void foo() { bool x = false; if(x||f()) {}}\n"); + "void foo() { bool x = false; if(x||f()) {}}"); ASSERT_EQUALS("[test.cpp:2]: (style) Condition 'x' is always false\n", errout.str()); check("bool f();\n" - "void foo() { bool x = false; if(x&&f()) {}}\n"); + "void foo() { bool x = false; if(x&&f()) {}}"); ASSERT_EQUALS("[test.cpp:2]: (style) Condition 'x' is always false\n", errout.str()); - check("void foo(bool b) { bool x = false; if(x&&b) {}}\n"); + check("void foo(bool b) { bool x = false; if(x&&b) {}}"); ASSERT_EQUALS("[test.cpp:1]: (style) Condition 'x' is always false\n", errout.str()); - check("void foo(bool b) { if(false&&b) {}}\n"); + check("void foo(bool b) { if(false&&b) {}}"); ASSERT_EQUALS("", errout.str()); check("bool f();\n" - "void foo() { bool x = true; if(x&&f()) {}}\n"); + "void foo() { bool x = true; if(x&&f()) {}}"); ASSERT_EQUALS("[test.cpp:2]: (style) Condition 'x' is always true\n", errout.str()); // #9578 @@ -4116,7 +4101,7 @@ private: check("void f(int& x, int y) {\n" " if (x == y)\n" " x = y;\n" - "}\n"); + "}"); ASSERT_EQUALS("test.cpp:3:style:Assignment 'x=y' is redundant with condition 'x==y'.\n" "test.cpp:2:note:Condition 'x==y'\n" "test.cpp:3:note:Assignment 'x=y' is redundant\n", errout.str()); @@ -4124,7 +4109,7 @@ private: check("void f(int& x, int y) {\n" " if (x != y)\n" " x = y;\n" - "}\n"); + "}"); ASSERT_EQUALS("test.cpp:2:style:The statement 'if (x!=y) x=y' is logically equivalent to 'x=y'.\n" "test.cpp:3:note:Assignment 'x=y'\n" "test.cpp:2:note:Condition 'x!=y' is redundant\n", errout.str()); @@ -4134,7 +4119,7 @@ private: " x = y;\n" " else\n" " x = 1;\n" - "}\n"); + "}"); ASSERT_EQUALS("test.cpp:3:style:Assignment 'x=y' is redundant with condition 'x==y'.\n" "test.cpp:2:note:Condition 'x==y'\n" "test.cpp:3:note:Assignment 'x=y' is redundant\n", errout.str()); @@ -4144,13 +4129,13 @@ private: " x = y;\n" " else\n" " x = 1;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int& x, int y) {\n" " if (x == y)\n" " x = y + 1;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void g();\n" @@ -4159,7 +4144,7 @@ private: " x = y;\n" " g();\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } }; diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index c3b4a1b40..df1e23ed3 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -442,7 +442,7 @@ private: check("class Fred {\n" " int x=1;\n" " int *y=0;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -455,7 +455,7 @@ private: " {}\n" "private:\n" " int x;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); check("class Fred : public Base {" @@ -466,7 +466,7 @@ private: " {}\n" "private:\n" " int x;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -534,7 +534,7 @@ private: void noConstructor7() { // ticket #4391 check("short bar;\n" - "class foo;\n"); + "class foo;"); ASSERT_EQUALS("", errout.str()); } @@ -542,7 +542,7 @@ private: // ticket #4404 check("class LineSegment;\n" "class PointArray { };\n" - "void* tech_ = NULL;\n"); + "void* tech_ = NULL;"); ASSERT_EQUALS("", errout.str()); } @@ -573,7 +573,7 @@ private: " virtual ~A();\n" "private:\n" " wxTimer *WxTimer1;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -602,15 +602,15 @@ private: // ticket #3190 "SymbolDatabase: Parse of sub class constructor fails" void forwardDeclaration() { check("class foo;\n" - "int bar;\n"); + "int bar;"); ASSERT_EQUALS("", errout.str()); check("class foo;\n" - "class foo;\n"); + "class foo;"); ASSERT_EQUALS("", errout.str()); check("class foo{};\n" - "class foo;\n"); + "class foo;"); ASSERT_EQUALS("", errout.str()); } @@ -1121,7 +1121,7 @@ private: " int foo_;\n" "};\n" "Foo::Foo() : Foo(0) {}\n" - "Foo::Foo(int foo) : foo_(foo) {}\n"); + "Foo::Foo(int foo) : foo_(foo) {}"); ASSERT_EQUALS("", errout.str()); // Noexcept ctors @@ -2277,8 +2277,7 @@ private: "Fred::Fred(struct C c, D d) { }\n" "Fred::Fred(E e, struct F f) { }\n" "Fred::Fred(G g, H h) { }\n" - "Fred::Fred(struct I i, struct J j) { }\n" - ); + "Fred::Fred(struct I i, struct J j) { }"); ASSERT_EQUALS("[test.cpp:10]: (warning) Member variable 'Fred::x' is not initialized in the constructor.\n" "[test.cpp:11]: (warning) Member variable 'Fred::x' is not initialized in the constructor.\n" "[test.cpp:12]: (warning) Member variable 'Fred::x' is not initialized in the constructor.\n" @@ -2323,35 +2322,35 @@ private: " int c;\n" " A(int x = 0, int y = 0, int z = 0);\n" "};\n" - "A::A(int x = 0, int y = 0, int z = 0) { } \n" + "A::A(int x = 0, int y = 0, int z = 0) { }\n" "struct B {\n" " int a;\n" " int b;\n" " int c;\n" " B(int x = 0, int y = 0, int z = 0);\n" "};\n" - "B::B(int x, int y, int z) { } \n" + "B::B(int x, int y, int z) { }\n" "struct C {\n" " int a;\n" " int b;\n" " int c;\n" " C(int, int, int);\n" "};\n" - "C::C(int x = 0, int y = 0, int z = 0) { } \n" + "C::C(int x = 0, int y = 0, int z = 0) { }\n" "struct D {\n" " int a;\n" " int b;\n" " int c;\n" " D(int, int, int);\n" "};\n" - "D::D(int x, int y, int z) { } \n" + "D::D(int x, int y, int z) { }\n" "struct E {\n" " int a;\n" " int b;\n" " int c;\n" " E(int x, int y, int z);\n" "};\n" - "E::E(int, int, int) { } \n" + "E::E(int, int, int) { }\n" "struct F {\n" " int a;\n" " int b;\n" @@ -2470,7 +2469,7 @@ private: "}\n" "using namespace NS;\n" "MyClass::~MyClass() { }\n" - "MyClass::MyClass() : SomeVar(false) { }\n"); + "MyClass::MyClass() : SomeVar(false) { }"); ASSERT_EQUALS("", errout.str()); } @@ -2488,7 +2487,7 @@ private: "}\n" "void MyClass::Restart() {\n" " m_retCode = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2501,7 +2500,7 @@ private: " {\n" " if (1) {}\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Foo::member' is not initialized in the constructor.\n", errout.str()); check("class Foo {\n" " friend class Bar;\n" @@ -2511,7 +2510,7 @@ private: " {\n" " while (1) {}\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Foo::member' is not initialized in the constructor.\n", errout.str()); check("class Foo {\n" " friend class Bar;\n" @@ -2521,7 +2520,7 @@ private: " {\n" " for (;;) {}\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Foo::member' is not initialized in the constructor.\n", errout.str()); } @@ -3535,7 +3534,7 @@ private: "public:\n" " C() _STLP_NOTHROW {}\n" " C(const C&) _STLP_NOTHROW {}\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -3890,7 +3889,7 @@ private: "class C {\n" " private:\n" " A* b;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); check("template class A{};\n" @@ -3902,7 +3901,7 @@ private: " bool m_value;\n" "};\n" "template\n" - "A>::A() : m_value(false) {}\n"); + "A>::A() : m_value(false) {}"); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testexceptionsafety.cpp b/test/testexceptionsafety.cpp index 9e5519bf7..60c30eaa4 100644 --- a/test/testexceptionsafety.cpp +++ b/test/testexceptionsafety.cpp @@ -326,13 +326,13 @@ private: "void func3() noexcept(true) { throw 1; }\n" "void func4() noexcept(false) { throw 1; }\n" "void func5() noexcept(true) { func1(); }\n" - "void func6() noexcept(false) { func1(); }\n"); + "void func6() noexcept(false) { func1(); }"); ASSERT_EQUALS("[test.cpp:2]: (error) Exception thrown in function declared not to throw exceptions.\n" "[test.cpp:3]: (error) Exception thrown in function declared not to throw exceptions.\n" "[test.cpp:5]: (error) Exception thrown in function declared not to throw exceptions.\n", errout.str()); // avoid false positives - check("const char *func() noexcept { return 0; }\n"); + check("const char *func() noexcept { return 0; }"); ASSERT_EQUALS("", errout.str()); } @@ -341,12 +341,12 @@ private: "void func2() throw() { throw 1; }\n" "void func3() throw(int) { throw 1; }\n" "void func4() throw() { func1(); }\n" - "void func5() throw(int) { func1(); }\n"); + "void func5() throw(int) { func1(); }"); ASSERT_EQUALS("[test.cpp:2]: (error) Exception thrown in function declared not to throw exceptions.\n" "[test.cpp:4]: (error) Exception thrown in function declared not to throw exceptions.\n", errout.str()); // avoid false positives - check("const char *func() throw() { return 0; }\n"); + check("const char *func() throw() { return 0; }"); ASSERT_EQUALS("", errout.str()); } @@ -377,12 +377,12 @@ private: void nothrowAttributeThrow() { check("void func1() throw(int) { throw 1; }\n" "void func2() __attribute((nothrow)); void func2() { throw 1; }\n" - "void func3() __attribute((nothrow)); void func3() { func1(); }\n"); + "void func3() __attribute((nothrow)); void func3() { func1(); }"); ASSERT_EQUALS("[test.cpp:2]: (error) Exception thrown in function declared not to throw exceptions.\n" "[test.cpp:3]: (error) Exception thrown in function declared not to throw exceptions.\n", errout.str()); // avoid false positives - check("const char *func() __attribute((nothrow)); void func1() { return 0; }\n"); + check("const char *func() __attribute((nothrow)); void func1() { return 0; }"); ASSERT_EQUALS("", errout.str()); } @@ -391,19 +391,19 @@ private: " void copyMemberValues() throw () {\n" " copyMemberValues();\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } void nothrowDeclspecThrow() { check("void func1() throw(int) { throw 1; }\n" "void __declspec(nothrow) func2() { throw 1; }\n" - "void __declspec(nothrow) func3() { func1(); }\n"); + "void __declspec(nothrow) func3() { func1(); }"); ASSERT_EQUALS("[test.cpp:2]: (error) Exception thrown in function declared not to throw exceptions.\n" "[test.cpp:3]: (error) Exception thrown in function declared not to throw exceptions.\n", errout.str()); // avoid false positives - check("const char *func() __attribute((nothrow)); void func1() { return 0; }\n"); + check("const char *func() __attribute((nothrow)); void func1() { return 0; }"); ASSERT_EQUALS("", errout.str()); } }; diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index ad42c5356..c338aabb9 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -518,7 +518,7 @@ private: " size_t l1 = strlen(&s1.x);\n" " size_t l2 = strlen(&s2.x);\n" " return l1 + l2;\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:9]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", "", errout.str()); check("const char x = 'x'; size_t f() { return strlen(&x); }"); @@ -537,13 +537,13 @@ private: " char * a = \"Hello world\";\n" " char ** b = &a;\n" " return strlen(&b[0][0]);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("size_t f() {\n" " char ca[] = \"asdf\";\n" " return strlen((char*) &ca);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #5225 @@ -554,7 +554,7 @@ private: " strcat(str, &d);\n" " puts(str);\n" " return 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Invalid strcat() argument nr 2. A nul-terminated string is required.\n", errout.str()); } @@ -847,36 +847,36 @@ private: // acos, acosf, acosl check("void foo()\n" "{\n" - " return acos(-1) \n" - " + acos(0.1) \n" - " + acos(0.0001) \n" - " + acos(0.01) \n" - " + acos(1.0E-1) \n" - " + acos(-1.0E-1) \n" - " + acos(+1.0E-1) \n" - " + acos(0.1E-1) \n" - " + acos(+0.1E-1) \n" - " + acos(-0.1E-1) \n" - " + acosf(-1) \n" - " + acosf(0.1) \n" - " + acosf(0.0001) \n" - " + acosf(0.01) \n" - " + acosf(1.0E-1) \n" - " + acosf(-1.0E-1) \n" - " + acosf(+1.0E-1) \n" - " + acosf(0.1E-1) \n" - " + acosf(+0.1E-1) \n" - " + acosf(-0.1E-1) \n" - " + acosl(-1) \n" - " + acosl(0.1) \n" - " + acosl(0.0001) \n" - " + acosl(0.01) \n" - " + acosl(1.0E-1) \n" - " + acosl(-1.0E-1) \n" - " + acosl(+1.0E-1) \n" - " + acosl(0.1E-1) \n" - " + acosl(+0.1E-1) \n" - " + acosl(-0.1E-1); \n" + " return acos(-1) \n" + " + acos(0.1) \n" + " + acos(0.0001) \n" + " + acos(0.01) \n" + " + acos(1.0E-1) \n" + " + acos(-1.0E-1) \n" + " + acos(+1.0E-1) \n" + " + acos(0.1E-1) \n" + " + acos(+0.1E-1) \n" + " + acos(-0.1E-1) \n" + " + acosf(-1) \n" + " + acosf(0.1) \n" + " + acosf(0.0001) \n" + " + acosf(0.01) \n" + " + acosf(1.0E-1) \n" + " + acosf(-1.0E-1) \n" + " + acosf(+1.0E-1) \n" + " + acosf(0.1E-1) \n" + " + acosf(+0.1E-1) \n" + " + acosf(-0.1E-1) \n" + " + acosl(-1) \n" + " + acosl(0.1) \n" + " + acosl(0.0001) \n" + " + acosl(0.01) \n" + " + acosl(1.0E-1) \n" + " + acosl(-1.0E-1) \n" + " + acosl(+1.0E-1) \n" + " + acosl(0.1E-1) \n" + " + acosl(+0.1E-1) \n" + " + acosl(-0.1E-1);\n" "}"); ASSERT_EQUALS("", errout.str()); @@ -905,39 +905,39 @@ private: // asin, asinf, asinl check("void foo()\n" "{\n" - " return asin(1) \n" - " + asin(-1) \n" - " + asin(0.1) \n" - " + asin(0.0001) \n" - " + asin(0.01) \n" - " + asin(1.0E-1) \n" - " + asin(-1.0E-1) \n" - " + asin(+1.0E-1) \n" - " + asin(0.1E-1) \n" - " + asin(+0.1E-1) \n" - " + asin(-0.1E-1) \n" - " + asinf(1) \n" - " + asinf(-1) \n" - " + asinf(0.1) \n" - " + asinf(0.0001) \n" - " + asinf(0.01) \n" - " + asinf(1.0E-1) \n" - " + asinf(-1.0E-1) \n" - " + asinf(+1.0E-1) \n" - " + asinf(0.1E-1) \n" - " + asinf(+0.1E-1) \n" - " + asinf(-0.1E-1) \n" - " + asinl(1) \n" - " + asinl(-1) \n" - " + asinl(0.1) \n" - " + asinl(0.0001) \n" - " + asinl(0.01) \n" - " + asinl(1.0E-1) \n" - " + asinl(-1.0E-1) \n" - " + asinl(+1.0E-1) \n" - " + asinl(0.1E-1) \n" - " + asinl(+0.1E-1) \n" - " + asinl(-0.1E-1); \n" + " return asin(1) \n" + " + asin(-1) \n" + " + asin(0.1) \n" + " + asin(0.0001) \n" + " + asin(0.01) \n" + " + asin(1.0E-1) \n" + " + asin(-1.0E-1) \n" + " + asin(+1.0E-1) \n" + " + asin(0.1E-1) \n" + " + asin(+0.1E-1) \n" + " + asin(-0.1E-1) \n" + " + asinf(1) \n" + " + asinf(-1) \n" + " + asinf(0.1) \n" + " + asinf(0.0001) \n" + " + asinf(0.01) \n" + " + asinf(1.0E-1) \n" + " + asinf(-1.0E-1) \n" + " + asinf(+1.0E-1) \n" + " + asinf(0.1E-1) \n" + " + asinf(+0.1E-1) \n" + " + asinf(-0.1E-1) \n" + " + asinl(1) \n" + " + asinl(-1) \n" + " + asinl(0.1) \n" + " + asinl(0.0001) \n" + " + asinl(0.01) \n" + " + asinl(1.0E-1) \n" + " + asinl(-1.0E-1) \n" + " + asinl(+1.0E-1) \n" + " + asinl(0.1E-1) \n" + " + asinl(+0.1E-1) \n" + " + asinl(-0.1E-1);\n" "}"); ASSERT_EQUALS("", errout.str()); @@ -1221,7 +1221,7 @@ private: check("template uint8_t b(std::tuple d) {\n" " std::tuple c{std::move(d)};\n" " return std::get<0>(c);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A { int x; };\n" @@ -1229,7 +1229,7 @@ private: "A f(int x, Ts... xs) {\n" " return {std::move(x), static_cast(xs)...};\n" "}\n" - "A g() { return f(1); }\n"); + "A g() { return f(1); }"); ASSERT_EQUALS("", errout.str()); } @@ -1257,17 +1257,17 @@ private: void memsetZeroBytes() { check("void f() {\n" " memset(p, 10, 0x0);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0 bytes.\n", errout.str()); check("void f() {\n" " memset(p, sizeof(p), 0);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0 bytes.\n", errout.str()); check("void f() {\n" " memset(p, sizeof(p), i);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #6269 false positives in case of overloaded standard library functions @@ -1282,7 +1282,7 @@ private: // #7285 check("void f() {\n" " memset(&tm, sizeof(tm), 0);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0 bytes.\n", errout.str()); } @@ -1293,7 +1293,7 @@ private: " memset(is, 1.0f, 40);\n" " int* is2 = new int[10];\n" " memset(is2, 0.1f, 40);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (portability) The 2nd memset() argument '1.0f' is a float, its representation is implementation defined.\n" "[test.cpp:5]: (portability) The 2nd memset() argument '0.1f' is a float, its representation is implementation defined.\n", errout.str()); @@ -1301,19 +1301,19 @@ private: " int* is = new int[10];\n" " float g = computeG();\n" " memset(is, g, 40);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (portability) The 2nd memset() argument 'g' is a float, its representation is implementation defined.\n", errout.str()); check("void f() {\n" " int* is = new int[10];\n" " memset(is, 0.0f, 40);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" // FP " float x = 2.3f;\n" " memset(a, (x?64:0), 40);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" @@ -1321,7 +1321,7 @@ private: " memset(ss, 256, 4);\n" " short ss2[2];\n" " memset(ss2, -129, 4);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) The 2nd memset() argument '256' doesn't fit into an 'unsigned char'.\n" "[test.cpp:5]: (warning) The 2nd memset() argument '-129' doesn't fit into an 'unsigned char'.\n", errout.str()); @@ -1336,14 +1336,14 @@ private: " memset(cs2, 255, 30);\n" " char cs3[30];\n" " memset(cs3, 0, 30);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" " int is[10];\n" " const int i = g();\n" " memset(is, 1.0f + i, 40);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (portability) The 2nd memset() argument '1.0f+i' is a float, its representation is implementation defined.\n", errout.str()); } }; diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index ced1b7671..a1d19742a 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -466,7 +466,7 @@ private: TODO_ASSERT_THROW(checkCode("int ScopedEnum{ template { { e = T::error }; };\n" "ScopedEnum1 se1; { enum class E : T { e = 0 = e ScopedEnum2 struct UnscopedEnum3 { T{ e = 4 }; };\n" "arr[(int) E::e]; }; UnscopedEnum3 e2 = f()\n" - "{ { e = e1; T::error } int test1 ue2; g() { enum class E { e = T::error }; return E::e; } int test2 = } \n" + "{ { e = e1; T::error } int test1 ue2; g() { enum class E { e = T::error }; return E::e; } int test2 = }\n" "namespace UnscopedEnum { template struct UnscopedEnum1 { E{ e = T::error }; }; UnscopedEnum1 { enum E : { e = 0 }; };\n" "UnscopedEnum2 ue3; template struct UnscopedEnum3 { enum { }; }; int arr[E::e]; };\n" "UnscopedEnum3 namespace template int f() { enum E { e }; T::error }; return (int) E(); } int test1 int g() { enum E { e = E };\n" @@ -582,7 +582,7 @@ private: checkCode("struct R1 {\n" " int a;\n" " R1 () : a { }\n" - "};\n"); + "};"); } void garbageCode30() { @@ -847,7 +847,7 @@ private: void garbageCode99() { // #6726 ASSERT_THROW(checkCode("{ xs :: i(:) ! ! x/5 ! !\n" - "i, :: a :: b integer, } foo2(x) :: j(:) \n" + "i, :: a :: b integer, } foo2(x) :: j(:)\n" "b type(*), d(:), a x :: end d(..), foo end\n" "foo4 b d(..), a a x type(*), b foo2 b"), InternalError); } @@ -929,7 +929,7 @@ private: void garbageCode118() { // #5600 - missing include causes invalid enum ASSERT_THROW(checkCode("enum {\n" - " NUM_OPCODES = \n" + " NUM_OPCODES =\n" // #include "definition" "};\n" "struct bytecode {};\n" @@ -989,7 +989,7 @@ private: " ~A() { printf(\"A d'tor\\n\"); }\n" "};\n" " const A& foo(const A& arg) { return arg; }\n" - " foo(A(12)).Var\n"); + " foo(A(12)).Var"); } void garbageCode128() { @@ -1077,7 +1077,7 @@ private: checkCode("struct S { int i, j; }; " "template struct X {}; " "X<&S::i, int> x = X<&S::i, int>(); " - "X<&S::j, int> y = X<&S::j, int>(); "); + "X<&S::j, int> y = X<&S::j, int>();"); checkCode("template struct A {}; " "template <> struct A {}; " "void foo(const void* f = 0) {}"); @@ -1240,13 +1240,13 @@ private: void garbageCode157() { // #7131 ASSERT_THROW(checkCode("namespace std {\n" " template < typename >\n" - " void swap(); \n" + " void swap();\n" "}" "template std::swap\n"), InternalError); } void garbageCode158() { // #3238 - checkCode("__FBSDID(\"...\");\n"); + checkCode("__FBSDID(\"...\");"); } void garbageCode159() { // #7119 @@ -1292,7 +1292,7 @@ private: checkCode("YY_DECL { switch (yy_act) {\n" " case 65: YY_BREAK\n" " case YY_STATE_EOF(block):\n" - " yyterminate(); \n" + " yyterminate();\n" "} }"); // #5663 } @@ -1312,13 +1312,13 @@ private: void templateSimplifierCrashes() { checkCode( // #5950 - "struct A { \n" + "struct A {\n" " template operator T*();\n" - "}; \n" + "};\n" "\n" "template <> A::operator char*(){ return 0; } // specialization\n" "\n" - "int main() { \n" + "int main() {\n" " A a;\n" " int *ip = a.operator int*();\n" "}\n" @@ -1331,7 +1331,7 @@ private: " void f() {\n" " s.operator A >();\n" " }\n" - "}\n"); + "}"); checkCode( // #6034 "template class T, typename... Args>\n" @@ -1345,8 +1345,7 @@ private: "\n" "int main() {\n" " foo >::value;\n" - "}\n" - ); + "}"); checkCode( // #6117 "template struct something_like_tuple\n" @@ -1364,19 +1363,17 @@ private: "\n" "typedef something_like_tuple something_like_tuple_t;\n" "SA ((is_last::value == false));\n" - "SA ((is_last::value == false));\n" - ); + "SA ((is_last::value == false));"); checkCode( // #6225 "template \n" "void templ_fun_with_ty_pack() {}\n" - " \n" + "\n" "namespace PR20047 {\n" " template \n" " struct A {};\n" " using AliasA = A;\n" - "}\n" - ); + "}"); // #3449 ASSERT_EQUALS("template < typename T > struct A ;\n" @@ -1493,7 +1490,7 @@ private: " pOut->CreateObject( nIndex, GDI_BRUSH, new WinMtfFillStyle( ReadColor(), ( nStyle == BS_HOLLOW ) ? TRUE : FALSE ) );\n" " return bStatus;\n" " };\n" - "}\n"); + "}"); } // #8151 - segfault due to incorrect template syntax @@ -1744,7 +1741,7 @@ private: // #8913 /* ASSERT_THROW(checkCode("public ref class LibCecSharp : public CecCallbackMethods {\n" - "array ^ FindAdapters(String ^ path) {} \n" + "array ^ FindAdapters(String ^ path) {}\n" "bool GetDeviceInformation(String ^ port, LibCECConfiguration ^configuration, uint32_t timeoutMs) {\n" "bool bReturn(false);\n" "}\n" @@ -1766,20 +1763,20 @@ private: "template< class T >\n" "template< class Predicate > int\n" "List::DeleteIf( const Predicate &pred )\n" - "{}\n"); + "{}"); // #8749 checkCode( "struct A {\n" " void operator+=(A&) && = delete;\n" - "};\n"); + "};"); // #8788 checkCode( "struct foo;\n" "void f() {\n" " auto fn = []() -> foo* { return new foo(); };\n" - "}\n"); + "}"); } }; diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 4495d0972..d29da328c 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -307,13 +307,13 @@ private: check("struct A { void operator()(int); };\n" "void f() {\n" "A{}(0);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("template struct A { void operator()(int); };\n" "void f() {\n" "A{}(0);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -342,7 +342,7 @@ private: check("void foo(int,const char*,int);\n" "void f(int value) {\n" " foo(42,\"test\",42),(value&42);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) Found suspicious operator ','\n", errout.str()); } diff --git a/test/testio.cpp b/test/testio.cpp index 174489425..fb6c8608f 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -2059,7 +2059,7 @@ private: " scanf(\"%lf\",&v4[0]);\n" " myvector v5(1);\n" " scanf(\"%10s\",v5[0]);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); { @@ -2089,7 +2089,7 @@ private: check("void g() {\n" " const char c[]=\"42\";\n" " scanf(\"%s\", c);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) %s in format string (no. 1) requires a 'char *' but the argument type is 'const char *'.\n" "[test.cpp:3]: (warning) scanf() without field width limits can crash with huge input data.\n", errout.str()); } @@ -2759,7 +2759,7 @@ private: check("void f(int len, int newline) {\n" " printf(\"%s\", newline ? a : str + len);\n" " printf(\"%s\", newline + newline);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'signed int'.\n", errout.str()); check("struct Fred { int i; } f;\n" @@ -2829,27 +2829,27 @@ private: // #4984 check("void f(double *x) {\n" " printf(\"%f\", x[0]);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int array[10];\n" "int * foo() { return array; }\n" "void f() {\n" " printf(\"%f\", foo()[0]);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'.\n", errout.str()); check("struct Base { int length() { } };\n" "struct Derived : public Base { };\n" "void foo(Derived * d) {\n" " printf(\"%f\", d.length());\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'.\n", errout.str()); check("std::vector v;\n" "void foo() {\n" " printf(\"%d %u %f\", v[0], v[0], v[0]);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:3]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'signed int'.\n", errout.str()); @@ -2857,7 +2857,7 @@ private: check("int bar(int a);\n" "void foo() {\n" " printf(\"%d\", bar(0));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::vector v;\n" @@ -3103,20 +3103,20 @@ private: check("void foo() {\n" " printf(\"%f %d\", static_cast(1.0f), reinterpret_cast(0));\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'.\n" "[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const void *'.\n", errout.str()); check("void foo() {\n" " UNKNOWN * u;\n" " printf(\"%d %x %u %f\", u[i], u[i], u[i], u[i]);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo() {\n" " long * l;\n" " printf(\"%d %x %u %f\", l[i], l[i], l[i], l[i]);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'signed long'.\n" "[test.cpp:3]: (warning) %x in format string (no. 2) requires 'unsigned int' but the argument type is 'signed long'.\n" "[test.cpp:3]: (warning) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed long'.\n" @@ -3137,27 +3137,27 @@ private: " printf(\"%u\",v6[0]);\n" " myvector v7(1,0);\n" " printf(\"%s\",v7[0]);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::vector v;\n" // #5151 "void foo() {\n" " printf(\"%c %u %f\", v.at(32), v.at(32), v.at(32));\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'char'.\n" "[test.cpp:3]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'char'.\n", errout.str()); // #5195 (segmentation fault) check("void T::a(const std::vector& vx) {\n" " printf(\"%f\", vx.at(0));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #5486 check("void foo() {\n" " ssize_t test = 0;\n" " printf(\"%zd\", test);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #6009 @@ -3165,7 +3165,7 @@ private: "extern int IntByReturnValue();\n" "void MyFunction() {\n" " printf( \"%s - %s\", StringByReturnValue(), IntByReturnValue() );\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'std::string'.\n" "[test.cpp:4]: (warning) %s in format string (no. 2) requires 'char *' but the argument type is 'signed int'.\n", errout.str()); @@ -3178,7 +3178,7 @@ private: " Array array1;\n" " Array array2;\n" " printf(\"%u %u\", array1[0], array2[0]);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:9]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'int'.\n" "[test.cpp:9]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'float'.\n", errout.str()); @@ -4711,7 +4711,7 @@ private: void testTernary() { // ticket #6182 check("void test(const std::string &val) {\n" " printf(\"%s\", val.empty() ? \"I like to eat bananas\" : val.c_str());\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -4719,30 +4719,30 @@ private: check("void test() {\n" " unsigned const x = 5;\n" " printf(\"%u\", x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } void testAstType() { // ticket #7014 check("void test() {\n" " printf(\"%c\", \"hello\"[0]);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void test() {\n" " printf(\"%lld\", (long long)1);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void test() {\n" " printf(\"%i\", (short *)x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) %i in format string (no. 1) requires 'int' but the argument type is 'signed short *'.\n", errout.str()); check("int (*fp)();\n" // #7178 - function pointer call "void test() {\n" " printf(\"%i\", fp());\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -4750,7 +4750,7 @@ private: check("void foo() {\n" " printf(\"%u %lu %llu\", 0U, 0UL, 0ULL);\n" " printf(\"%u %lu %llu\", 0u, 0ul, 0ull);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -4806,17 +4806,17 @@ private: void testPrintfParenthesis() { // #8489 check("void f(int a) {\n" " printf(\"%f\", (a >> 24) & 0xff);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'.\n", errout.str()); check("void f(int a) {\n" " printf(\"%f\", 0xff & (a >> 24));\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'.\n", errout.str()); check("void f(int a) {\n" " printf(\"%f\", ((a >> 24) + 1) & 0xff);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'.\n", errout.str()); } }; diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index a76aa96cc..639f74f47 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -615,14 +615,14 @@ private: check("struct Foo { int* ptr; };\n" "void f(Foo* foo) {\n" " delete foo->ptr;\n" - " foo->ptr = new Foo; \n" + " foo->ptr = new Foo;\n" "}", true); ASSERT_EQUALS("", errout.str()); check("struct Foo { int* ptr; };\n" "void f(Foo* foo) {\n" " delete foo->ptr;\n" - " x = *foo->ptr; \n" + " x = *foo->ptr;\n" "}", true); ASSERT_EQUALS("[test.cpp:4]: (error) Dereferencing 'ptr' after it is deallocated / released\n", errout.str()); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 4d98b15c7..8eaf1681a 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -230,7 +230,7 @@ private: " free(buf);\n" " else\n" " free(new_buf);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -244,7 +244,7 @@ private: " }\n" " free(pData);\n" " return true;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -256,7 +256,7 @@ private: " if (!m_buf) {\n" " m_buf = origBuf;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -264,7 +264,7 @@ private: check("void foo()\n" "{\n" " x = realloc(x,100);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -274,7 +274,7 @@ private: " pa = pb = malloc(10);\n" " pa = realloc(pa, 20);" " exit();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -285,7 +285,7 @@ private: " if (!p)\n" " error();\n" " usep(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -317,7 +317,7 @@ private: " if (!p)\n" " error();\n" " usep(p);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -328,7 +328,7 @@ private: " if( m_options == NULL )\n" " return false;\n" " return true;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Common realloc mistake: \'m_options\' nulled but not freed upon failure\n", errout.str()); } @@ -338,7 +338,7 @@ private: " if (zLine) {\n" " free(zLine);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1559,7 +1559,7 @@ private: " data_ = new char[42];\n" " delete data_;\n" " data_ = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:17]: (warning) Possible leak in public function. The pointer 'data_' is not deallocated before it is allocated.\n" "[test.cpp:18]: (error) Mismatching allocation and deallocation: Foo::data_\n", errout.str()); @@ -1582,7 +1582,7 @@ private: " data_ = new char[42];\n" " delete data_;\n" " data_ = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:17]: (warning) Possible leak in public function. The pointer 'data_' is not deallocated before it is allocated.\n" "[test.cpp:18]: (error) Mismatching allocation and deallocation: Foo::data_\n", errout.str()); } @@ -2438,18 +2438,18 @@ private: void resourceLeak() { check("void foo() {\n" " fopen(\"file.txt\", \"r\");\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (error) Return value of allocation function 'fopen' is not stored.\n", errout.str()); check("void foo() {\n" " FILE f* = fopen(\"file.txt\", \"r\");\n" " freopen(\"file.txt\", \"r\", f);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Return value of allocation function 'freopen' is not stored.\n", errout.str()); check("void foo() {\n" " freopen(\"file.txt\", \"r\", stdin);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct Holder {\n" @@ -2459,7 +2459,7 @@ private: "};\n" "void foo() {\n" " Holder h ( fopen(\"file.txt\", \"r\"));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct Holder {\n" @@ -2469,7 +2469,7 @@ private: "};\n" "void foo() {\n" " Holder ( fopen(\"file.txt\", \"r\"));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct Holder {\n" @@ -2479,7 +2479,7 @@ private: "};\n" "void foo() {\n" " Holder h { fopen(\"file.txt\", \"r\")};\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct Holder {\n" @@ -2489,7 +2489,7 @@ private: "};\n" "void foo() {\n" " Holder h = fopen(\"file.txt\", \"r\");\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct Holder {\n" @@ -2499,7 +2499,7 @@ private: "};\n" "void foo() {\n" " Holder { fopen(\"file.txt\", \"r\")};\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct Holder {\n" @@ -2509,7 +2509,7 @@ private: "};\n" "void foo() {\n" " Holder { 0, fopen(\"file.txt\", \"r\")};\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 068d9e19d..51a1f0a54 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -275,7 +275,7 @@ private: " while (tok) tok = tok->next();\n" " }\n" " tok->str();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Either the condition 'tok' is redundant or there is possible null pointer dereference: tok.\n", errout.str()); check("int foo(const Token *tok)\n" @@ -300,7 +300,7 @@ private: " while (d && d->i == 0)\n" " d = d->c;\n" " if (!d) throw;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct b {\n" @@ -1425,11 +1425,11 @@ private: void nullpointer28() { // #6491 check("typedef struct { int value; } S;\n" - "int f(const S *s) { \n" - " int i = s ? s->value + 1 \n" - " : s->value - 1; // <-- null ptr dereference \n" + "int f(const S *s) {\n" + " int i = s ? s->value + 1\n" + " : s->value - 1; // <-- null ptr dereference\n" " return i;\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:4]: (warning) Possible null pointer dereference: s\n", "", errout.str()); } @@ -1437,7 +1437,7 @@ private: check("void f(std::vector *values)\n" "{\n" " values->clear();\n" - " if (values) \n" + " if (values)\n" " {\n" " for (int i = 0; i < values->size(); ++i)\n" " {\n" @@ -1455,7 +1455,7 @@ private: "{\n" " int x;\n" "};\n" - " \n" + "\n" "static void foo(F* f)\n" "{\n" " if( f ) {}\n" @@ -1573,7 +1573,7 @@ private: "void f(struct A *a) {\n" " if (a->x == NULL) {}\n" " *(a->x);\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'a->x==NULL' is redundant or there is possible null pointer dereference: a->x.\n", errout.str()); @@ -1584,7 +1584,7 @@ private: "void f(struct A *a) {\n" " if (a->x == nullptr) {}\n" " *(a->x);\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'a->x==nullptr' is redundant or there is possible null pointer dereference: a->x.\n", errout.str()); @@ -1595,7 +1595,7 @@ private: "void f(struct A *a) {\n" " if (a->g() == nullptr) {}\n" " *(a->g());\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'a->g()==nullptr' is redundant or there is possible null pointer dereference: a->g().\n", errout.str()); @@ -1604,7 +1604,7 @@ private: "void f(struct A *a) {\n" " if (a->g() == nullptr) {}\n" " *(a->g());\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1613,7 +1613,7 @@ private: "void f(struct A *a) {\n" " if (a->g() == nullptr) {}\n" " *(a->g());\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'a->g()==nullptr' is redundant or there is possible null pointer dereference: a->g().\n", errout.str()); @@ -1626,7 +1626,7 @@ private: " if (x) {\n" " (void)*a->x;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1638,7 +1638,7 @@ private: " if ( w == 0.0 )\n" " return 0;\n" " return b->get();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9423 check("extern F* GetF();\n" @@ -1655,7 +1655,7 @@ private: " if (!lPtrOk)\n" " return;\n" " lPtr->Clear();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1672,7 +1672,7 @@ private: " g();\n" " a d = *c->b();\n" " return d;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct a {\n" @@ -1688,7 +1688,7 @@ private: " e();\n" " a d = *c->b();\n" " return d;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1696,7 +1696,7 @@ private: check("void f() {\n" " char* p = new(std::nothrow) char[1];\n" " if( p ) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1705,7 +1705,7 @@ private: " if(!p[0]) {}\n" " const int *const a = p;\n" " if(!a){}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (warning) Either the condition '!a' is redundant or there is possible null pointer dereference: p.\n", errout.str()); } @@ -1714,7 +1714,7 @@ private: "auto f(T& x) -> decltype(x);\n" "int& g(int* x) {\n" " return f(*x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1724,7 +1724,7 @@ private: " if(n > 10) q = p;\n" " *p +=2;\n" " if(n < 120) *q+=12;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (warning) Possible null pointer dereference: q\n", errout.str()); check("void f(int *p, int n) {\n" @@ -1732,7 +1732,7 @@ private: " if(n > 10) q = p;\n" " *p +=2;\n" " if(n > 10) *q+=12;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1746,7 +1746,7 @@ private: " }\n" " }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:2] -> [test.cpp:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p.\n", errout.str()); @@ -1762,7 +1762,7 @@ private: " if (c(e, \"\"))\n" " return nullptr;\n" " return e->b();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1772,7 +1772,7 @@ private: " if(b) c = b;\n" " if (!c) c = &a;\n" " return *c;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int f(int a, int* b) {\n" @@ -1781,7 +1781,7 @@ private: " bool d = !c;\n" " if (d) c = &a;\n" " return *c;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A { int* x; };\n" @@ -1791,7 +1791,7 @@ private: " if(b) c.x = b;\n" " if (!c.x) c.x = &a;\n" " return *c.x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A { int* x; };\n" @@ -1802,7 +1802,7 @@ private: " bool d = !c.x;\n" " if (d) c.x = &a;\n" " return *c.x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A { int* x; };\n" @@ -1825,7 +1825,7 @@ private: "}\n" "void bar() {\n" " f(0, 0);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) Possible null pointer dereference: params\n", errout.str()); } @@ -1837,11 +1837,11 @@ private: " return 1;\n" " }\n" " return 0;\n" - "} \n" + "}\n" "int bar() {\n" - " int **array = NULL; \n" + " int **array = NULL;\n" " foo (array, 0);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1851,7 +1851,7 @@ private: " while (tok3->astParent() && tok3->str() == \",\")\n" " tok3 = tok3->astParent();\n" " if (tok3 && tok3->str() == \"(\") {}\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:5] -> [test.cpp:3]: (warning) Either the condition 'tok3' is redundant or there is possible null pointer dereference: tok3.\n", errout.str()); @@ -1864,7 +1864,7 @@ private: " }\n" " if (!t1 || !t2)\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("bool f(int* i);\n" @@ -1872,7 +1872,7 @@ private: " while(f(i) && *i == 0)\n" " i++;\n" " if (!i) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1884,7 +1884,7 @@ private: " ListEntry *prev = NULL;\n" " for (ListEntry *cursor = listHead; cursor != NULL; prev = cursor, cursor = cursor->next) {}\n" " if (prev) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -2908,7 +2908,7 @@ private: "void f(int* x) {\n" " if (x)\n" " g(x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3134,42 +3134,42 @@ private: "void f(std::shared_ptr p) {\n" " if (p) {}\n" " dostuff(p->x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p.\n", errout.str()); check("struct Fred { int x; };\n" "void f(std::shared_ptr p) {\n" " p = nullptr;\n" " dostuff(p->x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str()); check("struct Fred { int x; };\n" "void f(std::unique_ptr p) {\n" " if (p) {}\n" " dostuff(p->x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'p' is redundant or there is possible null pointer dereference: p.\n", errout.str()); check("struct Fred { int x; };\n" "void f(std::unique_ptr p) {\n" " p = nullptr;\n" " dostuff(p->x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str()); check("struct Fred { int x; };\n" "void f() {\n" " std::shared_ptr p;\n" " dostuff(p->x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str()); check("struct Fred { int x; };\n" "void f(std::shared_ptr p) {\n" " p.reset();\n" " dostuff(p->x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str()); check("struct Fred { int x; };\n" @@ -3177,7 +3177,7 @@ private: " Fred * pp = nullptr;\n" " p.reset(pp);\n" " dostuff(p->x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference: p\n", errout.str()); check("struct Fred { int x; };\n" @@ -3185,28 +3185,28 @@ private: " std::shared_ptr p;\n" " p.reset(&f);\n" " dostuff(p->x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct Fred { int x; };\n" "void f(std::shared_ptr p) {\n" " p.release();\n" " dostuff(p->x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str()); check("struct Fred { int x; };\n" "void f() {\n" " std::shared_ptr p(nullptr);\n" " dostuff(p->x);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str()); check("struct A {};\n" "void f(int n) {\n" " std::unique_ptr p;\n" " p.reset(new const A*[n]);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9216 @@ -3217,7 +3217,7 @@ private: "void g(std::unique_ptr var) {\n" " var->reset();\n" " var->f();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9439 @@ -3560,7 +3560,7 @@ private: " unsigned int j;\n" " for (j = 0; j < b[0].a->size; ++j) {\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3584,27 +3584,27 @@ private: check("void foo(char *s) {\n" " p = s - 20;\n" "}\n" - "void bar() { foo(0); }\n"); + "void bar() { foo(0); }"); ASSERT_EQUALS("[test.cpp:2]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted.\n", errout.str()); check("void foo(char *s) {\n" " if (!s) {}\n" " p = s - 20;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition '!s' is redundant or there is overflow in pointer subtraction.\n", errout.str()); check("void foo(char *s) {\n" " s -= 20;\n" "}\n" - "void bar() { foo(0); }\n"); + "void bar() { foo(0); }"); ASSERT_EQUALS("[test.cpp:2]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted.\n", errout.str()); check("void foo(char *s) {\n" " if (!s) {}\n" " s -= 20;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition '!s' is redundant or there is overflow in pointer subtraction.\n", errout.str()); check("int* f8() { int *x = NULL; return --x; }"); @@ -3618,48 +3618,48 @@ private: check("void foo(char *s) {\n" " char * p = s + 20;\n" "}\n" - "void bar() { foo(0); }\n"); + "void bar() { foo(0); }"); ASSERT_EQUALS("[test.cpp:2]: (error) Pointer addition with NULL pointer.\n", errout.str()); check("void foo(char *s) {\n" " if (!s) {}\n" " char * p = s + 20;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition '!s' is redundant or there is pointer arithmetic with NULL pointer.\n", errout.str()); check("void foo(char *s) {\n" " char * p = 20 + s;\n" "}\n" - "void bar() { foo(0); }\n"); + "void bar() { foo(0); }"); ASSERT_EQUALS("[test.cpp:2]: (error) Pointer addition with NULL pointer.\n", errout.str()); check("void foo(char *s) {\n" " if (!s) {}\n" " char * p = 20 + s;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition '!s' is redundant or there is pointer arithmetic with NULL pointer.\n", errout.str()); check("void foo(char *s) {\n" " s += 20;\n" "}\n" - "void bar() { foo(0); }\n"); + "void bar() { foo(0); }"); ASSERT_EQUALS("[test.cpp:2]: (error) Pointer addition with NULL pointer.\n", errout.str()); check("void foo(char *s) {\n" " if (!s) {}\n" " s += 20;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Either the condition '!s' is redundant or there is pointer arithmetic with NULL pointer.\n", errout.str()); check("int* f7() { int *x = NULL; return ++x; }"); ASSERT_EQUALS("[test.cpp:1]: (error) Pointer addition with NULL pointer.\n", errout.str()); - check("int* f10() { int *x = NULL; return x++; } "); + check("int* f10() { int *x = NULL; return x++; }"); ASSERT_EQUALS("[test.cpp:1]: (error) Pointer addition with NULL pointer.\n", errout.str()); check("class foo {};\n" "const char* get() const { return 0; }\n" - "void f(foo x) { if (get()) x += get(); }\n"); + "void f(foo x) { if (get()) x += get(); }"); ASSERT_EQUALS("", errout.str()); } @@ -3763,7 +3763,7 @@ private: "void f(int* x) {\n" " if (x)\n" " g(x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } }; diff --git a/test/testother.cpp b/test/testother.cpp index 84f420cb8..6dd1c49ae 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -563,7 +563,7 @@ private: // #8141 check("intmax_t f() {\n" " return 1 / imaxabs(0);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (error) Division by zero.\n", errout.str()); } void zeroDiv13() { @@ -699,7 +699,7 @@ private: " else if (x > 0) {}\n" " else\n" " a = b / -x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A {\n" @@ -1271,7 +1271,7 @@ private: " if (cond2) { dostuff(key); }\n" " }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1620,7 +1620,7 @@ private: "class Plane {\n" " vec Refract(vec &vec) const;\n" " bool IntersectLinePlane(const vec &planeNormal);\n" - "}; "); + "};"); ASSERT_EQUALS("", errout.str()); check("class X {\n" @@ -1821,134 +1821,134 @@ private: check("int f(std::vector x) {\n" " int& i = x[0];\n" " return i;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'i' can be declared with const\n", errout.str()); check("int f(std::vector& x) {\n" " return x[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'x' can be declared with const\n", errout.str()); check("int f(std::vector x) {\n" " const int& i = x[0];\n" " return i;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int f(std::vector x) {\n" " static int& i = x[0];\n" " return i;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int f(std::vector x) {\n" " int& i = x[0];\n" " i++;\n" " return i;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int& f(std::vector& x) {\n" " x.push_back(1);\n" " int& i = x[0];\n" " return i;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int f(const std::vector& x) {\n" " return x[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int& f(std::vector& x) {\n" " return x[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int f(std::vector& x) {\n" " x[0]++;\n" " return x[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A { int a; };\n" "A f(std::vector& x) {\n" " x[0].a = 1;\n" " return x[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A { int a(); };\n" "A f(std::vector& x) {\n" " x[0].a();\n" " return x[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int g(int& x);\n" "int f(std::vector& x) {\n" " g(x[0]);\n" " return x[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("template\n" "T f(T& x) {\n" " return x[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("template\n" "T f(T&& x) {\n" " return x[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("template\n" "T f(T& x) {\n" " return x[0];\n" "}\n" - "void h() { std::vector v; h(v); }\n"); + "void h() { std::vector v; h(v); }"); ASSERT_EQUALS("", errout.str()); check("int f(int& x) {\n" " return std::move(x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(std::ostream& os) {\n" " os << \"Hello\";\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void g(int*);\n" "void f(int& x) {\n" " g(&x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A { A(int*); };\n" "A f(int& x) {\n" " return A(&x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A { A(int*); };\n" "A f(int& x) {\n" " return A{&x};\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Perhaps unused variable should be checked as well. check("void f(int& x, int& y) {\n" " y++;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A {\n" " explicit A(int& y) : x(&y) {}\n" " int * x = nullptr;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); check("struct A {\n" @@ -1956,7 +1956,7 @@ private: " void swap(A& a) {\n" " v.swap(a.v);\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); check("struct A {\n" @@ -1967,54 +1967,54 @@ private: "};\n" "void g(A& a) {\n" " a.f();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(std::vector& v) {\n" " for(auto&& x:v)\n" " x = 1;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(std::vector& v) {\n" " for(auto x:v)\n" " x = 1;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'v' can be declared with const\n", errout.str()); check("void f(std::vector& v) {\n" " for(auto& x:v) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'v' can be declared with const\n", errout.str()); check("void f(std::vector& v) {\n" " for(const auto& x:v) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'v' can be declared with const\n", errout.str()); check("void f(int& i) {\n" " int& j = i;\n" " j++;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(std::vector& v) {\n" " int& i = v[0];\n" " i++;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(std::map >& m, unsigned int i) {\n" " std::map& members = m[i];\n" " members.clear();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A {\n" " int& x;\n" " A(int& y) : x(y)\n" " {}\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); check("struct A {\n" @@ -2023,14 +2023,14 @@ private: "struct B : A {\n" " B(int& x) : A(x)\n" " {}\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); check("void f(bool b, int& x, int& y) {\n" " auto& z = x;\n" " auto& w = b ? y : z;\n" " w = 1;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct S {\n" @@ -2038,7 +2038,7 @@ private: "};\n" "int& f(S& s) {\n" " return s.i;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int* f(std::list& x, unsigned int y) {\n" @@ -2047,7 +2047,7 @@ private: " return &m;\n" " }\n" " return nullptr;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int& f(std::list& x, int& y) {\n" @@ -2056,7 +2056,7 @@ private: " return m;\n" " }\n" " return y;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("bool from_string(int& t, const std::string& s) {\n" @@ -2461,7 +2461,7 @@ private: "}\n" "void bc(size_t ae) {\n" "wchar_t *ad = 0, *af = 0;\n" - "struct tm *ag = 0; \n" + "struct tm *ag = 0;\n" "(void)std::wcsftime(ad, ae, af, ag);\n" "(void)std::wcsftime(0, ae, 0, 0);\n" "}\n" @@ -2475,7 +2475,7 @@ private: "void bh(const std::list &ak, const std::list &al);\n" "void ah();\n" "void an();\n" - "void h();\n"); + "void h();"); ASSERT_EQUALS("", errout.str()); check("class C\n" @@ -2496,7 +2496,7 @@ private: "D::D(int& i)\n" " : c(i)\n" "{\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("class C\n" @@ -2537,7 +2537,7 @@ private: "D::D(int& i)\n" " : c(i)\n" "{\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:16]: (style) Parameter 'i' can be declared with const\n", "", errout.str()); check("class C\n" @@ -2558,7 +2558,7 @@ private: "D::D(int& i)\n" " : c(i)\n" "{\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:16]: (style) Parameter 'i' can be declared with const\n", "", errout.str()); check("class C\n" @@ -2579,7 +2579,7 @@ private: "D::D(int& i)\n" " : c(0, i)\n" "{\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:16]: (style) Parameter 'i' can be declared with const\n", "", errout.str()); } @@ -3997,7 +3997,7 @@ private: "void something(void) {}\n" "void f() {\n" " struct callbacks ops = { .s = ops.s };\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("[test.cpp:6]: (warning) Redundant assignment of 'something' to itself.\n", "", errout.str()); check("class V\n" @@ -4046,8 +4046,7 @@ private: " Lock(123);\n" " std::cout << \"hello\" << std::endl;\n" " return 0;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:15]: (style) Instance of 'Lock' object is destroyed immediately.\n", errout.str()); } @@ -4066,8 +4065,7 @@ private: "{\n" " CouldBeFunction ( 123 ) ;\n" " return 0 ;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -4084,8 +4082,7 @@ private: " error();\n" " do_something();\n" " }\n" - "};\n" - ); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -4095,8 +4092,7 @@ private: "{\n" " NotAFunction ( 123 );\n" " return 0 ;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Instance of 'NotAFunction' object is destroyed immediately.\n", errout.str()); } @@ -4106,8 +4102,7 @@ private: "{\n" " NotAClass ( 123 ) ;\n" " return true ;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:4]: (style) Instance of 'NotAClass' object is destroyed immediately.\n", errout.str()); } @@ -4116,8 +4111,7 @@ private: "{\n" " if ( a > b ) return c == a ;\n" " return b == a ;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -4127,8 +4121,7 @@ private: "public:\n" "~Something ( ) ;\n" "Something ( ) ;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -4147,8 +4140,7 @@ private: " int a = 1;\n" " IncrementFunctor()(a);\n" " return a;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -4161,8 +4153,7 @@ private: " };\n" " Foo();\n" " do_something();\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:7]: (style) Instance of 'Foo' object is destroyed immediately.\n", errout.str()); } @@ -4174,8 +4165,7 @@ private: "\n" "void fn() {\n" " Foo().bar();\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -4257,8 +4247,7 @@ private: "\n" " { sigaction(SIGHUP, &sa, 0); };\n" " { sigaction(SIGINT, &sa, 0); };\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -4269,8 +4258,7 @@ private: " };\n" "\n" " const AB ab[3] = { AB(0), AB(1), AB(2) };\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -4523,7 +4511,7 @@ private: " } else {\n" " x = j;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5] -> [test.cpp:3]: (style, inconclusive) Found duplicate branches for 'if' and 'else'.\n", errout.str()); check("void f(bool b, int i) {\n" @@ -4534,7 +4522,7 @@ private: " } else {\n" " x = j;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -4545,7 +4533,7 @@ private: " } else {\n" " return new A::Z(true);\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -4921,7 +4909,7 @@ private: check("void f(C *src) {\n" " if (x(src) || x(src))\n" " a++;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(A *src) {\n" @@ -4978,36 +4966,36 @@ private: check("void f() {\n" " const int i = sizeof(int);\n" " if ( i != sizeof (int)){}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'i != sizeof(int)' is always false because 'i' and 'sizeof(int)' represent the same value.\n", errout.str()); check("void f() {\n" " const int i = sizeof(int);\n" " if ( sizeof (int) != i){}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'sizeof(int) != i' is always false because 'sizeof(int)' and 'i' represent the same value.\n", errout.str()); - check("void f(int a = 1) { if ( a != 1){}}\n"); + check("void f(int a = 1) { if ( a != 1){}}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" " int a = 1;\n" - " if ( a != 1){} \n" - "}\n"); + " if ( a != 1){}\n" + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'a != 1' is always false.\n", errout.str()); check("void f() {\n" " int a = 1;\n" " int b = 1;\n" - " if ( a != b){} \n" - "}\n"); + " if ( a != b){}\n" + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3] -> [test.cpp:4]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value.\n", errout.str()); check("void f() {\n" " int a = 1;\n" " int b = a;\n" - " if ( a != b){} \n" - "}\n"); + " if ( a != b){}\n" + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) The comparison 'a != b' is always false because 'a' and 'b' represent the same value.\n", errout.str()); check("void use(int);\n" @@ -5015,8 +5003,8 @@ private: " int a = 1;\n" " int b = 1;\n" " use(b);\n" - " if ( a != 1){} \n" - "}\n"); + " if ( a != 1){}\n" + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (style) The comparison 'a != 1' is always false.\n", errout.str()); check("void use(int);\n" @@ -5024,8 +5012,8 @@ private: " int a = 1;\n" " use(a);\n" " a = 2;\n" - " if ( a != 1){} \n" - "}\n"); + " if ( a != 1){}\n" + "}"); ASSERT_EQUALS("", errout.str()); check("void use(int);\n" @@ -5033,39 +5021,39 @@ private: " int a = 2;\n" " use(a);\n" " a = 1;\n" - " if ( a != 1){} \n" - "}\n"); + " if ( a != 1){}\n" + "}"); ASSERT_EQUALS("", errout.str()); check("const int a = 1;\n" "void f() {\n" - " if ( a != 1){} \n" - "}\n"); + " if ( a != 1){}\n" + "}"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:3]: (style) The comparison 'a != 1' is always false.\n", errout.str()); check("int a = 1;\n" " void f() {\n" - " if ( a != 1){} \n" - "}\n"); + " if ( a != 1){}\n" + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" " static const int a = 1;\n" - " if ( a != 1){} \n" - "}\n"); + " if ( a != 1){}\n" + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'a != 1' is always false.\n", errout.str()); check("void f() {\n" " static int a = 1;\n" - " if ( a != 1){} \n" - "}\n"); + " if ( a != 1){}\n" + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" " int a = 1;\n" " if ( a != 1){\n" " a++;\n" - " }}\n"); + " }}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'a != 1' is always false.\n", errout.str()); check("void f(int b) {\n" @@ -5074,26 +5062,26 @@ private: " if ( a != 1){}\n" " a++;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("bool f(bool a, bool b) {\n" " const bool c = a;\n" " return a && b && c;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Same expression on both sides of '&&' because 'a' and 'c' represent the same value.\n", errout.str()); // 6906 check("void f(const bool b) {\n" " const bool b1 = !b;\n" " if(!b && b1){}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Same expression on both sides of '&&' because '!b' and 'b1' represent the same value.\n", errout.str()); // 7284 check("void f(void) {\n" " if (a || !!a) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Same expression on both sides of '||' because 'a' and '!!a' represent the same value.\n", errout.str()); // 8205 @@ -5104,7 +5092,7 @@ private: " if (Diag==0) {}\n" " break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:5]: (style) The comparison 'Diag == 0' is always true.\n", errout.str()); } @@ -5114,13 +5102,13 @@ private: " int b = a;\n" " a = 2;\n" " if ( b != a){}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); - check("void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}\n"); + check("void f(int * a, int i) { int b = a[i]; a[i] = 2; if ( b != a[i]){}}"); ASSERT_EQUALS("", errout.str()); - check("void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}\n"); + check("void f(int * a, int i) { int b = *a; *a = 2; if ( b != *a){}}"); ASSERT_EQUALS("", errout.str()); check("struct A { int f() const; };\n" @@ -5131,7 +5119,7 @@ private: " x = g();\n" " if (x.f() == a) break;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int f(int i);\n" @@ -5144,33 +5132,33 @@ private: " const bool x = a.f(A::B);\n" " const bool y = a.f(A::C);\n" " if(!x && !y) return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); - check("void foo() { \n" + check("void foo() {\n" " const bool x = a.f(A::B);\n" " const bool y = a.f(A::C);\n" " if (!x && !y) return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(bool * const b);\n" - "void foo() { \n" + "void foo() {\n" " bool x = true;\n" " bool y = true;\n" " f(&x);\n" " if (!x && !y) return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" " const int a = {};\n" " if(a == 1) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("volatile const int var = 42;\n" - "void f() { if(var == 42) {} }\n"); + "void f() { if(var == 42) {} }"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" @@ -5179,7 +5167,7 @@ private: " c.a = &a;\n" " g(&c);\n" " if (a == 0) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5189,7 +5177,7 @@ private: " uint16_t x = 1000;\n" " uint8_t y = x;\n" " if (x != y) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5200,7 +5188,7 @@ private: " const int b = a-1;\n" " const int c = a+1;\n" " return c;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5229,23 +5217,23 @@ private: check("void f() {\n" " int a = 1;\n" " while ( a != 1){}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'a != 1' is always false.\n", errout.str()); - check("void f() { int a = 1; while ( a != 1){ a++; }}\n"); + check("void f() { int a = 1; while ( a != 1){ a++; }}"); ASSERT_EQUALS("", errout.str()); - check("void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}\n"); + check("void f() { int a = 1; for ( int i=0; i < 3 && a != 1; i++){ a++; }}"); ASSERT_EQUALS("", errout.str()); - check("void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; } \n"); + check("void f(int b) { int a = 1; while (b) { if ( a != 1){} b++; } a++; }"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" " for(int i = 0; i < 10;) {\n" " if( i != 0 ) {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'i != 0' is always false.\n", errout.str()); check("void f() {\n" @@ -5253,7 +5241,7 @@ private: " if( i != 0 ) {}\n" " i++;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" @@ -5261,14 +5249,14 @@ private: " if( i != 0 ) { i++; }\n" " i++;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" " for(int i = 0; i < 10;) {\n" " if( i != 0 ) { i++; }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" @@ -5277,7 +5265,7 @@ private: " if( i != 0 ) {}\n" " i++;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int b) {\n" @@ -5286,7 +5274,7 @@ private: " if ( a != 1){}\n" " b++;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) The comparison 'a != 1' is always false.\n", errout.str()); } @@ -5299,7 +5287,7 @@ private: check("int f(bool b, int a) {\n" " const int c = a;\n" " return b ? a : c;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Same expression in both branches of ternary operator.\n", errout.str()); check("void f() {\n" @@ -5475,7 +5463,7 @@ private: " const bool b = a;\n" " if( a == !(b) ) {}\n" " if( b == !(a) ) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Opposite expression on both sides of '=='.\n" "[test.cpp:2] -> [test.cpp:4]: (style) Opposite expression on both sides of '=='.\n", errout.str()); @@ -5483,7 +5471,7 @@ private: " const bool b = *a;\n" " if( *a == !(b) ) {}\n" " if( b == !(*a) ) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Opposite expression on both sides of '=='.\n" "[test.cpp:2] -> [test.cpp:4]: (style) Opposite expression on both sides of '=='.\n", errout.str()); @@ -5508,29 +5496,29 @@ private: check("void A::f(bool a, bool c)\n" "{\n" " const bool b = a;\n" - " if(c) { a = false; } \n" + " if(c) { a = false; }\n" " if(b && !a) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(bool c) {\n" " const bool b = a;\n" - " if(c) { a = false; } \n" + " if(c) { a = false; }\n" " if(b && !a) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" " bool x = a;\n" " dostuff();\n" " if (x && a) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" " const bool b = g();\n" " if (!b && g()) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(bool *a) {\n" @@ -5868,7 +5856,7 @@ private: " }\n" " previous = current;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:16] -> [test.cpp:15]: (style, inconclusive) Same expression used in consecutive assignments of 'current' and 'previous'.\n", errout.str()); } @@ -5884,21 +5872,21 @@ private: " int b = x.f();\n" " (void)a;\n" " (void)b;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:7]: (style, inconclusive) Same expression used in consecutive assignments of 'a' and 'b'.\n", errout.str()); // Issue #8712 check("void f() {\n" " unsigned char d;\n" " d = d % 5;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("template \n" "T f() {\n" " T x = T();\n" "}\n" - "int &a = f();\n"); + "int &a = f();"); ASSERT_EQUALS("", errout.str()); // Issue #8713 @@ -5910,7 +5898,7 @@ private: " uint32_t a = 42;\n" " uint32_t b = uint32_t(A ::B / 1024);\n" " int32_t c = int32_t(a / b);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Issue #8709 @@ -5919,7 +5907,7 @@ private: " switch (d) { case b:; }\n" " double e(b);\n" " if(e <= 0) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5929,7 +5917,7 @@ private: " int val = 0;\n" " if (val < 0) continue;\n" " if ((val > 0)) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'val < 0' is always false.\n" "[test.cpp:2] -> [test.cpp:4]: (style) The comparison 'val > 0' is always false.\n", errout.str()); @@ -5956,7 +5944,7 @@ private: " if (val < 0) {\n" " if ((val > 0)) {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'val < 0' is always false.\n" "[test.cpp:2] -> [test.cpp:4]: (style) The comparison 'val > 0' is always false.\n", errout.str()); @@ -5965,7 +5953,7 @@ private: " if (val < 0) {\n" " if ((val < 0)) {}\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) The comparison 'val < 0' is always false.\n" "[test.cpp:2] -> [test.cpp:4]: (style) The comparison 'val < 0' is always false.\n", errout.str()); @@ -5974,7 +5962,7 @@ private: " int foo = 0;\n" " if (activate) {}\n" " else if (foo) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -6186,7 +6174,7 @@ private: keepTemplates.checkUnusedTemplates = true; check("template void foo(unsigned int x) {\n" "if (x <= 0);\n" - "}\n", &keepTemplates); + "}", &keepTemplates); ASSERT_EQUALS("[test.cpp:2]: (style) Checking if unsigned expression 'x' is less than zero.\n", errout.str()); } @@ -6197,7 +6185,7 @@ private: " {\n" " value = 0u;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Checking if unsigned expression 'value' is less than zero.\n", errout.str()); // #9040 @@ -6283,7 +6271,7 @@ private: " int* ptr;\n" "};\n" "void foo(S* first) {\n" - " if (first.ptr >= 0) {} \n" + " if (first.ptr >= 0) {}\n" "}"); ASSERT_EQUALS("[test.cpp:5]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not.\n", errout.str()); @@ -6291,7 +6279,7 @@ private: " int* ptr;\n" "};\n" "void foo(S* first, S* second) {\n" - " if((first.ptr - second.ptr) >= 0) {} \n" + " if((first.ptr - second.ptr) >= 0) {}\n" "}"); ASSERT_EQUALS("", errout.str()); @@ -6299,7 +6287,7 @@ private: " int* ptr;\n" "};\n" "void foo(S* first) {\n" - " if((first.ptr) >= 0) {} \n" + " if((first.ptr) >= 0) {}\n" "}"); ASSERT_EQUALS("[test.cpp:5]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not.\n", errout.str()); @@ -6307,7 +6295,7 @@ private: " int* ptr;\n" "};\n" "void foo(S* first, S* second) {\n" - " if(0 <= first.ptr - second.ptr) {} \n" + " if(0 <= first.ptr - second.ptr) {}\n" "}"); ASSERT_EQUALS("", errout.str()); @@ -6315,7 +6303,7 @@ private: " int* ptr;\n" "};\n" "void foo(S* first, S* second) {\n" - " if(0 <= (first.ptr - second.ptr)) {} \n" + " if(0 <= (first.ptr - second.ptr)) {}\n" "}"); ASSERT_EQUALS("", errout.str()); @@ -6323,7 +6311,7 @@ private: " int* ptr;\n" "};\n" "void foo(S* first, S* second) {\n" - " if(first.ptr - second.ptr < 0) {} \n" + " if(first.ptr - second.ptr < 0) {}\n" "}"); ASSERT_EQUALS("", errout.str()); @@ -6331,7 +6319,7 @@ private: " int* ptr;\n" "};\n" "void foo(S* first, S* second) {\n" - " if((first.ptr - second.ptr) < 0) {} \n" + " if((first.ptr - second.ptr) < 0) {}\n" "}"); ASSERT_EQUALS("", errout.str()); @@ -6339,7 +6327,7 @@ private: " int* ptr;\n" "};\n" "void foo(S* first, S* second) {\n" - " if(0 > first.ptr - second.ptr) {} \n" + " if(0 > first.ptr - second.ptr) {}\n" "}"); ASSERT_EQUALS("", errout.str()); @@ -6347,7 +6335,7 @@ private: " int* ptr;\n" "};\n" "void foo(S* first, S* second) {\n" - " if(0 > (first.ptr - second.ptr)) {} \n" + " if(0 > (first.ptr - second.ptr)) {}\n" "}"); ASSERT_EQUALS("", errout.str()); @@ -6725,7 +6713,7 @@ private: "}"); ASSERT_EQUALS("[test.cpp:2]: (portability) Shifting a negative value is technically undefined behaviour\n", errout.str()); - check("x = y ? z << $-1 : 0;\n"); + check("x = y ? z << $-1 : 0;"); ASSERT_EQUALS("", errout.str()); // Negative LHS @@ -6740,7 +6728,7 @@ private: check("int shift1() { return 1 >> -1 ;}\n" "int shift2() { return 1 << -1 ;}\n" "int shift3() { return -1 >> 1 ;}\n" - "int shift4() { return -1 << 1 ;}\n"); + "int shift4() { return -1 << 1 ;}"); ASSERT_EQUALS("[test.cpp:1]: (error) Shifting by a negative value is undefined behaviour\n" "[test.cpp:2]: (error) Shifting by a negative value is undefined behaviour\n" "[test.cpp:3]: (portability) Shifting a negative value is technically undefined behaviour\n" @@ -7745,7 +7733,7 @@ private: "{\n" " if (pipe (arrayPtr) < 0)\n" " {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // avoid crash with pointer variable - for local variable on stack as well - see #4801 @@ -8111,7 +8099,7 @@ private: // no signed integer overflow should happen check("void f(unsigned long long ull) {\n" " if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -8184,7 +8172,7 @@ private: " int counter = 0;\n" " InterlockedDecrement(&counter);\n" " whatever();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8193,7 +8181,7 @@ private: " if (counter)\n" " return;\n" " destroy();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8201,7 +8189,7 @@ private: " InterlockedDecrement(&counter);\n" " if (!counter)\n" " destroy();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8210,7 +8198,7 @@ private: " if (counter > 0)\n" " return;\n" " destroy();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8219,7 +8207,7 @@ private: " if (0 < counter)\n" " return;\n" " destroy();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8227,7 +8215,7 @@ private: " InterlockedDecrement(&counter);\n" " if (counter == 0)\n" " destroy();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8235,7 +8223,7 @@ private: " InterlockedDecrement(&counter);\n" " if (0 == counter)\n" " destroy();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8244,7 +8232,7 @@ private: " if (0 != counter)\n" " return;\n" " destroy()\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8253,7 +8241,7 @@ private: " if (counter != 0)\n" " return;\n" " destroy()\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8261,7 +8249,7 @@ private: " InterlockedDecrement(&counter);\n" " if (counter <= 0)\n" " destroy();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8269,7 +8257,7 @@ private: " InterlockedDecrement(&counter);\n" " if (0 >= counter)\n" " destroy();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8278,7 +8266,7 @@ private: " if (newCount)\n" " return;\n" " destroy();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8286,7 +8274,7 @@ private: " int newCount = InterlockedDecrement(&counter);\n" " if (!newCount)\n" " destroy();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8295,7 +8283,7 @@ private: " if (newCount > 0)\n" " return;\n" " destroy();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8304,7 +8292,7 @@ private: " if (0 < newCount)\n" " return;\n" " destroy();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8312,7 +8300,7 @@ private: " int newCount = InterlockedDecrement(&counter);\n" " if (newCount == 0)\n" " destroy();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8320,7 +8308,7 @@ private: " int newCount = InterlockedDecrement(&counter);\n" " if (0 == newCount)\n" " destroy();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8329,7 +8317,7 @@ private: " if (0 != newCount)\n" " return;\n" " destroy()\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8338,7 +8326,7 @@ private: " if (newCount != 0)\n" " return;\n" " destroy()\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8346,7 +8334,7 @@ private: " int newCount = InterlockedDecrement(&counter);\n" " if (newCount <= 0)\n" " destroy();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkInterlockedDecrement("void f() {\n" @@ -8354,7 +8342,7 @@ private: " int newCount = InterlockedDecrement(&counter);\n" " if (0 >= newCount)\n" " destroy;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkInterlockedDecrement("int f() {\n" @@ -8365,7 +8353,7 @@ private: " } else {\n" " return counter;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout.str()); checkInterlockedDecrement("int f() {\n" @@ -8376,7 +8364,7 @@ private: " } else {\n" " return counter;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout.str()); @@ -8387,7 +8375,7 @@ private: " return 0;\n" " }\n" " return counter;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout.str()); checkInterlockedDecrement("int f() {\n" @@ -8397,7 +8385,7 @@ private: " return 0;\n" " }\n" " return counter;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout.str()); checkInterlockedDecrement("int f() {\n" @@ -8407,8 +8395,8 @@ private: " return 0;\n" " } else\n" " return counter;\n" - " \n" - "}\n"); + " \n" + "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout.str()); checkInterlockedDecrement("int f() {\n" @@ -8418,8 +8406,8 @@ private: " return 0;\n" " } else\n" " return counter;\n" - " \n" - "}\n"); + " \n" + "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Race condition: non-interlocked access after InterlockedDecrement(). Use InterlockedDecrement() return value instead.\n", errout.str()); } @@ -8868,12 +8856,12 @@ private: } void funcArgNamesDifferent() { - check("void func1(int a, int b, int c); \n" + check("void func1(int a, int b, int c);\n" "void func1(int a, int b, int c) { }\n" "void func2(int a, int b, int c);\n" "void func2(int A, int B, int C) { }\n" "class Fred {\n" - " void func1(int a, int b, int c); \n" + " void func1(int a, int b, int c);\n" " void func2(int a, int b, int c);\n" " void func3(int a = 0, int b = 0, int c = 0);\n" " void func4(int a = 0, int b = 0, int c = 0);\n" @@ -8881,7 +8869,7 @@ private: "void Fred::func1(int a, int b, int c) { }\n" "void Fred::func2(int A, int B, int C) { }\n" "void Fred::func3(int a, int b, int c) { }\n" - "void Fred::func4(int A, int B, int C) { }\n"); + "void Fred::func4(int A, int B, int C) { }"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style, inconclusive) Function 'func2' argument 1 names different: declaration 'a' definition 'A'.\n" "[test.cpp:3] -> [test.cpp:4]: (style, inconclusive) Function 'func2' argument 2 names different: declaration 'b' definition 'B'.\n" "[test.cpp:3] -> [test.cpp:4]: (style, inconclusive) Function 'func2' argument 3 names different: declaration 'c' definition 'C'.\n" @@ -8930,11 +8918,11 @@ private: void shadowVariables() { check("int x;\n" - "void f() { int x; }\n"); + "void f() { int x; }"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:2]: (style) Local variable \'x\' shadows outer variable\n", errout.str()); check("int x();\n" - "void f() { int x; }\n"); + "void f() { int x; }"); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:2]: (style) Local variable \'x\' shadows outer function\n", errout.str()); check("struct C {\n" @@ -8946,12 +8934,12 @@ private: check("void f() {\n" " if (cond) {int x;}\n" // <- not a shadow variable " int x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int size() {\n" " int size;\n" // <- not a shadow variable - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" // #8954 - lambda @@ -8971,65 +8959,65 @@ private: check("void g(int);\n" "void f(int x) {\n" " g((x & 0x01) >> 7);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Argument '(x&0x01)>>7' to function g is always 0. It does not matter what value 'x' has.\n", errout.str()); check("void g(int);\n" "void f(int x) {\n" " g((int)((x & 0x01) >> 7));\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Argument '(int)((x&0x01)>>7)' to function g is always 0. It does not matter what value 'x' has.\n", errout.str()); check("void g(int);\n" "void f(int x) {\n" " g(0);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void g(int);\n" "void h() { return 1; }\n" "void f(int x) {\n" " g(h());\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void g(int);\n" "void f(int x) {\n" " g(std::strlen(\"a\"));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void g(int);\n" "void f(int x) {\n" " g((int)0);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void g(Foo *);\n" "void f() {\n" " g(reinterpret_cast(0));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void g(int);\n" "void f(int x) {\n" " x = 0;\n" " g(x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void g(int);\n" "void f() {\n" " const int x = 0;\n" " g(x + 1);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void g(int);\n" "void f() {\n" " char i = 1;\n" " g(static_cast(i));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("char *yytext;\n" @@ -9049,14 +9037,14 @@ private: "void g() {\n" " const int x[] = { 10, 10 };\n" " f(x[0]);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int);\n" "void g() {\n" " int x[] = { 10, 10 };\n" " f(x[0]);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A { int x; };" @@ -9065,14 +9053,14 @@ private: " A y;\n" " y.x = 1;\n" " g(y.x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // allow known argument value in assert call check("void g(int);\n" "void f(int x) {\n" " ASSERT((int)((x & 0x01) >> 7));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9905 - expression that does not use integer calculation at all @@ -9119,7 +9107,7 @@ private: " diff = 1;\n" " }\n" " return diff;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:2] -> [test.cpp:5] -> [test.cpp:3] -> [test.cpp:5] -> [test.cpp:5]: (error) Comparing pointers that point to different objects\n", errout.str()); @@ -9130,7 +9118,7 @@ private: " int* xp = &x;\n" " int* yp = &y;\n" " return xp > yp;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:2] -> [test.cpp:4] -> [test.cpp:3] -> [test.cpp:5] -> [test.cpp:6]: (error) Comparing pointers that point to different objects\n", errout.str()); @@ -9139,7 +9127,7 @@ private: " int x = 0;\n" " int y = 1;\n" " return &x > &y;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:2] -> [test.cpp:4] -> [test.cpp:3] -> [test.cpp:4] -> [test.cpp:4]: (error) Comparing pointers that point to different objects\n", errout.str()); @@ -9151,7 +9139,7 @@ private: " int* xp = &x.data;\n" " int* yp = &y.data;\n" " return xp > yp;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:1] -> [test.cpp:5] -> [test.cpp:1] -> [test.cpp:6] -> [test.cpp:7]: (error) Comparing pointers that point to different objects\n", errout.str()); @@ -9163,14 +9151,14 @@ private: " int* xp = &x->data;\n" " int* yp = &y->data;\n" " return xp > yp;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:2] -> [test.cpp:3] -> [test.cpp:5] -> [test.cpp:2] -> [test.cpp:4] -> [test.cpp:6] -> [test.cpp:7]: (error) Comparing pointers that point to different objects\n", errout.str()); check("bool f(int * xp, int* yp) {\n" " return &xp > &yp;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:1] -> [test.cpp:2] -> [test.cpp:1] -> [test.cpp:2] -> [test.cpp:2]: (error) Comparing pointers that point to different objects\n", errout.str()); @@ -9179,7 +9167,7 @@ private: " int x = 0;\n" " int y = 1;\n" " return &x - &y;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:2] -> [test.cpp:4] -> [test.cpp:3] -> [test.cpp:4] -> [test.cpp:4]: (error) Subtracting pointers that point to different objects\n", errout.str()); @@ -9189,17 +9177,17 @@ private: " int* xp = &x[0];\n" " int* yp = &x[1];\n" " return xp > yp;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("bool f(int * xp, int* yp) {\n" " return xp > yp;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("bool f(const int & x, const int& y) {\n" " return &x > &y;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("int& g();\n" @@ -9209,7 +9197,7 @@ private: " const int* xp = &x;\n" " const int* yp = &y;\n" " return xp > yp;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct A {int data;};\n" @@ -9219,7 +9207,7 @@ private: " int* xp = &x->data;\n" " int* yp = &y->data;\n" " return xp > yp;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testpostfixoperator.cpp b/test/testpostfixoperator.cpp index c605ab27d..6e24d21ba 100644 --- a/test/testpostfixoperator.cpp +++ b/test/testpostfixoperator.cpp @@ -329,7 +329,7 @@ private: "\n" "void f() {\n" " p++;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index bf723aeb5..9e1631d5e 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -2484,7 +2484,7 @@ private: void template102() { // #9005 const char code[] = "namespace ns {\n" "template \n" - "struct is_floating_point \n" + "struct is_floating_point\n" ": std::integral_constant::value || true>\n" "{};\n" "}\n" @@ -4563,11 +4563,11 @@ private: void syntax_error_templates_1() { // ok code.. using ">" for a comparison - tok("xz> xyz;\n"); + tok("xz> xyz;"); ASSERT_EQUALS("", errout.str()); // ok code - tok("template operator<(T a, T b) { }\n"); + tok("template operator<(T a, T b) { }"); ASSERT_EQUALS("", errout.str()); // ok code (ticket #1984) @@ -4604,7 +4604,7 @@ private: " }\n" "private:\n" " A a;\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); //both of these should work but in cppcheck 2.1 only the first option will work (ticket #9843) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 7b9be8e98..df65c9f1b 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -3165,7 +3165,7 @@ private: const char code[] = "void foo()\n" "{\n" " char *a, *b;\n" - " if (x) \n" + " if (x)\n" " delete a, b;\n" "}\n"; ASSERT_EQUALS("void foo ( ) { char * a ; char * b ; if ( x ) { delete a ; b ; } }", tok(code)); diff --git a/test/testsizeof.cpp b/test/testsizeof.cpp index 4389447bd..17a31786f 100644 --- a/test/testsizeof.cpp +++ b/test/testsizeof.cpp @@ -223,7 +223,7 @@ private: " Y = sizeof(f(g() << h())) == sizeof(A),\n" " Z = X & Y\n" " };\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -231,8 +231,7 @@ private: check("void f() {\n" " int a[10];\n" " std::cout << sizeof(a) / sizeof(int) << std::endl;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" @@ -240,8 +239,7 @@ private: " unsigned int b = 2;\n" " int c[(a+b)];\n" " std::cout << sizeof(c) / sizeof(int) << std::endl;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" @@ -249,8 +247,7 @@ private: " unsigned int b[] = { 0 };\n" " int c[a[b[0]]];\n" " std::cout << sizeof(c) / sizeof(int) << std::endl;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); @@ -259,42 +256,36 @@ private: " unsigned int b = 2;\n" " int c[(a[0]+b)];\n" " std::cout << sizeof(c) / sizeof(int) << std::endl;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" " int a[] = { 1, 2, 3 };\n" " std::cout << sizeof(a) / sizeof(int) << std::endl;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" " int a[3] = { 1, 2, 3 };\n" " std::cout << sizeof(a) / sizeof(int) << std::endl;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f( int a[]) {\n" " std::cout << sizeof(a) / sizeof(int) << std::endl;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Using 'sizeof' on array given as " "function argument returns size of a pointer.\n", errout.str()); check("void f( int a[]) {\n" " std::cout << sizeof a / sizeof(int) << std::endl;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Using 'sizeof' on array given as " "function argument returns size of a pointer.\n", errout.str()); check("void f( int a[3] ) {\n" " std::cout << sizeof(a) / sizeof(int) << std::endl;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Using 'sizeof' on array given as " "function argument returns size of a pointer.\n", errout.str()); @@ -302,22 +293,19 @@ private: "int f2(Fixname& f2v) {\n" " int i = sizeof(f2v);\n" " printf(\"sizeof f2v %d\", i);\n" - " }\n" - ); + " }"); ASSERT_EQUALS("", errout.str()); check("void f(int *p) {\n" " p[0] = 0;\n" " int unused = sizeof(p);\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" " char p[] = \"test\";\n" " int unused = sizeof(p);\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); // ticket #2495 @@ -331,38 +319,33 @@ private: " {1,0,1},\n" " };\n" " const int COL_MAX=sizeof(col)/sizeof(col[0]);\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); // ticket #155 check("void f() {\n" " char buff1[1024*64],buff2[sizeof(buff1)*2];\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); // ticket #2510 check("void f( int a[], int b) {\n" " std::cout << sizeof(a) / sizeof(int) << std::endl;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Using 'sizeof' on array given as " "function argument returns size of a pointer.\n", errout.str()); // ticket #2510 check("void f( int a[3] , int b[2] ) {\n" " std::cout << sizeof(a) / sizeof(int) << std::endl;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Using 'sizeof' on array given as " "function argument returns size of a pointer.\n", errout.str()); // ticket #2510 check("void f() {\n" " char buff1[1024*64],buff2[sizeof(buff1)*(2+1)];\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -370,22 +353,22 @@ private: void sizeofForNumericParameter() { check("void f() {\n" " std::cout << sizeof(10) << std::endl;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter.\n", errout.str()); check("void f() {\n" " std::cout << sizeof(-10) << std::endl;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter.\n", errout.str()); check("void f() {\n" " std::cout << sizeof 10 << std::endl;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter.\n", errout.str()); check("void f() {\n" " std::cout << sizeof -10 << std::endl;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter.\n", errout.str()); } @@ -850,7 +833,7 @@ private: " char x = *((char*)(foo.data+1));\n" " foo.data++;\n" " return x;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (portability) 'foo.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n" "[test.cpp:6]: (portability) 'foo.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str()); @@ -874,7 +857,7 @@ private: "};\n" "void f4(struct BOO* boo) {\n" " char c = *((char*)boo->data.data + 1);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("struct FOO {\n" @@ -882,7 +865,7 @@ private: "};\n" "char f(struct FOO* foo) {\n" " *(foo[1].data + 1) = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (portability) 'foo[1].data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str()); check("struct FOO {\n" @@ -895,7 +878,7 @@ private: // #6050 arithmetic on void** check("void* array[10];\n" - "void** b = array + 3;\n"); + "void** b = array + 3;"); ASSERT_EQUALS("", errout.str()); } @@ -904,7 +887,7 @@ private: check("char strncat ();\n" "int main () {\n" " return strncat ();\n" - "}\n"); + "}"); } }; diff --git a/test/teststl.cpp b/test/teststl.cpp index 64c1f7fea..87ea9d7b9 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -225,7 +225,7 @@ private: checkNormal("void f(std::vector v) {\n" " v.front();\n" " if (v.empty()) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("test.cpp:2:warning:Either the condition 'v.empty()' is redundant or expression 'v.front()' cause access out of bounds.\n" "test.cpp:3:note:condition 'v.empty()'\n" "test.cpp:2:note:Access out of bounds\n", errout.str()); @@ -233,7 +233,7 @@ private: checkNormal("void f(std::vector v) {\n" " if (v.size() == 3) {}\n" " v[16] = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("test.cpp:3:warning:Either the condition 'v.size()==3' is redundant or v size can be 3. Expression 'v[16]' cause access out of bounds.\n" "test.cpp:2:note:condition 'v.size()==3'\n" "test.cpp:3:note:Access out of bounds\n", errout.str()); @@ -243,7 +243,7 @@ private: " if (v.size() == 3) {\n" " v[i] = 0;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("test.cpp:4:warning:Either the condition 'v.size()==3' is redundant or v size can be 3. Expression 'v[i]' cause access out of bounds.\n" "test.cpp:3:note:condition 'v.size()==3'\n" "test.cpp:4:note:Access out of bounds\n", errout.str()); @@ -251,19 +251,19 @@ private: checkNormal("void f(std::vector v, int i) {\n" " if (v.size() == 3 || i == 16) {}\n" " v[i] = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkNormal("void f(std::map x) {\n" " if (x.empty()) { x[1] = 2; }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkNormal("void f(std::string s) {\n" " if (s.size() == 1) {\n" " s[2] = 0;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("test.cpp:3:warning:Either the condition 's.size()==1' is redundant or s size can be 1. Expression 's[2]' cause access out of bounds.\n" "test.cpp:2:note:condition 's.size()==1'\n" "test.cpp:3:note:Access out of bounds\n", errout.str()); @@ -273,47 +273,47 @@ private: " std::string b[];\n" " for (auto c : b)\n" " c.data();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkNormal("std::string f(std::string x) {\n" " if (x.empty()) return {};\n" " x[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkNormal("std::string f(std::string x) {\n" " if (x.empty()) return std::string{};\n" " x[0];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkNormal("void f() {\n" " std::string s;\n" " x = s.begin() + 1;\n" - "}\n"); + "}"); ASSERT_EQUALS("test.cpp:3:error:Out of bounds access in expression 's.begin()+1' because 's' is empty.\n", errout.str()); checkNormal("void f(int x) {\n" " std::string s;\n" " x = s.begin() + x;\n" - "}\n"); + "}"); ASSERT_EQUALS("test.cpp:3:error:Out of bounds access in expression 's.begin()+x' because 's' is empty and 'x' may be non-zero.\n", errout.str()); checkNormal("char fstr1(){const std::string s = \"\"; return s[42]; }\n" - "wchar_t fwstr1(){const std::wstring s = L\"\"; return s[42]; }\n"); + "wchar_t fwstr1(){const std::wstring s = L\"\"; return s[42]; }"); ASSERT_EQUALS("test.cpp:1:error:Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42\n" "test.cpp:2:error:Out of bounds access in 's[42]', if 's' size is 6 and '42' is 42\n", errout.str()); checkNormal("char fstr1(){const std::string s = \"\"; return s[1]; }\n" - "wchar_t fwstr1(){const std::wstring s = L\"\"; return s[1]; }\n"); + "wchar_t fwstr1(){const std::wstring s = L\"\"; return s[1]; }"); ASSERT_EQUALS("", errout.str()); checkNormal("int f() {\n" " std::vector v;\n" " std::vector * pv = &v;\n" " return (*pv)[42];\n" - "}\n"); + "}"); ASSERT_EQUALS("test.cpp:4:error:Out of bounds access in expression '(*pv)[42]' because '*pv' is empty.\n", errout.str()); checkNormal("void f() {\n" @@ -328,14 +328,14 @@ private: " int x = 6;\n" " if(b) ++x;\n" " return s[x];\n" - "}\n"); + "}"); ASSERT_EQUALS("test.cpp:5:error:Out of bounds access in 's[x]', if 's' size is 6 and 'x' is 6\n", errout.str()); checkNormal("void f() {\n" " static const int N = 4;\n" " std::array x;\n" " x[0] = 0;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkNormal("void f(bool b) {\n" @@ -1165,7 +1165,7 @@ private: "};\n" "bool A::B::operator==(const A::B& b) const {\n" " return std::tie(x, y, z) == std::tie(b.x, b.y, b.z);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1173,29 +1173,29 @@ private: // #9556 check("void f(int a, int b) {\n" " if (&a == &b) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int a, int b) {\n" " if (std::for_each(&a, &b + 1, [](auto) {})) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (error) Iterators of different containers 'a' and 'b' are used together.\n", errout.str()); check("void f(int a, int b) {\n" " if (std::for_each(&a, &b, [](auto) {})) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (error) Iterators of different containers 'a' and 'b' are used together.\n", errout.str()); check("void f(int a) {\n" " if (std::for_each(&a, &a, [](auto) {})) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Same iterators expression are used for algorithm.\n", errout.str()); check("void f(int a) {\n" " if (std::for_each(&a, &a + 1, [](auto) {})) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -1208,7 +1208,7 @@ private: " bool operator()(const S& lhs, const S& rhs) const {\n" " return &lhs.v != &rhs.v;\n" " }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); } @@ -1217,21 +1217,21 @@ private: "std::vector& g();\n" "void foo() {\n" " (void)std::find(f().begin(), g().end(), 0);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together.\n", errout.str()); check("std::vector& f();\n" "std::vector& g();\n" "void foo() {\n" " if(f().begin() == g().end()) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together.\n", errout.str()); check("std::vector& f();\n" "std::vector& g();\n" "void foo() {\n" " auto size = f().end() - g().begin();\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together.\n", errout.str()); check("struct A {\n" @@ -1240,7 +1240,7 @@ private: "};\n" "void foo() {\n" " (void)std::find(A().f().begin(), A().g().end(), 0);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (warning) Iterators to containers from different expressions 'A().f()' and 'A().g()' are used together.\n", errout.str()); check("struct A {\n" @@ -1249,14 +1249,14 @@ private: "};\n" "void foo() {\n" " (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (warning) Iterators to containers from different expressions 'A{}.f()' and 'A{}.g()' are used together.\n", errout.str()); check("std::vector& f();\n" "std::vector& g();\n" "void foo() {\n" " (void)std::find(begin(f()), end(g()), 0);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together.\n", errout.str()); check("struct A {\n" @@ -1265,14 +1265,14 @@ private: "};\n" "void foo() {\n" " (void)std::find(A().f().begin(), A().f().end(), 0);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::vector& f();\n" "std::vector& g();\n" "void foo() {\n" " if(bar(f().begin()) == g().end()) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::vector& f();\n" @@ -1297,7 +1297,7 @@ private: " (void)std::find(begin(f()) + 1, end(f()), 0);\n" " (void)std::find(begin(f()), end(f()) - 1, 0);\n" " (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("std::vector& f();\n" @@ -1307,65 +1307,65 @@ private: " if(f().begin() == f().end()+1) {}\n" " if(f().begin()+1 == f().end()) {}\n" " if(f().begin()+1 == f().end()+1) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("template\n" "std::vector& f();\n" "void foo() {\n" " if(f<1>().begin() == f<1>().end()) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" " if (a.begin().x == b.begin().x) {}\n" " if (begin(a).x == begin(b).x) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(std::list a, std::list b) {\n" " if (*a.begin() == *b.begin()) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void foo() {\n" " if(f().begin(1) == f().end()) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } void iteratorSameExpression() { check("void f(std::vector v) {\n" " std::for_each(v.begin(), v.begin(), [](int){});\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Same iterators expression are used for algorithm.\n", errout.str()); check("std::vector& g();\n" "void f() {\n" " std::for_each(g().begin(), g().begin(), [](int){});\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Same iterators expression are used for algorithm.\n", errout.str()); check("void f(std::vector v) {\n" " std::for_each(v.end(), v.end(), [](int){});\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Same iterators expression are used for algorithm.\n", errout.str()); check("std::vector& g();\n" "void f() {\n" " std::for_each(g().end(), g().end(), [](int){});\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Same iterators expression are used for algorithm.\n", errout.str()); check("std::vector::iterator g();\n" "void f(std::vector v) {\n" " std::for_each(g(), g(), [](int){});\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Same iterators expression are used for algorithm.\n", errout.str()); check("void f(std::vector::iterator it) {\n" " std::for_each(it, it, [](int){});\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Same iterators expression are used for algorithm.\n", errout.str()); } @@ -1374,13 +1374,13 @@ private: " std::vector a, b;\n" " a.insert(b.end(), value);\n" " return a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Iterator 'b.end()' from different container 'a' are used together.\n", errout.str()); check("std::vector f(std::vector a, std::vector b) {\n" " a.erase(b.begin());\n" " return a;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (error) Iterator 'b.begin()' from different container 'a' are used together.\n", errout.str()); // #9973 @@ -1643,7 +1643,7 @@ private: " return a[x - 5];\n" " else\n" " return a[4 - x];\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3504,8 +3504,8 @@ private: " x < vector < EffectivityRangeData> >();\n" " EffectivityRange er;\n" " }\n" - " void shift() { EffectivityRangeData::iterator it; } \n" - "};\n"); + " void shift() { EffectivityRangeData::iterator it; }\n" + "};"); ASSERT_EQUALS("", errout.str()); } @@ -3515,7 +3515,7 @@ private: " if (std::isalpha(*i) && i != str.end()) {\n" " std::cout << *i;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout.str()); check("void foo(std::string::iterator& i) {\n" @@ -3523,7 +3523,7 @@ private: " else if (std::isalpha(*i) && i != str.end()) {\n" " std::cout << *i;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (warning) Possible dereference of an invalid iterator: i\n", errout.str()); // Test suggested correction doesn't report an error @@ -3531,7 +3531,7 @@ private: " if (i != str.end() && std::isalpha(*i)) {\n" " std::cout << *i;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Test "while" with "&&" case @@ -3540,7 +3540,7 @@ private: " std::cout << *i;\n" " i ++;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout.str()); check("void foo(std::string::iterator& i) {\n" @@ -3548,7 +3548,7 @@ private: " std::cout << *i;\n" " i ++;\n" " } while (std::isalpha(*i) && i != str.end());\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (warning) Possible dereference of an invalid iterator: i\n", errout.str()); // Test "while" with "||" case @@ -3557,7 +3557,7 @@ private: " std::cout << *i;\n" " i ++;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout.str()); // Test fix for "while" with "||" case @@ -3566,7 +3566,7 @@ private: " std::cout << *i;\n" " i ++;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Test "for" with "&&" case @@ -3575,7 +3575,7 @@ private: " std::cout << *i;\n" " i ++;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout.str()); // Test "for" with "||" case @@ -3584,7 +3584,7 @@ private: " std::cout << *i;\n" " i ++;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout.str()); // Test that a dereference outside the condition part of a "for" @@ -3594,7 +3594,7 @@ private: " std::cout << c;\n" " i ++;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Test that other "&&" terms in the condition don't invalidate the check @@ -3602,7 +3602,7 @@ private: " if (*c && std::isalpha(*i) && i != str.end()) {\n" " std::cout << *i;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout.str()); // Test that dereference of different variable doesn't trigger a false positive @@ -3610,7 +3610,7 @@ private: " if (std::isalpha(*c) && i != str.end()) {\n" " std::cout << *c;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // Test case involving "rend()" instead of "end()" @@ -3619,7 +3619,7 @@ private: " std::cout << *i;\n" " i ++;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout.str()); // Test that mixed "&&" and "||" don't result in a false positive @@ -3627,7 +3627,7 @@ private: " if ((i == str.end() || *i) || (isFoo() && i != str.end())) {\n" " std::cout << \"foo\";\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f() {\n" @@ -3783,11 +3783,11 @@ private: " ++m_ptr.m_place;\n" " return *this;\n" " }\n" - " }; \n" + " };\n" " iterator begin() {\n" - " iterator it; \n" + " iterator it;\n" " it->m_place = 0;\n" - " return it; \n" + " return it;\n" "}\n", true); ASSERT_EQUALS("[test.cpp:18]: (error, inconclusive) Invalid iterator 'it' used.\n", errout.str()); } @@ -4045,7 +4045,7 @@ private: "void foo() {\n" " for(int& x:v) {\n" " if (pred(x)) {\n" - " x = 1; \n" + " x = 1;\n" " }\n" " }\n" "}\n", @@ -4057,7 +4057,7 @@ private: " int n = 0;\n" " for(int x:v) {\n" " if (pred(x)) {\n" - " n += x; \n" + " n += x;\n" " }\n" " }\n" "}\n", @@ -4069,7 +4069,7 @@ private: " int n = 0;\n" " for(int x:v) {\n" " if (pred(x)) {\n" - " n += 1; \n" + " n += 1;\n" " }\n" " }\n" "}\n", @@ -4081,7 +4081,7 @@ private: " int n = 0;\n" " for(int x:v) {\n" " if (pred(x)) {\n" - " n++; \n" + " n++;\n" " }\n" " }\n" "}\n", @@ -4092,7 +4092,7 @@ private: "void foo() {\n" " for(int& x:v) {\n" " if (pred(x)) {\n" - " x = x + 1; \n" + " x = x + 1;\n" " }\n" " }\n" "}\n", @@ -4104,7 +4104,7 @@ private: " std::vector c;\n" " for(int x:v) {\n" " if (pred(x)) {\n" - " c.push_back(x); \n" + " c.push_back(x);\n" " }\n" " }\n" "}\n", @@ -4115,7 +4115,7 @@ private: "bool foo() {\n" " for(int x:v) {\n" " if (pred(x)) {\n" - " return false; \n" + " return false;\n" " }\n" " }\n" " return true;\n" @@ -4127,7 +4127,7 @@ private: "bool foo() {\n" " for(int x:v) {\n" " if (pred(x)) {\n" - " break; \n" + " break;\n" " }\n" " }\n" " return true;\n" @@ -4140,8 +4140,8 @@ private: "void foo() {\n" " for(int x:v) {\n" " if (pred(x)) {\n" - " f(); \n" - " break; \n" + " f();\n" + " break;\n" " }\n" " }\n" "}\n", @@ -4153,8 +4153,8 @@ private: "void foo() {\n" " for(int x:v) {\n" " if (pred(x)) {\n" - " f(x); \n" - " break; \n" + " f(x);\n" + " break;\n" " }\n" " }\n" "}\n", @@ -4205,7 +4205,7 @@ private: "bool foo() {\n" " for(int x:v) {\n" " if (pred(x)) {\n" - " return false; \n" + " return false;\n" " }\n" " return true;\n" " }\n" @@ -4219,7 +4219,7 @@ private: " std::vector c;\n" " for(int x:v) {\n" " if (pred(x)) {\n" - " c.push_back(x + 1); \n" + " c.push_back(x + 1);\n" " }\n" " }\n" "}\n", @@ -4231,7 +4231,7 @@ private: " for(int& x:v) {\n" " x++;\n" " if (pred(x)) {\n" - " x = 1; \n" + " x = 1;\n" " }\n" " }\n" "}\n", @@ -4244,7 +4244,7 @@ private: " for(int x:v) {\n" " if (pred(x)) {\n" " if(x) { return; }\n" - " break; \n" + " break;\n" " }\n" " }\n" "}\n", diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index c13bd7c54..73eb80d39 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -710,7 +710,7 @@ private: "_asm\n" "{\n" " // cppcheck-suppress syntaxError\n" - " push EAX ; save EAX for callers \n" + " push EAX ; save EAX for callers\n" " mov EAX,Real10 ; get the address pointed to by Real10\n" " fld TBYTE PTR [EAX] ; load an extended real (10 bytes)\n" " fstp QWORD PTR result ; store a double (8 bytes)\n" diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index cdc7c0cbf..186765b46 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -922,7 +922,7 @@ private: void VariableValueType1() { GET_SYMBOL_DB("typedef uint8_t u8;\n" - "static u8 x;\n"); + "static u8 x;"); const Variable* x = db->getVariableFromVarId(1); ASSERT_EQUALS("x", x->name()); ASSERT(x->valueType()->isIntegral()); @@ -930,7 +930,7 @@ private: void VariableValueType2() { GET_SYMBOL_DB("using u8 = uint8_t;\n" - "static u8 x;\n"); + "static u8 x;"); const Variable* x = db->getVariableFromVarId(1); ASSERT_EQUALS("x", x->name()); ASSERT(x->valueType()->isIntegral()); @@ -939,7 +939,7 @@ private: void VariableValueType3() { // std::string::size_type { - GET_SYMBOL_DB("void f(std::string::size_type x);\n"); + GET_SYMBOL_DB("void f(std::string::size_type x);"); const Variable* const x = db->getVariableFromVarId(1); ASSERT_EQUALS("x", x->name()); // TODO: Configure std::string::size_type somehow. @@ -948,7 +948,7 @@ private: } // std::wstring::size_type { - GET_SYMBOL_DB("void f(std::wstring::size_type x);\n"); + GET_SYMBOL_DB("void f(std::wstring::size_type x);"); const Variable* const x = db->getVariableFromVarId(1); ASSERT_EQUALS("x", x->name()); // TODO: Configure std::wstring::size_type somehow. @@ -957,7 +957,7 @@ private: } // std::u16string::size_type { - GET_SYMBOL_DB("void f(std::u16string::size_type x);\n"); + GET_SYMBOL_DB("void f(std::u16string::size_type x);"); const Variable* const x = db->getVariableFromVarId(1); ASSERT_EQUALS("x", x->name()); // TODO: Configure std::u16string::size_type somehow. @@ -966,7 +966,7 @@ private: } // std::u32string::size_type { - GET_SYMBOL_DB("void f(std::u32string::size_type x);\n"); + GET_SYMBOL_DB("void f(std::u32string::size_type x);"); const Variable* const x = db->getVariableFromVarId(1); ASSERT_EQUALS("x", x->name()); // TODO: Configure std::u32string::size_type somehow. @@ -988,7 +988,7 @@ private: void VariableValueType5() { GET_SYMBOL_DB("class C {};\n" - "void foo(std::shared_ptr* p) {}\n"); + "void foo(std::shared_ptr* p) {}"); const Variable* const p = db->getVariableFromVarId(1); ASSERT(p->valueType()); @@ -1294,7 +1294,7 @@ private: void variableVolatile() { GET_SYMBOL_DB("std::atomic x;\n" - "volatile int y;\n"); + "volatile int y;"); const Token *x = Token::findsimplematch(tokenizer.tokens(), "x"); ASSERT(x); @@ -1395,7 +1395,7 @@ private: void getVariableFromVarIdBoundsCheck() { GET_SYMBOL_DB("int x;\n" - "int y;\n"); + "int y;"); const Variable* v = db->getVariableFromVarId(2); // three elements: varId 0 also counts via a fake-entry @@ -1405,7 +1405,7 @@ private: } void hasRegularFunction() { - GET_SYMBOL_DB("void func() { }\n"); + GET_SYMBOL_DB("void func() { }"); // 2 scopes: Global and Function ASSERT(db && db->scopeList.size() == 2); @@ -1447,7 +1447,7 @@ private: } void hasInlineClassFunction() { - GET_SYMBOL_DB("class Fred { void func() { } };\n"); + GET_SYMBOL_DB("class Fred { void func() { } };"); // 3 scopes: Global, Class, and Function ASSERT(db && db->scopeList.size() == 3); @@ -1498,7 +1498,7 @@ private: } void hasMissingInlineClassFunction() { - GET_SYMBOL_DB("class Fred { void func(); };\n"); + GET_SYMBOL_DB("class Fred { void func(); };"); // 2 scopes: Global and Class (no Function scope because there is no function implementation) ASSERT(db && db->scopeList.size() == 2); @@ -1542,7 +1542,7 @@ private: } void hasClassFunction() { - GET_SYMBOL_DB("class Fred { void func(); }; void Fred::func() { }\n"); + GET_SYMBOL_DB("class Fred { void func(); }; void Fred::func() { }"); // 3 scopes: Global, Class, and Function ASSERT(db && db->scopeList.size() == 3); @@ -1564,7 +1564,7 @@ private: } void hasClassFunction_trailingReturnType() { - GET_SYMBOL_DB("class Fred { auto func() -> int; }; auto Fred::func() -> int { }\n"); + GET_SYMBOL_DB("class Fred { auto func() -> int; }; auto Fred::func() -> int { }"); // 3 scopes: Global, Class, and Function ASSERT(db && db->scopeList.size() == 3); @@ -1586,7 +1586,7 @@ private: } void hasRegularFunctionReturningFunctionPointer() { - GET_SYMBOL_DB("void (*func(int f))(char) { }\n"); + GET_SYMBOL_DB("void (*func(int f))(char) { }"); // 2 scopes: Global and Function ASSERT(db && db->scopeList.size() == 2); @@ -1605,7 +1605,7 @@ private: } void hasInlineClassFunctionReturningFunctionPointer() { - GET_SYMBOL_DB("class Fred { void (*func(int f))(char) { } };\n"); + GET_SYMBOL_DB("class Fred { void (*func(int f))(char) { } };"); // 3 scopes: Global, Class, and Function ASSERT(db && db->scopeList.size() == 3); @@ -1624,7 +1624,7 @@ private: } void hasMissingInlineClassFunctionReturningFunctionPointer() { - GET_SYMBOL_DB("class Fred { void (*func(int f))(char); };\n"); + GET_SYMBOL_DB("class Fred { void (*func(int f))(char); };"); // 2 scopes: Global and Class (no Function scope because there is no function implementation) ASSERT(db && db->scopeList.size() == 2); @@ -1643,7 +1643,7 @@ private: } void hasClassFunctionReturningFunctionPointer() { - GET_SYMBOL_DB("class Fred { void (*func(int f))(char); }; void (*Fred::func(int f))(char) { }\n"); + GET_SYMBOL_DB("class Fred { void (*func(int f))(char); }; void (*Fred::func(int f))(char) { }"); // 3 scopes: Global, Class, and Function ASSERT(db && db->scopeList.size() == 3); @@ -1662,7 +1662,7 @@ private: } void methodWithRedundantScope() { - GET_SYMBOL_DB("class Fred { void Fred::func() {} };\n"); + GET_SYMBOL_DB("class Fred { void Fred::func() {} };"); // 3 scopes: Global, Class, and Function ASSERT(db && db->scopeList.size() == 3); @@ -1971,7 +1971,7 @@ private: void parseFunctionCorrect() { // ticket 3188 - "if" statement parsed as function - GET_SYMBOL_DB("void func(i) int i; { if (i == 1) return; }\n"); + GET_SYMBOL_DB("void func(i) int i; { if (i == 1) return; }"); ASSERT(db != nullptr); // 3 scopes: Global, function, if @@ -1998,7 +1998,7 @@ private: } void hasGlobalVariables1() { - GET_SYMBOL_DB("int i;\n"); + GET_SYMBOL_DB("int i;"); ASSERT(db && db->scopeList.size() == 1); @@ -2010,7 +2010,7 @@ private: } void hasGlobalVariables2() { - GET_SYMBOL_DB("int array[2][2];\n"); + GET_SYMBOL_DB("int array[2][2];"); ASSERT(db && db->scopeList.size() == 1); @@ -2023,7 +2023,7 @@ private: } void hasGlobalVariables3() { - GET_SYMBOL_DB("int array[2][2] = { { 0, 0 }, { 0, 0 } };\n"); + GET_SYMBOL_DB("int array[2][2] = { { 0, 0 }, { 0, 0 } };"); ASSERT(db && db->scopeList.size() == 1); @@ -2215,7 +2215,7 @@ private: "int foo(struct AB *ab);\n" "void bar() {\n" " struct AB ab;\n" - " foo(&ab); \n" + " foo(&ab);\n" "};"); ASSERT_EQUALS(true, db != nullptr); const Token *f = Token::findsimplematch(tokenizer.tokens(), "foo ( & ab"); @@ -2230,7 +2230,7 @@ private: "int foo(AB *ab);\n" "void bar() {\n" " struct AB ab;\n" - " foo(&ab); \n" + " foo(&ab);\n" "};"); ASSERT_EQUALS(true, db != nullptr); const Token *f = Token::findsimplematch(tokenizer.tokens(), "foo ( & ab"); @@ -2245,7 +2245,7 @@ private: "int foo(struct AB *ab);\n" "void bar() {\n" " AB ab;\n" - " foo(&ab); \n" + " foo(&ab);\n" "};"); ASSERT_EQUALS(true, db != nullptr); const Token *f = Token::findsimplematch(tokenizer.tokens(), "foo ( & ab"); @@ -2260,7 +2260,7 @@ private: "int foo(AB *ab);\n" "void bar() {\n" " AB ab;\n" - " foo(&ab); \n" + " foo(&ab);\n" "};"); ASSERT_EQUALS(true, db != nullptr); const Token *f = Token::findsimplematch(tokenizer.tokens(), "foo ( & ab"); @@ -2598,7 +2598,7 @@ private: check("static void function_declaration_before(void) __attribute__((__used__));\n" "static void function_declaration_before(void) {}\n" "static void function_declaration_after(void) {}\n" - "static void function_declaration_after(void) __attribute__((__used__));\n"); + "static void function_declaration_after(void) __attribute__((__used__));"); ASSERT_EQUALS("", errout.str()); check("main(int argc, char *argv[]) { }", true, "test.c"); @@ -2769,7 +2769,7 @@ private: // ticket 3437 (segmentation fault) void symboldatabase22() { check("template struct A {};\n" - "A a;\n"); + "A a;"); ASSERT_EQUALS("", errout.str()); } @@ -2898,7 +2898,7 @@ private: "::Foo::Sub::Sub() { }\n" "class Foo;\n" "class Bar;\n" - "class Sub;\n"); + "class Sub;"); ASSERT(db && db->typeList.size() == 5); std::list::const_iterator i = db->typeList.begin(); @@ -2966,7 +2966,7 @@ private: " Fred(const struct Barney & b) { barney = b; }\n" "private:\n" " struct Barney barney;\n" - "};\n"); + "};"); ASSERT(db && db->typeList.size() == 3); std::list::const_iterator i = db->typeList.begin(); @@ -2999,17 +2999,17 @@ private: check("void f() {\n" " try { }\n" " catch (std::bad_alloc) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } void symboldatabase41() { // ticket #5197 (unknown macro) - GET_SYMBOL_DB("struct X1 { MACRO1 f(int spd) MACRO2; };\n"); + GET_SYMBOL_DB("struct X1 { MACRO1 f(int spd) MACRO2; };"); ASSERT(db && db->findScopeByName("X1") && db->findScopeByName("X1")->functionList.size() == 1 && !db->findScopeByName("X1")->functionList.front().hasBody()); } void symboldatabase42() { // only put variables in variable list - GET_SYMBOL_DB("void f() { extern int x(); }\n"); + GET_SYMBOL_DB("void f() { extern int x(); }"); ASSERT(db != nullptr); const Scope * const fscope = db ? db->findScopeByName("f") : nullptr; ASSERT(fscope != nullptr); @@ -3019,7 +3019,7 @@ private: void symboldatabase43() { // ticket #4738 check("void f() {\n" " new int;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3111,7 +3111,7 @@ private: "}\n" "using namespace NS;\n" "MyClass::~MyClass() { }\n" - "MyClass::MyClass() { }\n"); + "MyClass::MyClass() { }"); ASSERT(db && !db->functionScopes.empty() && db->functionScopes.front()->function && db->functionScopes.front()->function->functionScope == db->functionScopes.front()); const Token *f = Token::findsimplematch(tokenizer.tokens(), "MyClass ( ) ;"); @@ -3126,7 +3126,7 @@ private: GET_SYMBOL_DB("namespace Ns { class C; }\n" "void f1() { char *p; *p = 0; }\n" "class Ns::C* p;\n" - "void f2() { char *p; *p = 0; }\n"); + "void f2() { char *p; *p = 0; }"); ASSERT(db != nullptr); const Token *f = Token::findsimplematch(tokenizer.tokens(), "p ; void f2"); ASSERT_EQUALS(true, db && f && f->variable()); @@ -3163,7 +3163,7 @@ private: "static const float f3 = 2 * std::foo3(a, b);\n" "static const float f4 = c * foo4(a, b);\n" "static const int i1 = 2 & foo5(a, b);\n" - "static const bool b1 = 2 > foo6(a, b);\n"); + "static const bool b1 = 2 > foo6(a, b);"); ASSERT(db != nullptr); ASSERT(findFunctionByName("foo1", &db->scopeList.front()) == nullptr); ASSERT(findFunctionByName("foo2", &db->scopeList.front()) == nullptr); @@ -3248,7 +3248,7 @@ private: } { GET_SYMBOL_DB_C("friend f1();\n" - "friend f2() { }\n"); + "friend f2() { }"); ASSERT(db != nullptr); ASSERT_EQUALS(2U, db->scopeList.size()); @@ -3816,7 +3816,7 @@ private: " ~impl() { }\n" " impl(const impl &) { }\n" " void foo(const impl &, const impl &) const { }\n" - "};\n"); + "};"); ASSERT(db != nullptr); ASSERT(db && db->scopeList.size() == 7); @@ -3859,7 +3859,7 @@ private: "template Fred::impl::impl() { }\n" "template Fred::impl::~impl() { }\n" "template Fred::impl::impl(const Fred::impl &) { }\n" - "template void Fred::impl::foo(const Fred::impl &, const Fred::impl &) const { }\n"); + "template void Fred::impl::foo(const Fred::impl &, const Fred::impl &) const { }"); ASSERT(db != nullptr); ASSERT(db && db->scopeList.size() == 7); @@ -3990,7 +3990,7 @@ private: "template NS::Fred::impl::impl() { }\n" "template NS::Fred::impl::~impl() { }\n" "template NS::Fred::impl::impl(const NS::Fred::impl &) { }\n" - "template void NS::Fred::impl::foo(const NS::Fred::impl &, const NS::Fred::impl &) const { }\n"); + "template void NS::Fred::impl::foo(const NS::Fred::impl &, const NS::Fred::impl &) const { }"); ASSERT(db != nullptr); ASSERT(db && db->scopeList.size() == 8); @@ -4076,7 +4076,7 @@ private: "template NS::Fred::impl::impl() { }\n" "template NS::Fred::impl::~impl() { }\n" "template NS::Fred::impl::impl(const NS::Fred::impl &) { }\n" - "template void NS::Fred::impl::foo(const NS::Fred::impl &, const NS::Fred::impl &) const { }\n"); + "template void NS::Fred::impl::foo(const NS::Fred::impl &, const NS::Fred::impl &) const { }"); ASSERT(db != nullptr); ASSERT(db && db->scopeList.size() == 8); @@ -4169,7 +4169,7 @@ private: "template Fred::impl::impl() { }\n" "template Fred::impl::~impl() { }\n" "template Fred::impl::impl(const Fred::impl &) { }\n" - "template void Fred::impl::foo(const Fred::impl &, const Fred::impl &) const { }\n"); + "template void Fred::impl::foo(const Fred::impl &, const Fred::impl &) const { }"); ASSERT(db != nullptr); ASSERT(db && db->scopeList.size() == 8); @@ -4822,7 +4822,7 @@ private: "int b[A];\n" "int c[A + 2];\n" "int d[10 + B];\n" - "int e[A + B];\n"); + "int e[A + B];"); ASSERT(db != nullptr); ASSERT_EQUALS(2U, db->scopeList.size()); @@ -4916,7 +4916,7 @@ private: "char array9[sizeof(EL)];\n" "char array10[sizeof(L)];\n" "char array11[sizeof(ELL)];\n" - "char array12[sizeof(LL)];\n"); + "char array12[sizeof(LL)];"); ASSERT(db != nullptr); ASSERT(db->variableList().size() == 13); // the first one is not used @@ -5419,7 +5419,7 @@ private: "void S::g() &&{ }\n" "void S::g() const { }\n" "void S::g() const & { }\n" - "void S::g() const &&{ }\n"); + "void S::g() const &&{ }"); ASSERT_EQUALS("", errout.str()); const Token *f = Token::findsimplematch(tokenizer.tokens(), "f ( ) {"); @@ -6463,7 +6463,7 @@ private: GET_SYMBOL_DB("void func1() noexcept;\n" "void func2() noexcept { }\n" "void func3() noexcept(true);\n" - "void func4() noexcept(true) { }\n"); + "void func4() noexcept(true) { }"); ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS(true, db != nullptr); // not null @@ -6474,7 +6474,7 @@ private: } void noexceptFunction2() { - GET_SYMBOL_DB("template void self_assign(T& t) noexcept(noexcept(t = t)) {t = t; }\n"); + GET_SYMBOL_DB("template void self_assign(T& t) noexcept(noexcept(t = t)) {t = t; }"); ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS(true, db != nullptr); // not null @@ -6535,7 +6535,7 @@ private: " A a;\n" " B(B&& b) noexcept\n" " :a(std::move(b.a)) { }\n" - "};\n"); + "};"); ASSERT_EQUALS("", errout.str()); ASSERT(db != nullptr); // not null const Scope *b = db->findScopeByName("B"); @@ -6553,7 +6553,7 @@ private: GET_SYMBOL_DB("void func1() throw();\n" "void func2() throw() { }\n" "void func3() throw(int);\n" - "void func4() throw(int) { }\n"); + "void func4() throw(int) { }"); ASSERT_EQUALS("", errout.str()); ASSERT(db != nullptr); // not null @@ -6604,7 +6604,7 @@ private: void nothrowAttributeFunction() { GET_SYMBOL_DB("void func() __attribute__((nothrow));\n" - "void func() { }\n"); + "void func() { }"); ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS(true, db != nullptr); // not null @@ -6614,7 +6614,7 @@ private: } void nothrowDeclspecFunction() { - GET_SYMBOL_DB("void __declspec(nothrow) func() { }\n"); + GET_SYMBOL_DB("void __declspec(nothrow) func() { }"); ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS(true, db != nullptr); // not null @@ -6847,7 +6847,7 @@ private: GET_SYMBOL_DB("class Fred {\n" " void foo(const std::string & a = \"\");\n" "};\n" - "Fred::foo(const std::string & b) { }\n"); + "Fred::foo(const std::string & b) { }"); ASSERT(db && db->scopeList.size() == 3); std::list::const_iterator scope = db->scopeList.begin(); diff --git a/test/testtoken.cpp b/test/testtoken.cpp index 26a2740cd..ce6e1acac 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -1083,7 +1083,7 @@ private: } void canFindMatchingBracketsWithTooManyClosing() const { - givenACodeSampleToTokenize var("X< 1>2 > x1;\n"); + givenACodeSampleToTokenize var("X< 1>2 > x1;"); const Token* const t = var.tokens()->next()->findClosingBracket(); ASSERT_EQUALS(">", t->str()); @@ -1091,7 +1091,7 @@ private: } void canFindMatchingBracketsWithTooManyOpening() const { - givenACodeSampleToTokenize var("X < (2 < 1) > x1;\n"); + givenACodeSampleToTokenize var("X < (2 < 1) > x1;"); const Token* t = var.tokens()->next()->findClosingBracket(); ASSERT(t != nullptr && t->str() == ">"); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 96a9df28a..c5c2f7707 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -3295,7 +3295,7 @@ private: "{}\n"), InternalError); tokenizeAndStringify("void foo(int, int)\n" - "{}\n"); + "{}"); ASSERT_EQUALS("", errout.str()); // #3848 - Don't hang diff --git a/test/testtype.cpp b/test/testtype.cpp index 4a121a09a..c31bb2451 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -171,7 +171,7 @@ private: " if (k > 32)\n" " return 0;\n" " return rm>> k;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:4] -> [test.cpp:6]: (warning) Shifting signed 32-bit value by 31 bits is undefined behaviour. See condition at line 4.\n", errout.str()); @@ -183,7 +183,7 @@ private: " return 0;\n" " else\n" " return rm>> k;\n" - "}\n"); + "}"); ASSERT_EQUALS( "[test.cpp:4] -> [test.cpp:7]: (warning) Shifting signed 32-bit value by 31 bits is undefined behaviour. See condition at line 4.\n", errout.str()); @@ -195,14 +195,14 @@ private: " return 0;\n" " else\n" " return rm>> k;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("static long long f(int x, long long y) {\n" " if (x >= 64)\n" " return 0;\n" " return -(y << (x-1));\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -258,7 +258,7 @@ private: check("unsigned int dostuff(int x) {\n" // x is signed " if (x==0) {}\n" " return (x-1)*sizeof(int);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Expression 'x-1' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation.\n", errout.str()); check("unsigned int f1(signed int x, unsigned int y) {" // x is signed @@ -360,27 +360,27 @@ private: check("void f(void) {\n" " return (int)1E100;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str())); check("void f(void) {\n" " return (int)-1E100;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str())); check("void f(void) {\n" " return (short)1E6;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str())); check("void f(void) {\n" " return (unsigned char)256.0;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str())); check("void f(void) {\n" " return (unsigned char)255.5;\n" - "}\n"); + "}"); ASSERT_EQUALS("", removeFloat(errout.str())); check("void f(void) {\n" diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 755ef4f5a..889a118a4 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1586,7 +1586,7 @@ private: " vertices[i][1][2] = 4.0;\n" " vertices[i][1][3] = 5.0;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: vertices\n", errout.str()); } @@ -1778,10 +1778,10 @@ private: // #7623 - new can also initialize the memory, don't warn in this case checkUninitVar("void foo(){\n" - " int* p1 = new int(314); \n" - " int* p2 = new int(); \n" - " int* arr = new int[5](); \n" - " std::cout << *p1 << *p2 << arr[0]; \n" + " int* p1 = new int(314);\n" + " int* p2 = new int();\n" + " int* arr = new int[5]();\n" + " std::cout << *p1 << *p2 << arr[0];\n" "}"); ASSERT_EQUALS("", errout.str()); @@ -3184,7 +3184,7 @@ private: " struct AB ab;\n" " ab.a = 0;\n" " do_something(ab);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("struct AB { int a; int b; };\n" @@ -3389,7 +3389,7 @@ private: " struct AB ab;\n" " ab.set();\n" " x = ab;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); checkUninitVar("struct AB { int a; int get() const; };\n" @@ -3397,7 +3397,7 @@ private: " struct AB ab;\n" " ab.get();\n" " x = ab;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized struct member: ab.a\n", errout.str()); checkUninitVar("struct AB { int a; void dostuff() {} };\n" @@ -3405,7 +3405,7 @@ private: " struct AB ab;\n" " ab.dostuff();\n" " x = ab;\n" - "}\n"); + "}"); TODO_ASSERT_EQUALS("error", "", errout.str()); } @@ -4055,10 +4055,10 @@ private: void trac_5970() { // Ticket #5970 checkUninitVar("void DES_ede3_ofb64_encrypt() {\n" - " DES_cblock d; \n" - " char *dp; \n" - " dp=(char *)d; \n" - " init(dp); \n" + " DES_cblock d;\n" + " char *dp;\n" + " dp=(char *)d;\n" + " init(dp);\n" "}", "test.c"); ASSERT_EQUALS("", errout.str()); } @@ -4419,7 +4419,7 @@ private: " int i;\n" " int* v = &i;\n" " sscanf(\"0\", \"%d\", v);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); valueFlowUninit("void test(int p) {\n" @@ -4428,7 +4428,7 @@ private: " f = 0;\n" " if (p > 1)\n" " f += 1;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); valueFlowUninit("unsigned char get();\n" @@ -4479,17 +4479,17 @@ private: "void f(void) {\n" " someType_t gVar;\n" " bar(&gVar);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:5]: (error) Uninitialized variable: flags\n", errout.str()); - valueFlowUninit("typedef struct \n" + valueFlowUninit("typedef struct\n" "{\n" " int flags[3];\n" "} someType_t;\n" "void f(void) {\n" " someType_t gVar;\n" " if(gVar.flags[1] == 42){}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: flags\n", errout.str()); valueFlowUninit("struct pc_data {\n" @@ -4500,7 +4500,7 @@ private: "void f() {\n" " struct pc_data *pcdata;\n" " if ( *pcdata->wampiryzm.strefa == '\\0' ) { }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: pcdata\n", errout.str()); // # 9293 @@ -4512,8 +4512,8 @@ private: "void f() {\n" " struct S s1;\n" " int * x = &s1.x;\n" - " struct S s2 = {*x, 0}; \n" - "}\n"); + " struct S s2 = {*x, 0};\n" + "}"); ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:9]: (error) Uninitialized variable: *x\n", errout.str()); valueFlowUninit("struct S {\n" @@ -4525,8 +4525,8 @@ private: " struct S s1;\n" " struct S s2;\n" " int * x = &s1.x;\n" - " s2.x = *x; \n" - "}\n"); + " s2.x = *x;\n" + "}"); ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:10]: (error) Uninitialized variable: *x\n", errout.str()); valueFlowUninit("void f(bool * x) {\n" @@ -4535,7 +4535,7 @@ private: "void g() {\n" " bool b;\n" " f(&b);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); valueFlowUninit("void f(bool * x) {\n" @@ -4545,7 +4545,7 @@ private: "void g() {\n" " bool x;\n" " f(&x);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); valueFlowUninit("void f() {\n" @@ -4553,7 +4553,7 @@ private: " bool * x = &b;\n" " if (x != nullptr)\n" " x = 1;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); valueFlowUninit("struct A { bool b; };" @@ -4563,14 +4563,14 @@ private: "void g() {\n" " A b;\n" " f(&b);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); valueFlowUninit("std::string f() {\n" " std::ostringstream ostr;\n" " ostr << \"\";\n" " return ostr.str();\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // #9281 valueFlowUninit("struct s {\n" @@ -4585,7 +4585,7 @@ private: "void a() {\n" " struct s s1;\n" " b(&s1);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // # 9290 @@ -4596,7 +4596,7 @@ private: " A * c;\n" " c->x = 42;\n" " return c->x;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: c\n" "[test.cpp:7]: (error) Uninitialized variable: c\n", errout.str()); @@ -4608,7 +4608,7 @@ private: " A c;\n" " c.x = 42;\n" " return c.x;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); valueFlowUninit("struct A {\n" @@ -4621,7 +4621,7 @@ private: "double b() {\n" " A c;\n" " return d(&c);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // # 9302 @@ -4634,7 +4634,7 @@ private: " vz.typ = 42;\n" " if (pvz->typ == 0)\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // # 9305 @@ -4650,7 +4650,7 @@ private: " set( pb);\n" " if (pb->x)\n" " return;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // # 9348 @@ -4661,7 +4661,7 @@ private: "void g() {\n" " int i;\n" " f(&i);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // # 9631 @@ -4672,7 +4672,7 @@ private: " size_t bytesCopied;\n" " bool copied_all = true;\n" " g(&copied_all, 5, 6, &bytesCopied);\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:2]: (error) Uninitialized variable: *buflen\n", errout.str()); } @@ -4684,7 +4684,7 @@ private: "void f() {\n" " C *c;\n" " if (c->x() == 4) {}\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: c\n", errout.str()); } @@ -4696,7 +4696,7 @@ private: "int main() {\n" " Foo* foo;\n" " foo->b\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: foo\n", errout.str()); } diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index 9adda49df..416c98449 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -226,7 +226,7 @@ private: "private:\n" " template void foo( T t ) const;\n" "};\n" - "template void X::foo( T t ) const { }\n"); + "template void X::foo( T t ) const { }"); ASSERT_EQUALS("[test.cpp:3]: (style) The function 'bar' is never used.\n", errout.str()); } @@ -257,19 +257,19 @@ private: void unusedError() { check("void foo() {}\n" - "int main()\n"); + "int main()"); ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str()); check("void foo() const {}\n" - "int main()\n"); + "int main()"); ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str()); check("void foo() const throw() {}\n" - "int main()\n"); + "int main()"); ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str()); check("void foo() throw() {}\n" - "int main()\n"); + "int main()"); ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str()); } @@ -427,7 +427,7 @@ private: void lineNumber() { check("void foo() {}\n" "void bar() {}\n" - "int main()\n"); + "int main()"); ASSERT_EQUALS("[test.cpp:2]: (style) The function 'bar' is never used.\n" "[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str()); } @@ -486,7 +486,7 @@ private: "A operator ++ (const A &){ return A(); }\n" "A operator -- (const A &, const int){ return A(); }\n" "A operator -- (const A &){ return A(); }\n" - "A operator , (const A &, const A &){ return A(); }\n"); + "A operator , (const A &, const A &){ return A(); }"); ASSERT_EQUALS("", errout.str()); diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index a365ae695..d4add33a3 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -416,7 +416,7 @@ private: "}\n" "class A::B {" " B() { A a; a.f(); }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index d320577b4..552f3b63f 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -1464,7 +1464,7 @@ private: "{\n" " printf(\"var.struct1.a = %d\", var.struct1.a);\n" " return 1;\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3136,7 +3136,7 @@ private: functionVariableUsage("Padding fun() {\n" " Distance d = DISTANCE;\n" " return (Padding){ d, d, d, d };\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -3203,7 +3203,7 @@ private: functionVariableUsage("void fun() {\n" " int x;\n" " while (c) { x=10; }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void dostuff(int x);\n" @@ -3213,7 +3213,7 @@ private: " dostuff(x);\n" " if (y) { x=10; break; }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str()); functionVariableUsage("void dostuff(int &x);\n" @@ -3223,7 +3223,7 @@ private: " dostuff(x);\n" " if (y) { x=10; break; }\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); // TODO : in this special case we can ignore that x is aliased. x is local and there are no function calls after the assignment functionVariableUsage("void fun() {\n" @@ -3232,13 +3232,13 @@ private: " dostuff(x);\n" " x = 10;\n" " }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void fun() {\n" " int x = 0;\n" " while (x < 10) { x = x + 1; }\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage("void fun()\n" @@ -5469,7 +5469,7 @@ private: " goto label;\n" " }\n" " return false;\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'X' is assigned a value that is never used.\n", errout.str()); // #4558 @@ -5721,8 +5721,7 @@ private: " static int fpUnread{0};\n" " const int var{fpUnread++};\n" " return var;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); } @@ -5730,8 +5729,7 @@ private: functionVariableUsage( "void fun(Value value) {\n" " value[10] = 123;\n" - "}\n" - ); + "}"); ASSERT_EQUALS("", errout.str()); functionVariableUsage( @@ -5810,8 +5808,7 @@ private: " else\n" " (*pos).second = number;\n" " }\n" - "};\n" - ); + "};"); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testvaarg.cpp b/test/testvaarg.cpp index 8c82c3647..3ccabbc42 100644 --- a/test/testvaarg.cpp +++ b/test/testvaarg.cpp @@ -167,7 +167,7 @@ private: " return va_arg(ap, const char*);\n" " });\n" " va_end(ap);\n" - "}\n"); + "}"); ASSERT_EQUALS("", errout.str()); check("void f(int n, ...)\n" @@ -179,7 +179,7 @@ private: " {\n" " return va_arg(ap, const char*);\n" " });\n" - "}\n"); + "}"); ASSERT_EQUALS("[test.cpp:10]: (error) va_list 'ap' was opened but not closed by va_end().\n", errout.str()); } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index dc60eee8c..8a7f76085 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -613,7 +613,7 @@ private: code = "void f(int i) {\n" " X x;\n" - " y = g(std::move(x), \n" + " y = g(std::move(x),\n" " x.size());\n" "}"; ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::MovedVariable)); @@ -1556,7 +1556,7 @@ private: "\n" "out:\n" " if (abc) {}\n" - "}\n"); + "}"); } void valueFlowBeforeConditionForward() { @@ -2472,7 +2472,7 @@ private: // protected usage with && code = "void f(const Token* x) {\n" " if (x) {}\n" - " for (; x && \n" + " for (; x &&\n" " x->str() != y; x = x->next()) {}\n" "}"; ASSERT_EQUALS(true, testValueOfX(code, 3U, 0)); @@ -2480,7 +2480,7 @@ private: code = "void f(const Token* x) {\n" " if (x) {}\n" - " if (x && \n" + " if (x &&\n" " x->str() != y) {}\n" "}"; ASSERT_EQUALS(true, testValueOfX(code, 3U, 0)); @@ -2833,9 +2833,9 @@ private: code = "void f(int i) {\n" " int x = 0;\n" - " if (i == 0) \n" + " if (i == 0)\n" " x = 1;\n" - " else if (!x && i == 1) \n" + " else if (!x && i == 1)\n" " int b = x;\n" "}\n"; ASSERT_EQUALS(true, testValueOfXKnown(code, 5U, 0)); @@ -4303,7 +4303,7 @@ private: code = "void f(int i, int j, bool a) {\n" " if (i != j) {}\n" - " if (i == j) return; \n" + " if (i == j) return;\n" "}\n"; ASSERT_EQUALS(false, valueOfTok(code, "!=").intvalue == 1); @@ -4335,7 +4335,7 @@ private: code = "void f(int i, int j, bool a) {\n" " bool x = (i != j);\n" " bool b = x;\n" - " if (i != j) return; \n" + " if (i != j) return;\n" "}\n"; ASSERT_EQUALS(false, testValueOfXKnown(code, 3U, 0)); diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 7da2c852c..e211716e4 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -476,7 +476,7 @@ private: "{\n" " std::string str(\"test\");\n" " str.clear();\n" - "}\n"); + "}"); const char expected[] = "1: void func ( )\n" "2: {\n" @@ -514,8 +514,7 @@ private: } void varid11() { - const std::string actual = tokenize( - "class Foo;\n"); + const std::string actual = tokenize("class Foo;"); const char expected[] = "1: class Foo ;\n"; @@ -527,7 +526,7 @@ private: "static void a()\n" "{\n" " class Foo *foo;\n" - "}\n"); + "}"); const char expected[] = "1: static void a ( )\n" "2: {\n" @@ -1278,8 +1277,7 @@ private: "std::list tokens;\n" "static std::vector ex1;\n" "extern std::vector ex2;\n" - "std::map m;\n" - ); + "std::map m;"); const char expected[] = "1: list < int > ints@1 ;\n" "2: list < int > :: iterator it@2 ;\n" @@ -1313,7 +1311,7 @@ private: "{\n" " int *a;\n" " delete a;\n" - "}\n"); + "}"); const char expected[] = "1: void f ( )\n" "2: {\n" @@ -1364,7 +1362,7 @@ private: "void f3(const std::string &s)\n" "{\n" " s.size();\n" - "}\n"); + "}"); const char expected[] = "1: void f1 ( int & p@1 )\n" "2: {\n" @@ -1408,7 +1406,7 @@ private: " std::vector b;\n" " std::vector &a = b;\n" " std::vector *c = &b;\n" - "}\n"); + "}"); const char expected[] = "1: void f ( )\n" "2: {\n" @@ -1428,7 +1426,7 @@ private: "public:\n" " std::string name1;\n" " std::string name2;\n" - "};\n"); + "};"); const char expected[] = "1: class Foo\n" "2: {\n" @@ -1454,7 +1452,7 @@ private: " POINT pOutput = { 0 , 0 };\n" " int x = pOutput.x;\n" " int y = pOutput.y;\n" - "}\n"); + "}"); const char expected[] = "1: class foo\n" "2: {\n" @@ -1489,7 +1487,7 @@ private: "void Bar::f()\n" "{\n" " foo.x = x;\n" - "}\n"); + "}"); const char expected[] = "1: struct Foo {\n" "2: int x@1 ;\n" "3: } ;\n" @@ -2199,7 +2197,7 @@ private: "{\n" "public:\n" " void operator=(const Foo &);\n" - "};\n"); + "};"); const char expected[] = "1: class Foo\n" "2: {\n" @@ -2213,7 +2211,7 @@ private: const std::string actual = tokenize( "struct Foo {\n" " void * operator new [](int);\n" - "};\n"); + "};"); const char expected[] = "1: struct Foo {\n" "2: void * operatornew[] ( int ) ;\n" "3: } ;\n"; @@ -2225,7 +2223,7 @@ private: void varid_throw() { // ticket #1723 const std::string actual = tokenize( "UserDefinedException* pe = new UserDefinedException();\n" - "throw pe;\n"); + "throw pe;"); const char expected[] = "1: UserDefinedException * pe@1 ; pe@1 = new UserDefinedException ( ) ;\n" "2: throw pe@1 ;\n"; @@ -2383,7 +2381,7 @@ private: " class QErrorLogger {\n" " void reportErr(ErrorLogger::ErrorMessage &msg) {\n" " }\n" - " }; \n" + " };\n" "}")); } @@ -2716,7 +2714,7 @@ private: "Fred::foo1()\n" "{\n" " i = 0;\n" - "}\n"); + "}"); const char expected[] = "1: class Fred\n" "2: {\n" @@ -2752,7 +2750,7 @@ private: "void Fred::f()\n" "{\n" " i = 0;\n" - "}\n"); + "}"); const char expected[] = "1: class Fred\n" "2: { void f ( ) ; } ;\n" @@ -2784,7 +2782,7 @@ private: "void A::f()\n" "{\n" " i = 0;\n" - "}\n"); + "}"); const char expected[] = "1: class Fred\n" "2: { int i@1 ; void f ( ) ; } ;\n" @@ -2812,7 +2810,7 @@ private: "{\n" " if (i) { }\n" " i = 0;\n" - "}\n"); + "}"); const char expected[] = "1: class Fred\n" "2: { int i@1 ; void f ( ) ; } ;\n" @@ -2834,7 +2832,7 @@ private: " A *a;\n" " B() : a(new A)\n" " { }\n" - "};\n"); + "};"); const char expected[] = "1: class A { } ;\n" "2: class B\n"