Refactorization: Removed unnecessary \n and spaces in strings
Merged from LCppC.
This commit is contained in:
parent
25678a9faf
commit
cf1937294a
|
@ -1171,7 +1171,7 @@ void CmdLineParser::printHelp()
|
||||||
" --report-progress Report progress messages while checking a file.\n"
|
" --report-progress Report progress messages while checking a file.\n"
|
||||||
#ifdef HAVE_RULES
|
#ifdef HAVE_RULES
|
||||||
" --rule=<rule> Match regular expression.\n"
|
" --rule=<rule> Match regular expression.\n"
|
||||||
" --rule-file=<file> Use given rule file. For more information, see: \n"
|
" --rule-file=<file> Use given rule file. For more information, see:\n"
|
||||||
" http://sourceforge.net/projects/cppcheck/files/Articles/\n"
|
" http://sourceforge.net/projects/cppcheck/files/Articles/\n"
|
||||||
#endif
|
#endif
|
||||||
" --std=<id> Set standard.\n"
|
" --std=<id> Set standard.\n"
|
||||||
|
|
|
@ -248,7 +248,7 @@ private:
|
||||||
|
|
||||||
// #7451: Lambdas
|
// #7451: Lambdas
|
||||||
check("const int* test(std::vector<int> outputs, const std::string& text) {\n"
|
check("const int* test(std::vector<int> 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"
|
" [&](int ele) { return \"test\" == text; });\n"
|
||||||
" return nullptr;\n"
|
" return nullptr;\n"
|
||||||
"}");
|
"}");
|
||||||
|
|
|
@ -63,8 +63,7 @@ private:
|
||||||
" if (b) { a = 1+2 };\n"
|
" if (b) { a = 1+2 };\n"
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"assert(foo() == 3); \n"
|
"assert(foo() == 3);");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check(
|
check(
|
||||||
|
@ -72,8 +71,7 @@ private:
|
||||||
" int b=a+1;\n"
|
" int b=a+1;\n"
|
||||||
" return b;\n"
|
" return b;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"assert(foo(1) == 2); \n"
|
"assert(foo(1) == 2);");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,8 +82,7 @@ private:
|
||||||
" a = 1+2;\n"
|
" a = 1+2;\n"
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\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());
|
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"
|
// Ticket #4937 "false positive: Assert calls a function which may have desired side effects"
|
||||||
|
@ -97,7 +94,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" assert( !SquarePack::isRank1Or8(push2) );\n"
|
" assert( !SquarePack::isRank1Or8(push2) );\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct SquarePack {\n"
|
check("struct SquarePack {\n"
|
||||||
|
@ -108,7 +105,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" assert( !SquarePack::isRank1Or8(push2) );\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());
|
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"
|
check("struct SquarePack {\n"
|
||||||
|
@ -119,7 +116,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" assert( !SquarePack::isRank1Or8(push2) );\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());
|
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"
|
check("struct SquarePack {\n"
|
||||||
|
@ -130,7 +127,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" assert( !SquarePack::isRank1Or8(push2) );\n"
|
" assert( !SquarePack::isRank1Or8(push2) );\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,60 +169,54 @@ private:
|
||||||
" int a; a = 0;\n"
|
" int a; a = 0;\n"
|
||||||
" assert(a = 2);\n"
|
" assert(a = 2);\n"
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str());
|
||||||
|
|
||||||
check("void f(int a) {\n"
|
check("void f(int a) {\n"
|
||||||
" assert(a == 2);\n"
|
" assert(a == 2);\n"
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f(int a, int b) {\n"
|
check("void f(int a, int b) {\n"
|
||||||
" assert(a == 2 && (b = 1));\n"
|
" assert(a == 2 && (b = 1));\n"
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Assert statement modifies 'b'.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Assert statement modifies 'b'.\n", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" int a; a = 0;\n"
|
" int a; a = 0;\n"
|
||||||
" assert(a += 2);\n"
|
" assert(a += 2);\n"
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" int a; a = 0;\n"
|
" int a; a = 0;\n"
|
||||||
" assert(a *= 2);\n"
|
" assert(a *= 2);\n"
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" int a; a = 0;\n"
|
" int a; a = 0;\n"
|
||||||
" assert(a -= 2);\n"
|
" assert(a -= 2);\n"
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" int a = 0;\n"
|
" int a = 0;\n"
|
||||||
" assert(a--);\n"
|
" assert(a--);\n"
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" int a = 0;\n"
|
" int a = 0;\n"
|
||||||
" assert(--a);\n"
|
" assert(--a);\n"
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
|
@ -234,7 +225,7 @@ private:
|
||||||
" auto const expected = someOtherValue;\n"
|
" auto const expected = someOtherValue;\n"
|
||||||
" return tmp == expected;\n"
|
" return tmp == expected;\n"
|
||||||
" }));\n"
|
" }));\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -127,7 +127,7 @@ private:
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" S s = {0};\n"
|
" S s = {0};\n"
|
||||||
" *s.p = true;\n"
|
" *s.p = true;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct S {\n"
|
check("struct S {\n"
|
||||||
|
@ -136,7 +136,7 @@ private:
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" S s = {0};\n"
|
" S s = {0};\n"
|
||||||
" s.p = true;\n"
|
" s.p = true;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (error) Boolean value assigned to pointer.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (error) Boolean value assigned to pointer.\n", errout.str());
|
||||||
|
|
||||||
// ticket #5627 - false positive: template
|
// ticket #5627 - false positive: template
|
||||||
|
@ -210,7 +210,7 @@ private:
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" S s = {0};\n"
|
" S s = {0};\n"
|
||||||
" s.p = true;\n"
|
" s.p = true;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (style) Boolean value assigned to floating point variable.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (style) Boolean value assigned to floating point variable.\n", errout.str());
|
||||||
|
|
||||||
check("struct S {\n"
|
check("struct S {\n"
|
||||||
|
@ -219,7 +219,7 @@ private:
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" S s = {0};\n"
|
" S s = {0};\n"
|
||||||
" *s.p[0] = true;\n"
|
" *s.p[0] = true;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (style) Boolean value assigned to floating point variable.\n", errout.str());
|
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"
|
check("void f(int x) {\n"
|
||||||
" if ((x && 0x0f)==6)\n"
|
" if ((x && 0x0f)==6)\n"
|
||||||
" a++;\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());
|
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"
|
check("void f(int x) {\n"
|
||||||
" if ((x && 0x0f)==0)\n"
|
" if ((x && 0x0f)==0)\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f(int x) {\n"
|
check("void f(int x) {\n"
|
||||||
" if ((x || 0x0f)==6)\n"
|
" if ((x || 0x0f)==6)\n"
|
||||||
" a++;\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());
|
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"
|
check("void f(int x) {\n"
|
||||||
" if ((x || 0x0f)==0)\n"
|
" if ((x || 0x0f)==0)\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f(int x) {\n"
|
check("void f(int x) {\n"
|
||||||
" if ((x & 0x0f)==6)\n"
|
" if ((x & 0x0f)==6)\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f(int x) {\n"
|
check("void f(int x) {\n"
|
||||||
" if ((x | 0x0f)==6)\n"
|
" if ((x | 0x0f)==6)\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
|
||||||
check("void f(int x) {\n"
|
check("void f(int x) {\n"
|
||||||
" if ((5 && x)==3)\n"
|
" if ((5 && x)==3)\n"
|
||||||
" a++;\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());
|
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"
|
check("void f(int x) {\n"
|
||||||
" if ((5 && x)==3 || (8 && x)==9)\n"
|
" if ((5 && x)==3 || (8 && x)==9)\n"
|
||||||
" a++;\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());
|
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"
|
check("void f(int x) {\n"
|
||||||
" if ((5 && x)!=3)\n"
|
" if ((5 && x)!=3)\n"
|
||||||
" a++;\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());
|
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"
|
check("void f(int x) {\n"
|
||||||
" if ((5 && x) > 3)\n"
|
" if ((5 && x) > 3)\n"
|
||||||
" a++;\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());
|
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"
|
check("void f(int x) {\n"
|
||||||
" if ((5 && x) > 0)\n"
|
" if ((5 && x) > 0)\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f(int x) {\n"
|
check("void f(int x) {\n"
|
||||||
" if ((5 && x) < 0)\n"
|
" if ((5 && x) < 0)\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}"
|
||||||
);
|
);
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str());
|
||||||
|
|
||||||
check("void f(int x) {\n"
|
check("void f(int x) {\n"
|
||||||
" if ((5 && x) < 1)\n"
|
" if ((5 && x) < 1)\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f(int x) {\n"
|
check("void f(int x) {\n"
|
||||||
" if ((5 && x) > 1)\n"
|
" if ((5 && x) > 1)\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}"
|
||||||
);
|
);
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str());
|
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"
|
check("void f(int x) {\n"
|
||||||
" if (0 < (5 && x))\n"
|
" if (0 < (5 && x))\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f(int x) {\n"
|
check("void f(int x) {\n"
|
||||||
" if (0 > (5 && x))\n"
|
" if (0 > (5 && x))\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}"
|
||||||
);
|
);
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str());
|
||||||
|
|
||||||
check("void f(int x) {\n"
|
check("void f(int x) {\n"
|
||||||
" if (1 > (5 && x))\n"
|
" if (1 > (5 && x))\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f(int x) {\n"
|
check("void f(int x) {\n"
|
||||||
" if (1 < (5 && x))\n"
|
" if (1 < (5 && x))\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}"
|
||||||
);
|
);
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str());
|
||||||
|
|
||||||
check("void f(bool x ) {\n"
|
check("void f(bool x ) {\n"
|
||||||
" if ( x > false )\n"
|
" if ( x > false )\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
|
||||||
|
|
||||||
check("void f(bool x ) {\n"
|
check("void f(bool x ) {\n"
|
||||||
" if ( false < x )\n"
|
" if ( false < x )\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
|
||||||
|
|
||||||
check("void f(bool x ) {\n"
|
check("void f(bool x ) {\n"
|
||||||
" if ( x < false )\n"
|
" if ( x < false )\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
|
||||||
|
|
||||||
check("void f(bool x ) {\n"
|
check("void f(bool x ) {\n"
|
||||||
" if ( false > x )\n"
|
" if ( false > x )\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
|
||||||
|
|
||||||
check("void f(bool x ) {\n"
|
check("void f(bool x ) {\n"
|
||||||
" if ( x >= false )\n"
|
" if ( x >= false )\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
|
||||||
|
|
||||||
check("void f(bool x ) {\n"
|
check("void f(bool x ) {\n"
|
||||||
" if ( false >= x )\n"
|
" if ( false >= x )\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
|
||||||
|
|
||||||
check("void f(bool x ) {\n"
|
check("void f(bool x ) {\n"
|
||||||
" if ( x <= false )\n"
|
" if ( x <= false )\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
|
||||||
|
|
||||||
check("void f(bool x ) {\n"
|
check("void f(bool x ) {\n"
|
||||||
" if ( false <= x )\n"
|
" if ( false <= x )\n"
|
||||||
" a++;\n"
|
" a++;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
|
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"
|
check("typedef int (*func)(bool invert);\n"
|
||||||
|
@ -1180,25 +1158,25 @@ private:
|
||||||
check("bool f(void) {\n"
|
check("bool f(void) {\n"
|
||||||
" auto x = [](void) { return -1; };\n"
|
" auto x = [](void) { return -1; };\n"
|
||||||
" return false;\n"
|
" return false;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("bool f(void) {\n"
|
check("bool f(void) {\n"
|
||||||
" auto x = [](void) { return -1; };\n"
|
" auto x = [](void) { return -1; };\n"
|
||||||
" return 2;\n"
|
" return 2;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout.str());
|
||||||
|
|
||||||
check("bool f(void) {\n"
|
check("bool f(void) {\n"
|
||||||
" auto x = [](void) -> int { return -1; };\n"
|
" auto x = [](void) -> int { return -1; };\n"
|
||||||
" return false;\n"
|
" return false;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("bool f(void) {\n"
|
check("bool f(void) {\n"
|
||||||
" auto x = [](void) -> int { return -1; };\n"
|
" auto x = [](void) -> int { return -1; };\n"
|
||||||
" return 2;\n"
|
" return 2;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Non-boolean value returned from function returning bool\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -371,11 +371,11 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("int x[5];\n"
|
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());
|
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"
|
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());
|
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());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
|
||||||
check("int f( ){ \n"
|
check("int f( ){\n"
|
||||||
"struct Struct{\n"
|
"struct Struct{\n"
|
||||||
" int arr[ 3 ];\n"
|
" int arr[ 3 ];\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
|
@ -1367,7 +1367,7 @@ private:
|
||||||
check("struct AB { int a[10]; int b[10]; };\n"
|
check("struct AB { int a[10]; int b[10]; };\n"
|
||||||
"int main() {\n"
|
"int main() {\n"
|
||||||
" struct AB ab;\n"
|
" struct AB ab;\n"
|
||||||
" int * p = &ab.a[10]; \n"
|
" int * p = &ab.a[10];\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
@ -1375,7 +1375,7 @@ private:
|
||||||
check("struct AB { int a[10]; int b[10]; };\n"
|
check("struct AB { int a[10]; int b[10]; };\n"
|
||||||
"int main() {\n"
|
"int main() {\n"
|
||||||
" struct AB ab[1];\n"
|
" struct AB ab[1];\n"
|
||||||
" int * p = &ab[0].a[10]; \n"
|
" int * p = &ab[0].a[10];\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
@ -1383,7 +1383,7 @@ private:
|
||||||
check("struct AB { int a[10]; int b[10]; };\n"
|
check("struct AB { int a[10]; int b[10]; };\n"
|
||||||
"int main() {\n"
|
"int main() {\n"
|
||||||
" struct AB ab[1];\n"
|
" struct AB ab[1];\n"
|
||||||
" int * p = &ab[10].a[0]; \n"
|
" int * p = &ab[10].a[0];\n"
|
||||||
" return 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());
|
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"
|
check("int s[4];\n"
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" for (int i = 2; i < 0; i++)\n"
|
" for (int i = 2; i < 0; i++)\n"
|
||||||
" s[i] = 5; \n"
|
" s[i] = 5;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -1509,7 +1509,7 @@ private:
|
||||||
" i++;\n"
|
" i++;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" arr[k];\n"
|
" arr[k];\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1521,7 +1521,7 @@ private:
|
||||||
"void g() {\n"
|
"void g() {\n"
|
||||||
" f(\"12345678\");\n"
|
" f(\"12345678\");\n"
|
||||||
" f(\"12345\");\n"
|
" f(\"12345\");\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1640,7 +1640,7 @@ private:
|
||||||
" vertices[i][1][2] = 4.0;\n"
|
" vertices[i][1][2] = 4.0;\n"
|
||||||
" vertices[i][1][3] = 5.0;\n"
|
" vertices[i][1][3] = 5.0;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -2137,7 +2137,7 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("class ActorSprite { static ImageSet * targetCursorImages[2][10]; };\n"
|
check("class ActorSprite { static ImageSet * targetCursorImages[2][10]; };\n"
|
||||||
"ImageSet *ActorSprite::targetCursorImages[2][10];\n");
|
"ImageSet *ActorSprite::targetCursorImages[2][10];");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2208,7 +2208,7 @@ private:
|
||||||
check("constexpr int blockLen = 10;\n"
|
check("constexpr int blockLen = 10;\n"
|
||||||
"void foo(std::array<uint8_t, blockLen * 2>& a) {\n"
|
"void foo(std::array<uint8_t, blockLen * 2>& a) {\n"
|
||||||
" a[2] = 2;\n"
|
" a[2] = 2;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2546,7 +2546,7 @@ private:
|
||||||
" const char *src = \"AAAAAAAAAAAAAAAAAAAAA\";\n"
|
" const char *src = \"AAAAAAAAAAAAAAAAAAAAA\";\n"
|
||||||
" for (size_t i = 0; i <= 4; i++)\n"
|
" for (size_t i = 0; i <= 4; i++)\n"
|
||||||
" dst[i] = src[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());
|
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
|
// #7083: false positive: typedef and initialization with strings
|
||||||
void buffer_overrun_29() {
|
void buffer_overrun_29() {
|
||||||
check("typedef char testChar[10]; \n"
|
check("typedef char testChar[10];\n"
|
||||||
"int main(){ \n"
|
"int main(){\n"
|
||||||
" testChar tc1 = \"\"; \n"
|
" testChar tc1 = \"\";\n"
|
||||||
" tc1[5]='a'; \n"
|
" tc1[5]='a';\n"
|
||||||
"} \n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2610,8 +2609,7 @@ private:
|
||||||
check("struct S { int m[9]; };\n"
|
check("struct S { int m[9]; };\n"
|
||||||
"int f(S * s) {\n"
|
"int f(S * s) {\n"
|
||||||
" return s->m[sizeof(s->m)];\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());
|
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"
|
" const char d[] = \"0123456789\";\n"
|
||||||
" char *cp = d + 3;\n"
|
" char *cp = d + 3;\n"
|
||||||
" return cp - d;\n"
|
" return cp - d;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3389,7 +3387,7 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// ticket #1659 - overflowing variable when using memcpy
|
// ticket #1659 - overflowing variable when using memcpy
|
||||||
check("void f(void) { \n"
|
check("void f(void) {\n"
|
||||||
" char c;\n"
|
" char c;\n"
|
||||||
" mymemset(&c, 0, 4);\n"
|
" mymemset(&c, 0, 4);\n"
|
||||||
"}", settings);
|
"}", settings);
|
||||||
|
@ -3683,7 +3681,7 @@ private:
|
||||||
|
|
||||||
// Test with invalid code that there is no segfault
|
// Test with invalid code that there is no segfault
|
||||||
check("char baz[100];\n"
|
check("char baz[100];\n"
|
||||||
"strncpy(baz, \"var\", 100)\n");
|
"strncpy(baz, \"var\", 100)");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// Test that there are no duplicate error messages
|
// Test that there are no duplicate error messages
|
||||||
|
@ -3725,13 +3723,13 @@ private:
|
||||||
check("void bar() {\n"
|
check("void bar() {\n"
|
||||||
" char buf[4];\n"
|
" char buf[4];\n"
|
||||||
" strncpy(buf, \"ab\", 4);\n"
|
" strncpy(buf, \"ab\", 4);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void bar() {\n"
|
check("void bar() {\n"
|
||||||
" char buf[4];\n"
|
" char buf[4];\n"
|
||||||
" strncpy(buf, \"abcde\", 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());
|
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() {
|
void crash6() {
|
||||||
check("void start(char* name) {\n"
|
check("void start(char* name) {\n"
|
||||||
"char snapname[64] = { 0 }; \n"
|
"char snapname[64] = { 0 };\n"
|
||||||
"strncpy(snapname, \"snapshot\", arrayLength(snapname)); \n"
|
"strncpy(snapname, \"snapshot\", arrayLength(snapname));\n"
|
||||||
"}");
|
"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4195,7 +4193,7 @@ private:
|
||||||
" int *a;\n"
|
" int *a;\n"
|
||||||
" a = new int[-1];\n"
|
" a = new int[-1];\n"
|
||||||
" delete [] a;\n"
|
" delete [] a;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
|
@ -4203,7 +4201,7 @@ private:
|
||||||
" int *a;\n"
|
" int *a;\n"
|
||||||
" a = malloc( -10 );\n"
|
" a = malloc( -10 );\n"
|
||||||
" free(a);\n"
|
" free(a);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
|
@ -4211,7 +4209,7 @@ private:
|
||||||
" int *a;\n"
|
" int *a;\n"
|
||||||
" a = malloc( -10);\n"
|
" a = malloc( -10);\n"
|
||||||
" free(a);\n"
|
" free(a);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", errout.str());
|
||||||
|
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
|
@ -4219,7 +4217,7 @@ private:
|
||||||
" int *a;\n"
|
" int *a;\n"
|
||||||
" a = alloca( -10 );\n"
|
" a = alloca( -10 );\n"
|
||||||
" free(a);\n"
|
" free(a);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Memory allocation size is negative.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4234,7 +4232,7 @@ private:
|
||||||
check("int x, y;\n"
|
check("int x, y;\n"
|
||||||
"int a[-1];\n"
|
"int a[-1];\n"
|
||||||
"int b[x?1:-1];\n"
|
"int b[x?1:-1];\n"
|
||||||
"int c[x?y:-1];\n");
|
"int c[x?y:-1];");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4242,7 +4240,7 @@ private:
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" char arr[10];\n"
|
" char arr[10];\n"
|
||||||
" p = arr + 20;\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());
|
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() {
|
void objectIndex() {
|
||||||
check("int f() { \n"
|
check("int f() {\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
" return (&i)[1]; \n"
|
" return (&i)[1];\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS(
|
ASSERT_EQUALS(
|
||||||
"[test.cpp:3] -> [test.cpp:3]: (error) The address of local variable 'i' is accessed at non-zero index.\n",
|
"[test.cpp:3] -> [test.cpp:3]: (error) The address of local variable 'i' is accessed at non-zero index.\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
|
|
||||||
check("int f(int j) { \n"
|
check("int f(int j) {\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
" return (&i)[j]; \n"
|
" return (&i)[j];\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS(
|
ASSERT_EQUALS(
|
||||||
"[test.cpp:3] -> [test.cpp:3]: (warning) The address of local variable 'i' might be accessed at non-zero index.\n",
|
"[test.cpp:3] -> [test.cpp:3]: (warning) The address of local variable 'i' might be accessed at non-zero index.\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
|
|
||||||
check("int f() { \n"
|
check("int f() {\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
" return (&i)[0]; \n"
|
" return (&i)[0];\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("int f(int * i) { \n"
|
check("int f(int * i) {\n"
|
||||||
" return i[1]; \n"
|
" return i[1];\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("int f(std::vector<int> i) { \n"
|
check("int f(std::vector<int> i) {\n"
|
||||||
" return i[1]; \n"
|
" return i[1];\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("int f(std::vector<int> i) { \n"
|
check("int f(std::vector<int> i) {\n"
|
||||||
" return i.data()[1]; \n"
|
" return i.data()[1];\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("int* f(std::vector<int>& i) { \n"
|
check("int* f(std::vector<int>& i) {\n"
|
||||||
" return &(i[1]); \n"
|
" return &(i[1]);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct A { int i; int j; };\n"
|
check("struct A { int i; int j; };\n"
|
||||||
"int f() { \n"
|
"int f() {\n"
|
||||||
" A x;\n"
|
" A x;\n"
|
||||||
" return (&x.i)[0]; \n"
|
" return (&x.i)[0];\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct A { int i; int j; };\n"
|
check("struct A { int i; int j; };\n"
|
||||||
"int f() { \n"
|
"int f() {\n"
|
||||||
" A x;\n"
|
" A x;\n"
|
||||||
" int * i = &x.i;\n"
|
" int * i = &x.i;\n"
|
||||||
" return i[0]; \n"
|
" return i[0];\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
|
@ -4463,7 +4461,7 @@ private:
|
||||||
" std::map<int, int*> m;\n"
|
" std::map<int, int*> m;\n"
|
||||||
" m[0] = &x;\n"
|
" m[0] = &x;\n"
|
||||||
" m[1] = &x;\n"
|
" m[1] = &x;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("int f() {\n"
|
check("int f() {\n"
|
||||||
|
@ -4471,7 +4469,7 @@ private:
|
||||||
" std::map<int, int*> m;\n"
|
" std::map<int, int*> m;\n"
|
||||||
" m[0] = &x;\n"
|
" m[0] = &x;\n"
|
||||||
" return m[0][1];\n"
|
" return m[0][1];\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS(
|
ASSERT_EQUALS(
|
||||||
"[test.cpp:4] -> [test.cpp:5]: (error) The address of local variable 'x' is accessed at non-zero index.\n",
|
"[test.cpp:4] -> [test.cpp:5]: (error) The address of local variable 'x' is accessed at non-zero index.\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
|
@ -4482,7 +4480,7 @@ private:
|
||||||
" m[0] = &x;\n"
|
" m[0] = &x;\n"
|
||||||
" m[1] = y;\n"
|
" m[1] = y;\n"
|
||||||
" return m[1][1];\n"
|
" return m[1][1];\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void print(char** test);\n"
|
check("void print(char** test);\n"
|
||||||
|
|
|
@ -244,50 +244,50 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void copyCtorAndEqOperator() {
|
void copyCtorAndEqOperator() {
|
||||||
checkCopyCtorAndEqOperator("class A \n"
|
checkCopyCtorAndEqOperator("class A\n"
|
||||||
"{ \n"
|
"{\n"
|
||||||
" A(const A& other) { } \n"
|
" A(const A& other) { }\n"
|
||||||
" A& operator=(const A& other) { return *this; }\n"
|
" A& operator=(const A& other) { return *this; }\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
|
||||||
checkCopyCtorAndEqOperator("class A \n"
|
checkCopyCtorAndEqOperator("class A\n"
|
||||||
"{ \n"
|
"{\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkCopyCtorAndEqOperator("class A \n"
|
checkCopyCtorAndEqOperator("class A\n"
|
||||||
"{ \n"
|
"{\n"
|
||||||
" A(const A& other) { } \n"
|
" A(const A& other) { }\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkCopyCtorAndEqOperator("class A \n"
|
checkCopyCtorAndEqOperator("class A\n"
|
||||||
"{ \n"
|
"{\n"
|
||||||
" A& operator=(const A& other) { return *this; }\n"
|
" A& operator=(const A& other) { return *this; }\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
|
||||||
checkCopyCtorAndEqOperator("class A \n"
|
checkCopyCtorAndEqOperator("class A\n"
|
||||||
"{ \n"
|
"{\n"
|
||||||
" A(const A& other) { } \n"
|
" A(const A& other) { }\n"
|
||||||
" int x;\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_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'
|
// 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"
|
checkCopyCtorAndEqOperator("class A\n"
|
||||||
"{ \n"
|
"{\n"
|
||||||
" A& operator=(const A& other) { return *this; }\n"
|
" A& operator=(const A& other) { return *this; }\n"
|
||||||
" int x;\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_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'
|
// 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"
|
checkCopyCtorAndEqOperator("class A\n"
|
||||||
"{ \n"
|
"{\n"
|
||||||
" A& operator=(const int &x) { this->x = x; return *this; }\n"
|
" A& operator=(const int &x) { this->x = x; return *this; }\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
"};");
|
"};");
|
||||||
|
@ -321,7 +321,7 @@ private:
|
||||||
" test = std::move(s.test);\n"
|
" test = std::move(s.test);\n"
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// #8337 - False positive in copy constructor detection
|
// #8337 - False positive in copy constructor detection
|
||||||
|
@ -1126,7 +1126,7 @@ private:
|
||||||
"class A::B\n"
|
"class A::B\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" B & operator=(const B & b) { return b; }\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());
|
ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
|
@ -1137,7 +1137,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" B & operator=(const B &);\n"
|
" B & operator=(const B &);\n"
|
||||||
"};\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());
|
ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
|
@ -1147,7 +1147,7 @@ private:
|
||||||
"class A::B\n"
|
"class A::B\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" A::B & operator=(const A::B & b) { return b; }\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());
|
ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
|
@ -1158,7 +1158,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" A::B & operator=(const A::B &);\n"
|
" A::B & operator=(const A::B &);\n"
|
||||||
"};\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());
|
ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
|
@ -1168,7 +1168,7 @@ private:
|
||||||
"class A::B\n"
|
"class A::B\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" B & operator=(const B & b) { return b; }\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());
|
ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
|
@ -1179,7 +1179,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" B & operator=(const B &);\n"
|
" B & operator=(const B &);\n"
|
||||||
"};\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());
|
ASSERT_EQUALS("[test.cpp:8]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
|
@ -1189,7 +1189,7 @@ private:
|
||||||
"class A::B\n"
|
"class A::B\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" A::B & operator=(const A::B & b) { return b; }\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());
|
ASSERT_EQUALS("[test.cpp:6]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
|
@ -1200,7 +1200,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" A::B & operator=(const A::B &);\n"
|
" A::B & operator=(const A::B &);\n"
|
||||||
"};\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());
|
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"
|
"class NS::szp\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" szp &operator =(int *other) {}\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());
|
ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
|
@ -1249,7 +1249,7 @@ private:
|
||||||
"class NS::szp\n"
|
"class NS::szp\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" NS::szp &operator =(int *other) {}\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());
|
ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
|
@ -1270,7 +1270,7 @@ private:
|
||||||
"class A::szp\n"
|
"class A::szp\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" szp &operator =(int *other) {}\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());
|
ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
|
@ -1291,7 +1291,7 @@ private:
|
||||||
"class A::szp\n"
|
"class A::szp\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" A::szp &operator =(int *other) {}\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());
|
ASSERT_EQUALS("[test.cpp:6]: (error) No 'return' statement in non-void function causes undefined behavior.\n", errout.str());
|
||||||
|
|
||||||
checkOpertorEqRetRefThis(
|
checkOpertorEqRetRefThis(
|
||||||
|
@ -1363,7 +1363,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1460,7 +1460,7 @@ private:
|
||||||
" basic_fbstring& replace() {\n"
|
" basic_fbstring& replace() {\n"
|
||||||
" return replaceImplDiscr();\n"
|
" return replaceImplDiscr();\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2940,7 +2940,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" A a;\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());
|
ASSERT_EQUALS("[test.cpp:6]: (error) Using 'memset' on class that contains a reference.\n", errout.str());
|
||||||
checkNoMemset("class A {\n"
|
checkNoMemset("class A {\n"
|
||||||
|
@ -2948,7 +2948,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" A a;\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());
|
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"
|
checkThisSubtraction("; *this = *this-x ;\n"
|
||||||
"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"
|
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());
|
"[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"
|
"{return m_strVal.c_str();}\n"
|
||||||
"private:\n"
|
"private:\n"
|
||||||
"std::string m_strVal;\n"
|
"std::string m_strVal;\n"
|
||||||
"};\n"
|
"};");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkConst("class A{\n"
|
checkConst("class A{\n"
|
||||||
|
@ -4506,8 +4505,7 @@ private:
|
||||||
"{return m_strVal.c_str();}\n"
|
"{return m_strVal.c_str();}\n"
|
||||||
"private:\n"
|
"private:\n"
|
||||||
"std::string m_strVal;\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());
|
ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::strGetString' can be const.\n", errout.str());
|
||||||
|
|
||||||
checkConst("class A{\n"
|
checkConst("class A{\n"
|
||||||
|
@ -4517,8 +4515,7 @@ private:
|
||||||
"{return m_strVal.c_str();}\n"
|
"{return m_strVal.c_str();}\n"
|
||||||
"private:\n"
|
"private:\n"
|
||||||
"std::string m_strVal;\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());
|
ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::strGetString1' can be const.\n", errout.str());
|
||||||
|
|
||||||
checkConst("class A{\n"
|
checkConst("class A{\n"
|
||||||
|
@ -4528,8 +4525,7 @@ private:
|
||||||
"{return m_strVec.size();}\n"
|
"{return m_strVec.size();}\n"
|
||||||
"private:\n"
|
"private:\n"
|
||||||
"std::vector<std::string> m_strVec;\n"
|
"std::vector<std::string> m_strVec;\n"
|
||||||
"};\n"
|
"};");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::strGetSize' can be const.\n", errout.str());
|
||||||
|
|
||||||
checkConst("class A{\n"
|
checkConst("class A{\n"
|
||||||
|
@ -4539,8 +4535,7 @@ private:
|
||||||
"{return m_strVec.empty();}\n"
|
"{return m_strVec.empty();}\n"
|
||||||
"private:\n"
|
"private:\n"
|
||||||
"std::vector<std::string> m_strVec;\n"
|
"std::vector<std::string> m_strVec;\n"
|
||||||
"};\n"
|
"};");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const.\n", errout.str());
|
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<float>(delays_[index1], delays_[index2]);\n"
|
" std::swap<float>(delays_[index1], delays_[index2]);\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"float delays_[4];\n"
|
"float delays_[4];\n"
|
||||||
"};\n"
|
"};");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkConst("struct DelayBase {\n"
|
checkConst("struct DelayBase {\n"
|
||||||
|
@ -4595,8 +4589,7 @@ private:
|
||||||
" x=xPos;\n"
|
" x=xPos;\n"
|
||||||
" y=yPos;\n"
|
" y=yPos;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n"
|
"};");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkConst("class AA : public P {\n"
|
checkConst("class AA : public P {\n"
|
||||||
|
@ -5530,7 +5523,7 @@ private:
|
||||||
" m_ptr = new char[42];\n"
|
" m_ptr = new char[42];\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" MyString append( const MyString& str )\n"
|
" MyString append( const MyString& str )\n"
|
||||||
" { return operator+=( str ); } \n"
|
" { return operator+=( str ); }\n"
|
||||||
" char *m_ptr;\n"
|
" char *m_ptr;\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
@ -5539,7 +5532,7 @@ private:
|
||||||
" MyString() : m_ptr(0){}\n"
|
" MyString() : m_ptr(0){}\n"
|
||||||
" MyString& operator+=( const MyString& rhs );\n"
|
" MyString& operator+=( const MyString& rhs );\n"
|
||||||
" MyString append( const MyString& str )\n"
|
" MyString append( const MyString& str )\n"
|
||||||
" { return operator+=( str ); } \n"
|
" { return operator+=( str ); }\n"
|
||||||
" char *m_ptr;\n"
|
" char *m_ptr;\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
@ -5672,7 +5665,7 @@ private:
|
||||||
" TemplateClass<int> a;\n"
|
" TemplateClass<int> a;\n"
|
||||||
" TemplateClass<float> b;\n"
|
" TemplateClass<float> b;\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5682,7 +5675,7 @@ private:
|
||||||
" void f(int v) { g((char *) &v); }\n"
|
" void f(int v) { g((char *) &v); }\n"
|
||||||
" void g(char *) { n++; }\n"
|
" void g(char *) { n++; }\n"
|
||||||
" int n;\n"
|
" int n;\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5696,7 +5689,7 @@ private:
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" const std::list<std::shared_ptr<int>>& get() { return m_test.m_list; }\n"
|
" const std::list<std::shared_ptr<int>>& get() { return m_test.m_list; }\n"
|
||||||
" TestList<std::shared_ptr<int>> m_test;\n"
|
" TestList<std::shared_ptr<int>> m_test;\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (style, inconclusive) Technically the member function 'Test::get' can be const.\n", errout.str());
|
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"
|
" {\n"
|
||||||
" v = 0;\n"
|
" v = 0;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n"
|
"};");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5827,8 +5819,7 @@ private:
|
||||||
" {\n"
|
" {\n"
|
||||||
" v[0] = \"Happy new year!\";\n"
|
" v[0] = \"Happy new year!\";\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n"
|
"};");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6839,16 +6830,14 @@ private:
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
" Fred(int x);\n"
|
" Fred(int x);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"Fred::Fred(int x) : x(x) { }\n"
|
"Fred::Fred(int x) : x(x) { }");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkSelfInitialization("class Fred {\n"
|
checkSelfInitialization("class Fred {\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
" Fred(int x);\n"
|
" Fred(int x);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"Fred::Fred(int x) : x{x} { }\n"
|
"Fred::Fred(int x) : x{x} { }");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkSelfInitialization("class Fred {\n"
|
checkSelfInitialization("class Fred {\n"
|
||||||
|
@ -6915,21 +6904,21 @@ private:
|
||||||
" A();\n"
|
" A();\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::A()\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());
|
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"
|
checkVirtualFunctionCall("class A {\n"
|
||||||
" virtual int f();\n"
|
" virtual int f();\n"
|
||||||
" A() {f();}\n"
|
" A() {f();}\n"
|
||||||
"};\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());
|
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"
|
checkVirtualFunctionCall("class A : B {\n"
|
||||||
" int f() override;\n"
|
" int f() override;\n"
|
||||||
" A() {f();}\n"
|
" A() {f();}\n"
|
||||||
"};\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());
|
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"
|
checkVirtualFunctionCall("class B {\n"
|
||||||
|
@ -6939,14 +6928,14 @@ private:
|
||||||
" int f();\n"
|
" int f();\n"
|
||||||
" A() {f();}\n"
|
" A() {f();}\n"
|
||||||
"};\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());
|
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"
|
checkVirtualFunctionCall("class A\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" A() { A::f(); }\n"
|
" A() { A::f(); }\n"
|
||||||
" virtual void f() {}\n"
|
" virtual void f() {}\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6957,7 +6946,7 @@ private:
|
||||||
" A();\n"
|
" A();\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::A()\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());
|
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in constructor.\n", errout.str());
|
||||||
|
|
||||||
checkVirtualFunctionCall("class A\n"
|
checkVirtualFunctionCall("class A\n"
|
||||||
|
@ -6967,17 +6956,17 @@ private:
|
||||||
" int m;\n"
|
" int m;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::A():m(A::pure())\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());
|
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in constructor.\n", errout.str());
|
||||||
|
|
||||||
checkVirtualFunctionCall("class A\n"
|
checkVirtualFunctionCall("class A\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
" virtual void pure()=0; \n"
|
" virtual void pure()=0;\n"
|
||||||
" virtual ~A(); \n"
|
" virtual ~A();\n"
|
||||||
" int m; \n"
|
" int m;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::~A()\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());
|
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in destructor.\n", errout.str());
|
||||||
|
|
||||||
checkVirtualFunctionCall("class A\n"
|
checkVirtualFunctionCall("class A\n"
|
||||||
|
@ -6985,10 +6974,10 @@ private:
|
||||||
" virtual void pure()=0;\n"
|
" virtual void pure()=0;\n"
|
||||||
" void nonpure()\n"
|
" void nonpure()\n"
|
||||||
" {pure();}\n"
|
" {pure();}\n"
|
||||||
" A(); \n"
|
" A();\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::A()\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());
|
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"
|
checkVirtualFunctionCall("class A\n"
|
||||||
|
@ -6996,23 +6985,23 @@ private:
|
||||||
" virtual int pure()=0;\n"
|
" virtual int pure()=0;\n"
|
||||||
" int nonpure()\n"
|
" int nonpure()\n"
|
||||||
" {return pure();}\n"
|
" {return pure();}\n"
|
||||||
" A(); \n"
|
" A();\n"
|
||||||
" int m;\n"
|
" int m;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::A():m(nonpure())\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());
|
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"
|
checkVirtualFunctionCall("class A\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
" virtual void pure()=0; \n"
|
" virtual void pure()=0;\n"
|
||||||
" void nonpure()\n"
|
" void nonpure()\n"
|
||||||
" {pure();}\n"
|
" {pure();}\n"
|
||||||
" virtual ~A();\n"
|
" virtual ~A();\n"
|
||||||
" int m;\n"
|
" int m;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::~A()\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());
|
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"
|
checkVirtualFunctionCall("class A\n"
|
||||||
|
@ -7021,7 +7010,7 @@ private:
|
||||||
" A(bool b);\n"
|
" A(bool b);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::A(bool b)\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());
|
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:3]: (warning) Call of pure virtual function 'pure' in constructor.\n", errout.str());
|
||||||
|
|
||||||
checkVirtualFunctionCall("class A\n"
|
checkVirtualFunctionCall("class A\n"
|
||||||
|
@ -7061,7 +7050,7 @@ private:
|
||||||
" A(const A & a);\n"
|
" A(const A & a);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::A(const A & a)\n"
|
"A::A(const A & a)\n"
|
||||||
"{a.pure();}\n");
|
"{a.pure();}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkVirtualFunctionCall("class A\n"
|
checkVirtualFunctionCall("class A\n"
|
||||||
|
@ -7074,7 +7063,7 @@ private:
|
||||||
" virtual void pure()=0;\n"
|
" virtual void pure()=0;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::A()\n"
|
"A::A()\n"
|
||||||
"{B b; b.pure();}\n");
|
"{B b; b.pure();}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7087,7 +7076,7 @@ private:
|
||||||
"A::A()\n"
|
"A::A()\n"
|
||||||
"{pureWithBody();}\n"
|
"{pureWithBody();}\n"
|
||||||
"void A::pureWithBody()\n"
|
"void A::pureWithBody()\n"
|
||||||
"{}\n");
|
"{}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkVirtualFunctionCall("class A\n"
|
checkVirtualFunctionCall("class A\n"
|
||||||
|
@ -7095,12 +7084,12 @@ private:
|
||||||
" virtual void pureWithBody()=0;\n"
|
" virtual void pureWithBody()=0;\n"
|
||||||
" void nonpure()\n"
|
" void nonpure()\n"
|
||||||
" {pureWithBody();}\n"
|
" {pureWithBody();}\n"
|
||||||
" A(); \n"
|
" A();\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::A()\n"
|
"A::A()\n"
|
||||||
"{nonpure();}\n"
|
"{nonpure();}\n"
|
||||||
"void A::pureWithBody()\n"
|
"void A::pureWithBody()\n"
|
||||||
"{}\n");
|
"{}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7111,10 +7100,10 @@ private:
|
||||||
" virtual void pure()=0;\n"
|
" virtual void pure()=0;\n"
|
||||||
" void nonpure(bool bCallPure)\n"
|
" void nonpure(bool bCallPure)\n"
|
||||||
" { if (bCallPure) pure();}\n"
|
" { if (bCallPure) pure();}\n"
|
||||||
" A(); \n"
|
" A();\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::A()\n"
|
"A::A()\n"
|
||||||
"{nonpure(false);}\n");
|
"{nonpure(false);}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkVirtualFunctionCall("class A\n"
|
checkVirtualFunctionCall("class A\n"
|
||||||
|
@ -7122,10 +7111,10 @@ private:
|
||||||
" virtual void pure()=0;\n"
|
" virtual void pure()=0;\n"
|
||||||
" void nonpure(bool bCallPure)\n"
|
" void nonpure(bool bCallPure)\n"
|
||||||
" { if (!bCallPure) ; else pure();}\n"
|
" { if (!bCallPure) ; else pure();}\n"
|
||||||
" A(); \n"
|
" A();\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::A()\n"
|
"A::A()\n"
|
||||||
"{nonpure(false);}\n");
|
"{nonpure(false);}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkVirtualFunctionCall("class A\n"
|
checkVirtualFunctionCall("class A\n"
|
||||||
|
@ -7137,10 +7126,10 @@ private:
|
||||||
" case true: pure(); break;\n"
|
" case true: pure(); break;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" A(); \n"
|
" A();\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"A::A()\n"
|
"A::A()\n"
|
||||||
"{nonpure(false);}\n");
|
"{nonpure(false);}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -442,7 +442,7 @@ private:
|
||||||
check("class Fred {\n"
|
check("class Fred {\n"
|
||||||
" int x=1;\n"
|
" int x=1;\n"
|
||||||
" int *y=0;\n"
|
" int *y=0;\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,7 +455,7 @@ private:
|
||||||
" {}\n"
|
" {}\n"
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("class Fred : public Base<A, B> {"
|
check("class Fred : public Base<A, B> {"
|
||||||
|
@ -466,7 +466,7 @@ private:
|
||||||
" {}\n"
|
" {}\n"
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,7 +534,7 @@ private:
|
||||||
void noConstructor7() {
|
void noConstructor7() {
|
||||||
// ticket #4391
|
// ticket #4391
|
||||||
check("short bar;\n"
|
check("short bar;\n"
|
||||||
"class foo;\n");
|
"class foo;");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,7 +542,7 @@ private:
|
||||||
// ticket #4404
|
// ticket #4404
|
||||||
check("class LineSegment;\n"
|
check("class LineSegment;\n"
|
||||||
"class PointArray { };\n"
|
"class PointArray { };\n"
|
||||||
"void* tech_ = NULL;\n");
|
"void* tech_ = NULL;");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,7 +573,7 @@ private:
|
||||||
" virtual ~A();\n"
|
" virtual ~A();\n"
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" wxTimer *WxTimer1;\n"
|
" wxTimer *WxTimer1;\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -602,15 +602,15 @@ private:
|
||||||
// ticket #3190 "SymbolDatabase: Parse of sub class constructor fails"
|
// ticket #3190 "SymbolDatabase: Parse of sub class constructor fails"
|
||||||
void forwardDeclaration() {
|
void forwardDeclaration() {
|
||||||
check("class foo;\n"
|
check("class foo;\n"
|
||||||
"int bar;\n");
|
"int bar;");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("class foo;\n"
|
check("class foo;\n"
|
||||||
"class foo;\n");
|
"class foo;");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("class foo{};\n"
|
check("class foo{};\n"
|
||||||
"class foo;\n");
|
"class foo;");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1121,7 +1121,7 @@ private:
|
||||||
" int foo_;\n"
|
" int foo_;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"Foo::Foo() : Foo(0) {}\n"
|
"Foo::Foo() : Foo(0) {}\n"
|
||||||
"Foo::Foo(int foo) : foo_(foo) {}\n");
|
"Foo::Foo(int foo) : foo_(foo) {}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// Noexcept ctors
|
// Noexcept ctors
|
||||||
|
@ -2277,8 +2277,7 @@ private:
|
||||||
"Fred::Fred(struct C c, D d) { }\n"
|
"Fred::Fred(struct C c, D d) { }\n"
|
||||||
"Fred::Fred(E e, struct F f) { }\n"
|
"Fred::Fred(E e, struct F f) { }\n"
|
||||||
"Fred::Fred(G g, H h) { }\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"
|
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: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"
|
"[test.cpp:12]: (warning) Member variable 'Fred::x' is not initialized in the constructor.\n"
|
||||||
|
@ -2323,35 +2322,35 @@ private:
|
||||||
" int c;\n"
|
" int c;\n"
|
||||||
" A(int x = 0, int y = 0, int z = 0);\n"
|
" A(int x = 0, int y = 0, int z = 0);\n"
|
||||||
"};\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"
|
"struct B {\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" int b;\n"
|
" int b;\n"
|
||||||
" int c;\n"
|
" int c;\n"
|
||||||
" B(int x = 0, int y = 0, int z = 0);\n"
|
" B(int x = 0, int y = 0, int z = 0);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"B::B(int x, int y, int z) { } \n"
|
"B::B(int x, int y, int z) { }\n"
|
||||||
"struct C {\n"
|
"struct C {\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" int b;\n"
|
" int b;\n"
|
||||||
" int c;\n"
|
" int c;\n"
|
||||||
" C(int, int, int);\n"
|
" C(int, int, int);\n"
|
||||||
"};\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"
|
"struct D {\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" int b;\n"
|
" int b;\n"
|
||||||
" int c;\n"
|
" int c;\n"
|
||||||
" D(int, int, int);\n"
|
" D(int, int, int);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"D::D(int x, int y, int z) { } \n"
|
"D::D(int x, int y, int z) { }\n"
|
||||||
"struct E {\n"
|
"struct E {\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" int b;\n"
|
" int b;\n"
|
||||||
" int c;\n"
|
" int c;\n"
|
||||||
" E(int x, int y, int z);\n"
|
" E(int x, int y, int z);\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"E::E(int, int, int) { } \n"
|
"E::E(int, int, int) { }\n"
|
||||||
"struct F {\n"
|
"struct F {\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" int b;\n"
|
" int b;\n"
|
||||||
|
@ -2470,7 +2469,7 @@ private:
|
||||||
"}\n"
|
"}\n"
|
||||||
"using namespace NS;\n"
|
"using namespace NS;\n"
|
||||||
"MyClass::~MyClass() { }\n"
|
"MyClass::~MyClass() { }\n"
|
||||||
"MyClass::MyClass() : SomeVar(false) { }\n");
|
"MyClass::MyClass() : SomeVar(false) { }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2488,7 +2487,7 @@ private:
|
||||||
"}\n"
|
"}\n"
|
||||||
"void MyClass::Restart() {\n"
|
"void MyClass::Restart() {\n"
|
||||||
" m_retCode = 0;\n"
|
" m_retCode = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2501,7 +2500,7 @@ private:
|
||||||
" {\n"
|
" {\n"
|
||||||
" if (1) {}\n"
|
" if (1) {}\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Foo::member' is not initialized in the constructor.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Foo::member' is not initialized in the constructor.\n", errout.str());
|
||||||
check("class Foo {\n"
|
check("class Foo {\n"
|
||||||
" friend class Bar;\n"
|
" friend class Bar;\n"
|
||||||
|
@ -2511,7 +2510,7 @@ private:
|
||||||
" {\n"
|
" {\n"
|
||||||
" while (1) {}\n"
|
" while (1) {}\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Foo::member' is not initialized in the constructor.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Foo::member' is not initialized in the constructor.\n", errout.str());
|
||||||
check("class Foo {\n"
|
check("class Foo {\n"
|
||||||
" friend class Bar;\n"
|
" friend class Bar;\n"
|
||||||
|
@ -2521,7 +2520,7 @@ private:
|
||||||
" {\n"
|
" {\n"
|
||||||
" for (;;) {}\n"
|
" for (;;) {}\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Foo::member' is not initialized in the constructor.\n", errout.str());
|
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"
|
"public:\n"
|
||||||
" C() _STLP_NOTHROW {}\n"
|
" C() _STLP_NOTHROW {}\n"
|
||||||
" C(const C&) _STLP_NOTHROW {}\n"
|
" C(const C&) _STLP_NOTHROW {}\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3890,7 +3889,7 @@ private:
|
||||||
"class C {\n"
|
"class C {\n"
|
||||||
" private:\n"
|
" private:\n"
|
||||||
" A* b;\n"
|
" A* b;\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("template<class T> class A{};\n"
|
check("template<class T> class A{};\n"
|
||||||
|
@ -3902,7 +3901,7 @@ private:
|
||||||
" bool m_value;\n"
|
" bool m_value;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"template<class T1, class T2>\n"
|
"template<class T1, class T2>\n"
|
||||||
"A<B<T1, T2>>::A() : m_value(false) {}\n");
|
"A<B<T1, T2>>::A() : m_value(false) {}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -326,13 +326,13 @@ private:
|
||||||
"void func3() noexcept(true) { throw 1; }\n"
|
"void func3() noexcept(true) { throw 1; }\n"
|
||||||
"void func4() noexcept(false) { throw 1; }\n"
|
"void func4() noexcept(false) { throw 1; }\n"
|
||||||
"void func5() noexcept(true) { func1(); }\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"
|
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: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());
|
"[test.cpp:5]: (error) Exception thrown in function declared not to throw exceptions.\n", errout.str());
|
||||||
|
|
||||||
// avoid false positives
|
// avoid false positives
|
||||||
check("const char *func() noexcept { return 0; }\n");
|
check("const char *func() noexcept { return 0; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,12 +341,12 @@ private:
|
||||||
"void func2() throw() { throw 1; }\n"
|
"void func2() throw() { throw 1; }\n"
|
||||||
"void func3() throw(int) { throw 1; }\n"
|
"void func3() throw(int) { throw 1; }\n"
|
||||||
"void func4() throw() { func1(); }\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"
|
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());
|
"[test.cpp:4]: (error) Exception thrown in function declared not to throw exceptions.\n", errout.str());
|
||||||
|
|
||||||
// avoid false positives
|
// avoid false positives
|
||||||
check("const char *func() throw() { return 0; }\n");
|
check("const char *func() throw() { return 0; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,12 +377,12 @@ private:
|
||||||
void nothrowAttributeThrow() {
|
void nothrowAttributeThrow() {
|
||||||
check("void func1() throw(int) { throw 1; }\n"
|
check("void func1() throw(int) { throw 1; }\n"
|
||||||
"void func2() __attribute((nothrow)); void func2() { 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"
|
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());
|
"[test.cpp:3]: (error) Exception thrown in function declared not to throw exceptions.\n", errout.str());
|
||||||
|
|
||||||
// avoid false positives
|
// 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());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,19 +391,19 @@ private:
|
||||||
" void copyMemberValues() throw () {\n"
|
" void copyMemberValues() throw () {\n"
|
||||||
" copyMemberValues();\n"
|
" copyMemberValues();\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void nothrowDeclspecThrow() {
|
void nothrowDeclspecThrow() {
|
||||||
check("void func1() throw(int) { throw 1; }\n"
|
check("void func1() throw(int) { throw 1; }\n"
|
||||||
"void __declspec(nothrow) func2() { 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"
|
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());
|
"[test.cpp:3]: (error) Exception thrown in function declared not to throw exceptions.\n", errout.str());
|
||||||
|
|
||||||
// avoid false positives
|
// 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());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -518,7 +518,7 @@ private:
|
||||||
" size_t l1 = strlen(&s1.x);\n"
|
" size_t l1 = strlen(&s1.x);\n"
|
||||||
" size_t l2 = strlen(&s2.x);\n"
|
" size_t l2 = strlen(&s2.x);\n"
|
||||||
" return l1 + l2;\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());
|
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); }");
|
check("const char x = 'x'; size_t f() { return strlen(&x); }");
|
||||||
|
@ -537,13 +537,13 @@ private:
|
||||||
" char * a = \"Hello world\";\n"
|
" char * a = \"Hello world\";\n"
|
||||||
" char ** b = &a;\n"
|
" char ** b = &a;\n"
|
||||||
" return strlen(&b[0][0]);\n"
|
" return strlen(&b[0][0]);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("size_t f() {\n"
|
check("size_t f() {\n"
|
||||||
" char ca[] = \"asdf\";\n"
|
" char ca[] = \"asdf\";\n"
|
||||||
" return strlen((char*) &ca);\n"
|
" return strlen((char*) &ca);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// #5225
|
// #5225
|
||||||
|
@ -554,7 +554,7 @@ private:
|
||||||
" strcat(str, &d);\n"
|
" strcat(str, &d);\n"
|
||||||
" puts(str);\n"
|
" puts(str);\n"
|
||||||
" return 0;\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());
|
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
|
// acos, acosf, acosl
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" return acos(-1) \n"
|
" return acos(-1) \n"
|
||||||
" + acos(0.1) \n"
|
" + acos(0.1) \n"
|
||||||
" + acos(0.0001) \n"
|
" + acos(0.0001) \n"
|
||||||
" + acos(0.01) \n"
|
" + acos(0.01) \n"
|
||||||
" + acos(1.0E-1) \n"
|
" + acos(1.0E-1) \n"
|
||||||
" + acos(-1.0E-1) \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"
|
" + acos(+0.1E-1) \n"
|
||||||
" + acos(-0.1E-1) \n"
|
" + acos(-0.1E-1) \n"
|
||||||
" + acosf(-1) \n"
|
" + acosf(-1) \n"
|
||||||
" + acosf(0.1) \n"
|
" + acosf(0.1) \n"
|
||||||
" + acosf(0.0001) \n"
|
" + acosf(0.0001) \n"
|
||||||
" + acosf(0.01) \n"
|
" + acosf(0.01) \n"
|
||||||
" + acosf(1.0E-1) \n"
|
" + acosf(1.0E-1) \n"
|
||||||
" + acosf(-1.0E-1) \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"
|
" + acosf(+0.1E-1) \n"
|
||||||
" + acosf(-0.1E-1) \n"
|
" + acosf(-0.1E-1) \n"
|
||||||
" + acosl(-1) \n"
|
" + acosl(-1) \n"
|
||||||
" + acosl(0.1) \n"
|
" + acosl(0.1) \n"
|
||||||
" + acosl(0.0001) \n"
|
" + acosl(0.0001) \n"
|
||||||
" + acosl(0.01) \n"
|
" + acosl(0.01) \n"
|
||||||
" + acosl(1.0E-1) \n"
|
" + acosl(1.0E-1) \n"
|
||||||
" + acosl(-1.0E-1) \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"
|
" + acosl(+0.1E-1) \n"
|
||||||
" + acosl(-0.1E-1); \n"
|
" + acosl(-0.1E-1);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
@ -905,39 +905,39 @@ private:
|
||||||
// asin, asinf, asinl
|
// asin, asinf, asinl
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" return asin(1) \n"
|
" return asin(1) \n"
|
||||||
" + asin(-1) \n"
|
" + asin(-1) \n"
|
||||||
" + asin(0.1) \n"
|
" + asin(0.1) \n"
|
||||||
" + asin(0.0001) \n"
|
" + asin(0.0001) \n"
|
||||||
" + asin(0.01) \n"
|
" + asin(0.01) \n"
|
||||||
" + asin(1.0E-1) \n"
|
" + asin(1.0E-1) \n"
|
||||||
" + asin(-1.0E-1) \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"
|
" + asin(+0.1E-1) \n"
|
||||||
" + asin(-0.1E-1) \n"
|
" + asin(-0.1E-1) \n"
|
||||||
" + asinf(1) \n"
|
" + asinf(1) \n"
|
||||||
" + asinf(-1) \n"
|
" + asinf(-1) \n"
|
||||||
" + asinf(0.1) \n"
|
" + asinf(0.1) \n"
|
||||||
" + asinf(0.0001) \n"
|
" + asinf(0.0001) \n"
|
||||||
" + asinf(0.01) \n"
|
" + asinf(0.01) \n"
|
||||||
" + asinf(1.0E-1) \n"
|
" + asinf(1.0E-1) \n"
|
||||||
" + asinf(-1.0E-1) \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"
|
" + asinf(+0.1E-1) \n"
|
||||||
" + asinf(-0.1E-1) \n"
|
" + asinf(-0.1E-1) \n"
|
||||||
" + asinl(1) \n"
|
" + asinl(1) \n"
|
||||||
" + asinl(-1) \n"
|
" + asinl(-1) \n"
|
||||||
" + asinl(0.1) \n"
|
" + asinl(0.1) \n"
|
||||||
" + asinl(0.0001) \n"
|
" + asinl(0.0001) \n"
|
||||||
" + asinl(0.01) \n"
|
" + asinl(0.01) \n"
|
||||||
" + asinl(1.0E-1) \n"
|
" + asinl(1.0E-1) \n"
|
||||||
" + asinl(-1.0E-1) \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"
|
" + asinl(+0.1E-1) \n"
|
||||||
" + asinl(-0.1E-1); \n"
|
" + asinl(-0.1E-1);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
@ -1221,7 +1221,7 @@ private:
|
||||||
check("template <typename... a> uint8_t b(std::tuple<uint8_t> d) {\n"
|
check("template <typename... a> uint8_t b(std::tuple<uint8_t> d) {\n"
|
||||||
" std::tuple<a...> c{std::move(d)};\n"
|
" std::tuple<a...> c{std::move(d)};\n"
|
||||||
" return std::get<0>(c);\n"
|
" return std::get<0>(c);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct A { int x; };\n"
|
check("struct A { int x; };\n"
|
||||||
|
@ -1229,7 +1229,7 @@ private:
|
||||||
"A f(int x, Ts... xs) {\n"
|
"A f(int x, Ts... xs) {\n"
|
||||||
" return {std::move(x), static_cast<int>(xs)...};\n"
|
" return {std::move(x), static_cast<int>(xs)...};\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"A g() { return f(1); }\n");
|
"A g() { return f(1); }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1257,17 +1257,17 @@ private:
|
||||||
void memsetZeroBytes() {
|
void memsetZeroBytes() {
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" memset(p, 10, 0x0);\n"
|
" memset(p, 10, 0x0);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0 bytes.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0 bytes.\n", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" memset(p, sizeof(p), 0);\n"
|
" memset(p, sizeof(p), 0);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0 bytes.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0 bytes.\n", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" memset(p, sizeof(p), i);\n"
|
" memset(p, sizeof(p), i);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// #6269 false positives in case of overloaded standard library functions
|
// #6269 false positives in case of overloaded standard library functions
|
||||||
|
@ -1282,7 +1282,7 @@ private:
|
||||||
// #7285
|
// #7285
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" memset(&tm, sizeof(tm), 0);\n"
|
" memset(&tm, sizeof(tm), 0);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0 bytes.\n", errout.str());
|
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"
|
" memset(is, 1.0f, 40);\n"
|
||||||
" int* is2 = new int[10];\n"
|
" int* is2 = new int[10];\n"
|
||||||
" memset(is2, 0.1f, 40);\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"
|
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());
|
"[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"
|
" int* is = new int[10];\n"
|
||||||
" float g = computeG();\n"
|
" float g = computeG();\n"
|
||||||
" memset(is, g, 40);\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());
|
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"
|
check("void f() {\n"
|
||||||
" int* is = new int[10];\n"
|
" int* is = new int[10];\n"
|
||||||
" memset(is, 0.0f, 40);\n"
|
" memset(is, 0.0f, 40);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f() {\n" // FP
|
check("void f() {\n" // FP
|
||||||
" float x = 2.3f;\n"
|
" float x = 2.3f;\n"
|
||||||
" memset(a, (x?64:0), 40);\n"
|
" memset(a, (x?64:0), 40);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
|
@ -1321,7 +1321,7 @@ private:
|
||||||
" memset(ss, 256, 4);\n"
|
" memset(ss, 256, 4);\n"
|
||||||
" short ss2[2];\n"
|
" short ss2[2];\n"
|
||||||
" memset(ss2, -129, 4);\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"
|
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());
|
"[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"
|
" memset(cs2, 255, 30);\n"
|
||||||
" char cs3[30];\n"
|
" char cs3[30];\n"
|
||||||
" memset(cs3, 0, 30);\n"
|
" memset(cs3, 0, 30);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" int is[10];\n"
|
" int is[10];\n"
|
||||||
" const int i = g();\n"
|
" const int i = g();\n"
|
||||||
" memset(is, 1.0f + i, 40);\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());
|
ASSERT_EQUALS("[test.cpp:4]: (portability) The 2nd memset() argument '1.0f+i' is a float, its representation is implementation defined.\n", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -466,7 +466,7 @@ private:
|
||||||
TODO_ASSERT_THROW(checkCode("int ScopedEnum{ template<typename T> { { e = T::error }; };\n"
|
TODO_ASSERT_THROW(checkCode("int ScopedEnum{ template<typename T> { { e = T::error }; };\n"
|
||||||
"ScopedEnum1<int> se1; { enum class E : T { e = 0 = e ScopedEnum2<void*> struct UnscopedEnum3 { T{ e = 4 }; };\n"
|
"ScopedEnum1<int> se1; { enum class E : T { e = 0 = e ScopedEnum2<void*> struct UnscopedEnum3 { T{ e = 4 }; };\n"
|
||||||
"arr[(int) E::e]; }; UnscopedEnum3<int> e2 = f()\n"
|
"arr[(int) E::e]; }; UnscopedEnum3<int> 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<typename T> struct UnscopedEnum1 { E{ e = T::error }; }; UnscopedEnum1<int> { enum E : { e = 0 }; };\n"
|
"namespace UnscopedEnum { template<typename T> struct UnscopedEnum1 { E{ e = T::error }; }; UnscopedEnum1<int> { enum E : { e = 0 }; };\n"
|
||||||
"UnscopedEnum2<void*> ue3; template<typename T> struct UnscopedEnum3 { enum { }; }; int arr[E::e]; };\n"
|
"UnscopedEnum2<void*> ue3; template<typename T> struct UnscopedEnum3 { enum { }; }; int arr[E::e]; };\n"
|
||||||
"UnscopedEnum3<int> namespace template<typename T> int f() { enum E { e }; T::error }; return (int) E(); } int test1 int g() { enum E { e = E };\n"
|
"UnscopedEnum3<int> namespace template<typename T> 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"
|
checkCode("struct R1 {\n"
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" R1 () : a { }\n"
|
" R1 () : a { }\n"
|
||||||
"};\n");
|
"};");
|
||||||
}
|
}
|
||||||
|
|
||||||
void garbageCode30() {
|
void garbageCode30() {
|
||||||
|
@ -847,7 +847,7 @@ private:
|
||||||
|
|
||||||
void garbageCode99() { // #6726
|
void garbageCode99() { // #6726
|
||||||
ASSERT_THROW(checkCode("{ xs :: i(:) ! ! x/5 ! !\n"
|
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"
|
"b type(*), d(:), a x :: end d(..), foo end\n"
|
||||||
"foo4 b d(..), a a x type(*), b foo2 b"), InternalError);
|
"foo4 b d(..), a a x type(*), b foo2 b"), InternalError);
|
||||||
}
|
}
|
||||||
|
@ -929,7 +929,7 @@ private:
|
||||||
|
|
||||||
void garbageCode118() { // #5600 - missing include causes invalid enum
|
void garbageCode118() { // #5600 - missing include causes invalid enum
|
||||||
ASSERT_THROW(checkCode("enum {\n"
|
ASSERT_THROW(checkCode("enum {\n"
|
||||||
" NUM_OPCODES = \n"
|
" NUM_OPCODES =\n"
|
||||||
// #include "definition"
|
// #include "definition"
|
||||||
"};\n"
|
"};\n"
|
||||||
"struct bytecode {};\n"
|
"struct bytecode {};\n"
|
||||||
|
@ -989,7 +989,7 @@ private:
|
||||||
" ~A() { printf(\"A d'tor\\n\"); }\n"
|
" ~A() { printf(\"A d'tor\\n\"); }\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
" const A& foo(const A& arg) { return arg; }\n"
|
" const A& foo(const A& arg) { return arg; }\n"
|
||||||
" foo(A(12)).Var\n");
|
" foo(A(12)).Var");
|
||||||
}
|
}
|
||||||
|
|
||||||
void garbageCode128() {
|
void garbageCode128() {
|
||||||
|
@ -1077,7 +1077,7 @@ private:
|
||||||
checkCode("struct S { int i, j; }; "
|
checkCode("struct S { int i, j; }; "
|
||||||
"template<int S::*p, typename U> struct X {}; "
|
"template<int S::*p, typename U> struct X {}; "
|
||||||
"X<&S::i, int> x = X<&S::i, int>(); "
|
"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 <typename T> struct A {}; "
|
checkCode("template <typename T> struct A {}; "
|
||||||
"template <> struct A<void> {}; "
|
"template <> struct A<void> {}; "
|
||||||
"void foo(const void* f = 0) {}");
|
"void foo(const void* f = 0) {}");
|
||||||
|
@ -1240,13 +1240,13 @@ private:
|
||||||
void garbageCode157() { // #7131
|
void garbageCode157() { // #7131
|
||||||
ASSERT_THROW(checkCode("namespace std {\n"
|
ASSERT_THROW(checkCode("namespace std {\n"
|
||||||
" template < typename >\n"
|
" template < typename >\n"
|
||||||
" void swap(); \n"
|
" void swap();\n"
|
||||||
"}"
|
"}"
|
||||||
"template std::swap\n"), InternalError);
|
"template std::swap\n"), InternalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
void garbageCode158() { // #3238
|
void garbageCode158() { // #3238
|
||||||
checkCode("__FBSDID(\"...\");\n");
|
checkCode("__FBSDID(\"...\");");
|
||||||
}
|
}
|
||||||
|
|
||||||
void garbageCode159() { // #7119
|
void garbageCode159() { // #7119
|
||||||
|
@ -1292,7 +1292,7 @@ private:
|
||||||
checkCode("YY_DECL { switch (yy_act) {\n"
|
checkCode("YY_DECL { switch (yy_act) {\n"
|
||||||
" case 65: YY_BREAK\n"
|
" case 65: YY_BREAK\n"
|
||||||
" case YY_STATE_EOF(block):\n"
|
" case YY_STATE_EOF(block):\n"
|
||||||
" yyterminate(); \n"
|
" yyterminate();\n"
|
||||||
"} }"); // #5663
|
"} }"); // #5663
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1312,13 +1312,13 @@ private:
|
||||||
|
|
||||||
void templateSimplifierCrashes() {
|
void templateSimplifierCrashes() {
|
||||||
checkCode( // #5950
|
checkCode( // #5950
|
||||||
"struct A { \n"
|
"struct A {\n"
|
||||||
" template <class T> operator T*();\n"
|
" template <class T> operator T*();\n"
|
||||||
"}; \n"
|
"};\n"
|
||||||
"\n"
|
"\n"
|
||||||
"template <> A::operator char*(){ return 0; } // specialization\n"
|
"template <> A::operator char*(){ return 0; } // specialization\n"
|
||||||
"\n"
|
"\n"
|
||||||
"int main() { \n"
|
"int main() {\n"
|
||||||
" A a;\n"
|
" A a;\n"
|
||||||
" int *ip = a.operator int*();\n"
|
" int *ip = a.operator int*();\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
|
@ -1331,7 +1331,7 @@ private:
|
||||||
" void f() {\n"
|
" void f() {\n"
|
||||||
" s.operator A<A<int> >();\n"
|
" s.operator A<A<int> >();\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
checkCode( // #6034
|
checkCode( // #6034
|
||||||
"template<template<typename...> class T, typename... Args>\n"
|
"template<template<typename...> class T, typename... Args>\n"
|
||||||
|
@ -1345,8 +1345,7 @@ private:
|
||||||
"\n"
|
"\n"
|
||||||
"int main() {\n"
|
"int main() {\n"
|
||||||
" foo<int_<0> >::value;\n"
|
" foo<int_<0> >::value;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
|
|
||||||
checkCode( // #6117
|
checkCode( // #6117
|
||||||
"template <typename ...> struct something_like_tuple\n"
|
"template <typename ...> struct something_like_tuple\n"
|
||||||
|
@ -1364,19 +1363,17 @@ private:
|
||||||
"\n"
|
"\n"
|
||||||
"typedef something_like_tuple<char, int, float> something_like_tuple_t;\n"
|
"typedef something_like_tuple<char, int, float> something_like_tuple_t;\n"
|
||||||
"SA ((is_last<float, something_like_tuple_t>::value == false));\n"
|
"SA ((is_last<float, something_like_tuple_t>::value == false));\n"
|
||||||
"SA ((is_last<int, something_like_tuple_t>::value == false));\n"
|
"SA ((is_last<int, something_like_tuple_t>::value == false));");
|
||||||
);
|
|
||||||
|
|
||||||
checkCode( // #6225
|
checkCode( // #6225
|
||||||
"template <typename...>\n"
|
"template <typename...>\n"
|
||||||
"void templ_fun_with_ty_pack() {}\n"
|
"void templ_fun_with_ty_pack() {}\n"
|
||||||
" \n"
|
"\n"
|
||||||
"namespace PR20047 {\n"
|
"namespace PR20047 {\n"
|
||||||
" template <typename T>\n"
|
" template <typename T>\n"
|
||||||
" struct A {};\n"
|
" struct A {};\n"
|
||||||
" using AliasA = A<T>;\n"
|
" using AliasA = A<T>;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
|
|
||||||
// #3449
|
// #3449
|
||||||
ASSERT_EQUALS("template < typename T > struct A ;\n"
|
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"
|
" pOut->CreateObject( nIndex, GDI_BRUSH, new WinMtfFillStyle( ReadColor(), ( nStyle == BS_HOLLOW ) ? TRUE : FALSE ) );\n"
|
||||||
" return bStatus;\n"
|
" return bStatus;\n"
|
||||||
" };\n"
|
" };\n"
|
||||||
"}\n");
|
"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// #8151 - segfault due to incorrect template syntax
|
// #8151 - segfault due to incorrect template syntax
|
||||||
|
@ -1744,7 +1741,7 @@ private:
|
||||||
// #8913
|
// #8913
|
||||||
/*
|
/*
|
||||||
ASSERT_THROW(checkCode("public ref class LibCecSharp : public CecCallbackMethods {\n"
|
ASSERT_THROW(checkCode("public ref class LibCecSharp : public CecCallbackMethods {\n"
|
||||||
"array<CecAdapter ^> ^ FindAdapters(String ^ path) {} \n"
|
"array<CecAdapter ^> ^ FindAdapters(String ^ path) {}\n"
|
||||||
"bool GetDeviceInformation(String ^ port, LibCECConfiguration ^configuration, uint32_t timeoutMs) {\n"
|
"bool GetDeviceInformation(String ^ port, LibCECConfiguration ^configuration, uint32_t timeoutMs) {\n"
|
||||||
"bool bReturn(false);\n"
|
"bool bReturn(false);\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
|
@ -1766,20 +1763,20 @@ private:
|
||||||
"template< class T >\n"
|
"template< class T >\n"
|
||||||
"template< class Predicate > int\n"
|
"template< class Predicate > int\n"
|
||||||
"List<T>::DeleteIf( const Predicate &pred )\n"
|
"List<T>::DeleteIf( const Predicate &pred )\n"
|
||||||
"{}\n");
|
"{}");
|
||||||
|
|
||||||
// #8749
|
// #8749
|
||||||
checkCode(
|
checkCode(
|
||||||
"struct A {\n"
|
"struct A {\n"
|
||||||
" void operator+=(A&) && = delete;\n"
|
" void operator+=(A&) && = delete;\n"
|
||||||
"};\n");
|
"};");
|
||||||
|
|
||||||
// #8788
|
// #8788
|
||||||
checkCode(
|
checkCode(
|
||||||
"struct foo;\n"
|
"struct foo;\n"
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" auto fn = []() -> foo* { return new foo(); };\n"
|
" auto fn = []() -> foo* { return new foo(); };\n"
|
||||||
"}\n");
|
"}");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -307,13 +307,13 @@ private:
|
||||||
check("struct A { void operator()(int); };\n"
|
check("struct A { void operator()(int); };\n"
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
"A{}(0);\n"
|
"A{}(0);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("template<class> struct A { void operator()(int); };\n"
|
check("template<class> struct A { void operator()(int); };\n"
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
"A<int>{}(0);\n"
|
"A<int>{}(0);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ private:
|
||||||
check("void foo(int,const char*,int);\n"
|
check("void foo(int,const char*,int);\n"
|
||||||
"void f(int value) {\n"
|
"void f(int value) {\n"
|
||||||
" foo(42,\"test\",42),(value&42);\n"
|
" foo(42,\"test\",42),(value&42);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Found suspicious operator ','\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (warning) Found suspicious operator ','\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2059,7 +2059,7 @@ private:
|
||||||
" scanf(\"%lf\",&v4[0]);\n"
|
" scanf(\"%lf\",&v4[0]);\n"
|
||||||
" myvector<char *> v5(1);\n"
|
" myvector<char *> v5(1);\n"
|
||||||
" scanf(\"%10s\",v5[0]);\n"
|
" scanf(\"%10s\",v5[0]);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -2089,7 +2089,7 @@ private:
|
||||||
check("void g() {\n"
|
check("void g() {\n"
|
||||||
" const char c[]=\"42\";\n"
|
" const char c[]=\"42\";\n"
|
||||||
" scanf(\"%s\", c);\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"
|
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());
|
"[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"
|
check("void f(int len, int newline) {\n"
|
||||||
" printf(\"%s\", newline ? a : str + len);\n"
|
" printf(\"%s\", newline ? a : str + len);\n"
|
||||||
" printf(\"%s\", newline + newline);\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());
|
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"
|
check("struct Fred { int i; } f;\n"
|
||||||
|
@ -2829,27 +2829,27 @@ private:
|
||||||
// #4984
|
// #4984
|
||||||
check("void f(double *x) {\n"
|
check("void f(double *x) {\n"
|
||||||
" printf(\"%f\", x[0]);\n"
|
" printf(\"%f\", x[0]);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("int array[10];\n"
|
check("int array[10];\n"
|
||||||
"int * foo() { return array; }\n"
|
"int * foo() { return array; }\n"
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" printf(\"%f\", foo()[0]);\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());
|
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"
|
check("struct Base { int length() { } };\n"
|
||||||
"struct Derived : public Base { };\n"
|
"struct Derived : public Base { };\n"
|
||||||
"void foo(Derived * d) {\n"
|
"void foo(Derived * d) {\n"
|
||||||
" printf(\"%f\", d.length());\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());
|
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<int> v;\n"
|
check("std::vector<int> v;\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" printf(\"%d %u %f\", v[0], v[0], v[0]);\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"
|
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());
|
"[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"
|
check("int bar(int a);\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" printf(\"%d\", bar(0));\n"
|
" printf(\"%d\", bar(0));\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("std::vector<int> v;\n"
|
check("std::vector<int> v;\n"
|
||||||
|
@ -3103,20 +3103,20 @@ private:
|
||||||
|
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" printf(\"%f %d\", static_cast<int>(1.0f), reinterpret_cast<const void *>(0));\n"
|
" printf(\"%f %d\", static_cast<int>(1.0f), reinterpret_cast<const void *>(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"
|
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());
|
"[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"
|
check("void foo() {\n"
|
||||||
" UNKNOWN * u;\n"
|
" UNKNOWN * u;\n"
|
||||||
" printf(\"%d %x %u %f\", u[i], u[i], u[i], u[i]);\n"
|
" printf(\"%d %x %u %f\", u[i], u[i], u[i], u[i]);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" long * l;\n"
|
" long * l;\n"
|
||||||
" printf(\"%d %x %u %f\", l[i], l[i], l[i], l[i]);\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"
|
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) %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"
|
"[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"
|
" printf(\"%u\",v6[0]);\n"
|
||||||
" myvector<char *> v7(1,0);\n"
|
" myvector<char *> v7(1,0);\n"
|
||||||
" printf(\"%s\",v7[0]);\n"
|
" printf(\"%s\",v7[0]);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("std::vector<char> v;\n" // #5151
|
check("std::vector<char> v;\n" // #5151
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" printf(\"%c %u %f\", v.at(32), v.at(32), v.at(32));\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"
|
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());
|
"[test.cpp:3]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'char'.\n", errout.str());
|
||||||
|
|
||||||
// #5195 (segmentation fault)
|
// #5195 (segmentation fault)
|
||||||
check("void T::a(const std::vector<double>& vx) {\n"
|
check("void T::a(const std::vector<double>& vx) {\n"
|
||||||
" printf(\"%f\", vx.at(0));\n"
|
" printf(\"%f\", vx.at(0));\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// #5486
|
// #5486
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" ssize_t test = 0;\n"
|
" ssize_t test = 0;\n"
|
||||||
" printf(\"%zd\", test);\n"
|
" printf(\"%zd\", test);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// #6009
|
// #6009
|
||||||
|
@ -3165,7 +3165,7 @@ private:
|
||||||
"extern int IntByReturnValue();\n"
|
"extern int IntByReturnValue();\n"
|
||||||
"void MyFunction() {\n"
|
"void MyFunction() {\n"
|
||||||
" printf( \"%s - %s\", StringByReturnValue(), IntByReturnValue() );\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"
|
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());
|
"[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<int, 10> array1;\n"
|
" Array<int, 10> array1;\n"
|
||||||
" Array<float, 10> array2;\n"
|
" Array<float, 10> array2;\n"
|
||||||
" printf(\"%u %u\", array1[0], array2[0]);\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"
|
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());
|
"[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
|
void testTernary() { // ticket #6182
|
||||||
check("void test(const std::string &val) {\n"
|
check("void test(const std::string &val) {\n"
|
||||||
" printf(\"%s\", val.empty() ? \"I like to eat bananas\" : val.c_str());\n"
|
" printf(\"%s\", val.empty() ? \"I like to eat bananas\" : val.c_str());\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4719,30 +4719,30 @@ private:
|
||||||
check("void test() {\n"
|
check("void test() {\n"
|
||||||
" unsigned const x = 5;\n"
|
" unsigned const x = 5;\n"
|
||||||
" printf(\"%u\", x);\n"
|
" printf(\"%u\", x);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void testAstType() { // ticket #7014
|
void testAstType() { // ticket #7014
|
||||||
check("void test() {\n"
|
check("void test() {\n"
|
||||||
" printf(\"%c\", \"hello\"[0]);\n"
|
" printf(\"%c\", \"hello\"[0]);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void test() {\n"
|
check("void test() {\n"
|
||||||
" printf(\"%lld\", (long long)1);\n"
|
" printf(\"%lld\", (long long)1);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void test() {\n"
|
check("void test() {\n"
|
||||||
" printf(\"%i\", (short *)x);\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());
|
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
|
check("int (*fp)();\n" // #7178 - function pointer call
|
||||||
"void test() {\n"
|
"void test() {\n"
|
||||||
" printf(\"%i\", fp());\n"
|
" printf(\"%i\", fp());\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4750,7 +4750,7 @@ private:
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" printf(\"%u %lu %llu\", 0U, 0UL, 0ULL);\n"
|
" printf(\"%u %lu %llu\", 0U, 0UL, 0ULL);\n"
|
||||||
" printf(\"%u %lu %llu\", 0u, 0ul, 0ull);\n"
|
" printf(\"%u %lu %llu\", 0u, 0ul, 0ull);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4806,17 +4806,17 @@ private:
|
||||||
void testPrintfParenthesis() { // #8489
|
void testPrintfParenthesis() { // #8489
|
||||||
check("void f(int a) {\n"
|
check("void f(int a) {\n"
|
||||||
" printf(\"%f\", (a >> 24) & 0xff);\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());
|
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"
|
check("void f(int a) {\n"
|
||||||
" printf(\"%f\", 0xff & (a >> 24));\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());
|
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"
|
check("void f(int a) {\n"
|
||||||
" printf(\"%f\", ((a >> 24) + 1) & 0xff);\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());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'.\n", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -615,14 +615,14 @@ private:
|
||||||
check("struct Foo { int* ptr; };\n"
|
check("struct Foo { int* ptr; };\n"
|
||||||
"void f(Foo* foo) {\n"
|
"void f(Foo* foo) {\n"
|
||||||
" delete foo->ptr;\n"
|
" delete foo->ptr;\n"
|
||||||
" foo->ptr = new Foo; \n"
|
" foo->ptr = new Foo;\n"
|
||||||
"}", true);
|
"}", true);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct Foo { int* ptr; };\n"
|
check("struct Foo { int* ptr; };\n"
|
||||||
"void f(Foo* foo) {\n"
|
"void f(Foo* foo) {\n"
|
||||||
" delete foo->ptr;\n"
|
" delete foo->ptr;\n"
|
||||||
" x = *foo->ptr; \n"
|
" x = *foo->ptr;\n"
|
||||||
"}", true);
|
"}", true);
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Dereferencing 'ptr' after it is deallocated / released\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Dereferencing 'ptr' after it is deallocated / released\n", errout.str());
|
||||||
|
|
||||||
|
|
|
@ -230,7 +230,7 @@ private:
|
||||||
" free(buf);\n"
|
" free(buf);\n"
|
||||||
" else\n"
|
" else\n"
|
||||||
" free(new_buf);\n"
|
" free(new_buf);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" free(pData);\n"
|
" free(pData);\n"
|
||||||
" return true;\n"
|
" return true;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +256,7 @@ private:
|
||||||
" if (!m_buf) {\n"
|
" if (!m_buf) {\n"
|
||||||
" m_buf = origBuf;\n"
|
" m_buf = origBuf;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ private:
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" x = realloc(x,100);\n"
|
" x = realloc(x,100);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ private:
|
||||||
" pa = pb = malloc(10);\n"
|
" pa = pb = malloc(10);\n"
|
||||||
" pa = realloc(pa, 20);"
|
" pa = realloc(pa, 20);"
|
||||||
" exit();\n"
|
" exit();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +285,7 @@ private:
|
||||||
" if (!p)\n"
|
" if (!p)\n"
|
||||||
" error();\n"
|
" error();\n"
|
||||||
" usep(p);\n"
|
" usep(p);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ private:
|
||||||
" if (!p)\n"
|
" if (!p)\n"
|
||||||
" error();\n"
|
" error();\n"
|
||||||
" usep(p);\n"
|
" usep(p);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ private:
|
||||||
" if( m_options == NULL )\n"
|
" if( m_options == NULL )\n"
|
||||||
" return false;\n"
|
" return false;\n"
|
||||||
" return true;\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());
|
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"
|
" if (zLine) {\n"
|
||||||
" free(zLine);\n"
|
" free(zLine);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1559,7 +1559,7 @@ private:
|
||||||
" data_ = new char[42];\n"
|
" data_ = new char[42];\n"
|
||||||
" delete data_;\n"
|
" delete data_;\n"
|
||||||
" data_ = 0;\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"
|
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());
|
"[test.cpp:18]: (error) Mismatching allocation and deallocation: Foo::data_\n", errout.str());
|
||||||
|
|
||||||
|
@ -1582,7 +1582,7 @@ private:
|
||||||
" data_ = new char[42];\n"
|
" data_ = new char[42];\n"
|
||||||
" delete data_;\n"
|
" delete data_;\n"
|
||||||
" data_ = 0;\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"
|
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());
|
"[test.cpp:18]: (error) Mismatching allocation and deallocation: Foo::data_\n", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -2438,18 +2438,18 @@ private:
|
||||||
void resourceLeak() {
|
void resourceLeak() {
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" fopen(\"file.txt\", \"r\");\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());
|
ASSERT_EQUALS("[test.cpp:2]: (error) Return value of allocation function 'fopen' is not stored.\n", errout.str());
|
||||||
|
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" FILE f* = fopen(\"file.txt\", \"r\");\n"
|
" FILE f* = fopen(\"file.txt\", \"r\");\n"
|
||||||
" freopen(\"file.txt\", \"r\", f);\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());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Return value of allocation function 'freopen' is not stored.\n", errout.str());
|
||||||
|
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" freopen(\"file.txt\", \"r\", stdin);\n"
|
" freopen(\"file.txt\", \"r\", stdin);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct Holder {\n"
|
check("struct Holder {\n"
|
||||||
|
@ -2459,7 +2459,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" Holder h ( fopen(\"file.txt\", \"r\"));\n"
|
" Holder h ( fopen(\"file.txt\", \"r\"));\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct Holder {\n"
|
check("struct Holder {\n"
|
||||||
|
@ -2469,7 +2469,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" Holder ( fopen(\"file.txt\", \"r\"));\n"
|
" Holder ( fopen(\"file.txt\", \"r\"));\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct Holder {\n"
|
check("struct Holder {\n"
|
||||||
|
@ -2479,7 +2479,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" Holder h { fopen(\"file.txt\", \"r\")};\n"
|
" Holder h { fopen(\"file.txt\", \"r\")};\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct Holder {\n"
|
check("struct Holder {\n"
|
||||||
|
@ -2489,7 +2489,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" Holder h = fopen(\"file.txt\", \"r\");\n"
|
" Holder h = fopen(\"file.txt\", \"r\");\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct Holder {\n"
|
check("struct Holder {\n"
|
||||||
|
@ -2499,7 +2499,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" Holder { fopen(\"file.txt\", \"r\")};\n"
|
" Holder { fopen(\"file.txt\", \"r\")};\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct Holder {\n"
|
check("struct Holder {\n"
|
||||||
|
@ -2509,7 +2509,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" Holder { 0, fopen(\"file.txt\", \"r\")};\n"
|
" Holder { 0, fopen(\"file.txt\", \"r\")};\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -275,7 +275,7 @@ private:
|
||||||
" while (tok) tok = tok->next();\n"
|
" while (tok) tok = tok->next();\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" tok->str();\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());
|
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"
|
check("int foo(const Token *tok)\n"
|
||||||
|
@ -300,7 +300,7 @@ private:
|
||||||
" while (d && d->i == 0)\n"
|
" while (d && d->i == 0)\n"
|
||||||
" d = d->c;\n"
|
" d = d->c;\n"
|
||||||
" if (!d) throw;\n"
|
" if (!d) throw;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct b {\n"
|
check("struct b {\n"
|
||||||
|
@ -1425,11 +1425,11 @@ private:
|
||||||
|
|
||||||
void nullpointer28() { // #6491
|
void nullpointer28() { // #6491
|
||||||
check("typedef struct { int value; } S;\n"
|
check("typedef struct { int value; } S;\n"
|
||||||
"int f(const S *s) { \n"
|
"int f(const S *s) {\n"
|
||||||
" int i = s ? s->value + 1 \n"
|
" int i = s ? s->value + 1\n"
|
||||||
" : s->value - 1; // <-- null ptr dereference \n"
|
" : s->value - 1; // <-- null ptr dereference\n"
|
||||||
" return i;\n"
|
" return i;\n"
|
||||||
"}\n");
|
"}");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (warning) Possible null pointer dereference: s\n", "", errout.str());
|
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<std::string> *values)\n"
|
check("void f(std::vector<std::string> *values)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" values->clear();\n"
|
" values->clear();\n"
|
||||||
" if (values) \n"
|
" if (values)\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
" for (int i = 0; i < values->size(); ++i)\n"
|
" for (int i = 0; i < values->size(); ++i)\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
|
@ -1455,7 +1455,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
" \n"
|
"\n"
|
||||||
"static void foo(F* f)\n"
|
"static void foo(F* f)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" if( f ) {}\n"
|
" if( f ) {}\n"
|
||||||
|
@ -1573,7 +1573,7 @@ private:
|
||||||
"void f(struct A *a) {\n"
|
"void f(struct A *a) {\n"
|
||||||
" if (a->x == NULL) {}\n"
|
" if (a->x == NULL) {}\n"
|
||||||
" *(a->x);\n"
|
" *(a->x);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS(
|
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",
|
"[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());
|
errout.str());
|
||||||
|
@ -1584,7 +1584,7 @@ private:
|
||||||
"void f(struct A *a) {\n"
|
"void f(struct A *a) {\n"
|
||||||
" if (a->x == nullptr) {}\n"
|
" if (a->x == nullptr) {}\n"
|
||||||
" *(a->x);\n"
|
" *(a->x);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS(
|
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",
|
"[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());
|
errout.str());
|
||||||
|
@ -1595,7 +1595,7 @@ private:
|
||||||
"void f(struct A *a) {\n"
|
"void f(struct A *a) {\n"
|
||||||
" if (a->g() == nullptr) {}\n"
|
" if (a->g() == nullptr) {}\n"
|
||||||
" *(a->g());\n"
|
" *(a->g());\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS(
|
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",
|
"[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());
|
errout.str());
|
||||||
|
@ -1604,7 +1604,7 @@ private:
|
||||||
"void f(struct A *a) {\n"
|
"void f(struct A *a) {\n"
|
||||||
" if (a->g() == nullptr) {}\n"
|
" if (a->g() == nullptr) {}\n"
|
||||||
" *(a->g());\n"
|
" *(a->g());\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1613,7 +1613,7 @@ private:
|
||||||
"void f(struct A *a) {\n"
|
"void f(struct A *a) {\n"
|
||||||
" if (a->g() == nullptr) {}\n"
|
" if (a->g() == nullptr) {}\n"
|
||||||
" *(a->g());\n"
|
" *(a->g());\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS(
|
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",
|
"[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());
|
errout.str());
|
||||||
|
@ -1626,7 +1626,7 @@ private:
|
||||||
" if (x) {\n"
|
" if (x) {\n"
|
||||||
" (void)*a->x;\n"
|
" (void)*a->x;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1638,7 +1638,7 @@ private:
|
||||||
" if ( w == 0.0 )\n"
|
" if ( w == 0.0 )\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
" return b->get();\n"
|
" return b->get();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
// #9423
|
// #9423
|
||||||
check("extern F* GetF();\n"
|
check("extern F* GetF();\n"
|
||||||
|
@ -1655,7 +1655,7 @@ private:
|
||||||
" if (!lPtrOk)\n"
|
" if (!lPtrOk)\n"
|
||||||
" return;\n"
|
" return;\n"
|
||||||
" lPtr->Clear();\n"
|
" lPtr->Clear();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1672,7 +1672,7 @@ private:
|
||||||
" g();\n"
|
" g();\n"
|
||||||
" a d = *c->b();\n"
|
" a d = *c->b();\n"
|
||||||
" return d;\n"
|
" return d;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct a {\n"
|
check("struct a {\n"
|
||||||
|
@ -1688,7 +1688,7 @@ private:
|
||||||
" e();\n"
|
" e();\n"
|
||||||
" a d = *c->b();\n"
|
" a d = *c->b();\n"
|
||||||
" return d;\n"
|
" return d;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1696,7 +1696,7 @@ private:
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" char* p = new(std::nothrow) char[1];\n"
|
" char* p = new(std::nothrow) char[1];\n"
|
||||||
" if( p ) {}\n"
|
" if( p ) {}\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1705,7 +1705,7 @@ private:
|
||||||
" if(!p[0]) {}\n"
|
" if(!p[0]) {}\n"
|
||||||
" const int *const a = p;\n"
|
" const int *const a = p;\n"
|
||||||
" if(!a){}\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());
|
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"
|
"auto f(T& x) -> decltype(x);\n"
|
||||||
"int& g(int* x) {\n"
|
"int& g(int* x) {\n"
|
||||||
" return f(*x);\n"
|
" return f(*x);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1724,7 +1724,7 @@ private:
|
||||||
" if(n > 10) q = p;\n"
|
" if(n > 10) q = p;\n"
|
||||||
" *p +=2;\n"
|
" *p +=2;\n"
|
||||||
" if(n < 120) *q+=12;\n"
|
" if(n < 120) *q+=12;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (warning) Possible null pointer dereference: q\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (warning) Possible null pointer dereference: q\n", errout.str());
|
||||||
|
|
||||||
check("void f(int *p, int n) {\n"
|
check("void f(int *p, int n) {\n"
|
||||||
|
@ -1732,7 +1732,7 @@ private:
|
||||||
" if(n > 10) q = p;\n"
|
" if(n > 10) q = p;\n"
|
||||||
" *p +=2;\n"
|
" *p +=2;\n"
|
||||||
" if(n > 10) *q+=12;\n"
|
" if(n > 10) *q+=12;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1746,7 +1746,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS(
|
ASSERT_EQUALS(
|
||||||
"[test.cpp:2] -> [test.cpp:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p.\n",
|
"[test.cpp:2] -> [test.cpp:6]: (warning) Either the condition '!p' is redundant or there is possible null pointer dereference: p.\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
|
@ -1762,7 +1762,7 @@ private:
|
||||||
" if (c(e, \"\"))\n"
|
" if (c(e, \"\"))\n"
|
||||||
" return nullptr;\n"
|
" return nullptr;\n"
|
||||||
" return e->b();\n"
|
" return e->b();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1772,7 +1772,7 @@ private:
|
||||||
" if(b) c = b;\n"
|
" if(b) c = b;\n"
|
||||||
" if (!c) c = &a;\n"
|
" if (!c) c = &a;\n"
|
||||||
" return *c;\n"
|
" return *c;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("int f(int a, int* b) {\n"
|
check("int f(int a, int* b) {\n"
|
||||||
|
@ -1781,7 +1781,7 @@ private:
|
||||||
" bool d = !c;\n"
|
" bool d = !c;\n"
|
||||||
" if (d) c = &a;\n"
|
" if (d) c = &a;\n"
|
||||||
" return *c;\n"
|
" return *c;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct A { int* x; };\n"
|
check("struct A { int* x; };\n"
|
||||||
|
@ -1791,7 +1791,7 @@ private:
|
||||||
" if(b) c.x = b;\n"
|
" if(b) c.x = b;\n"
|
||||||
" if (!c.x) c.x = &a;\n"
|
" if (!c.x) c.x = &a;\n"
|
||||||
" return *c.x;\n"
|
" return *c.x;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct A { int* x; };\n"
|
check("struct A { int* x; };\n"
|
||||||
|
@ -1802,7 +1802,7 @@ private:
|
||||||
" bool d = !c.x;\n"
|
" bool d = !c.x;\n"
|
||||||
" if (d) c.x = &a;\n"
|
" if (d) c.x = &a;\n"
|
||||||
" return *c.x;\n"
|
" return *c.x;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct A { int* x; };\n"
|
check("struct A { int* x; };\n"
|
||||||
|
@ -1825,7 +1825,7 @@ private:
|
||||||
"}\n"
|
"}\n"
|
||||||
"void bar() {\n"
|
"void bar() {\n"
|
||||||
" f(0, 0);\n"
|
" f(0, 0);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Possible null pointer dereference: params\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (warning) Possible null pointer dereference: params\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1837,11 +1837,11 @@ private:
|
||||||
" return 1;\n"
|
" return 1;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
"} \n"
|
"}\n"
|
||||||
"int bar() {\n"
|
"int bar() {\n"
|
||||||
" int **array = NULL; \n"
|
" int **array = NULL;\n"
|
||||||
" foo (array, 0);\n"
|
" foo (array, 0);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1851,7 +1851,7 @@ private:
|
||||||
" while (tok3->astParent() && tok3->str() == \",\")\n"
|
" while (tok3->astParent() && tok3->str() == \",\")\n"
|
||||||
" tok3 = tok3->astParent();\n"
|
" tok3 = tok3->astParent();\n"
|
||||||
" if (tok3 && tok3->str() == \"(\") {}\n"
|
" if (tok3 && tok3->str() == \"(\") {}\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS(
|
ASSERT_EQUALS(
|
||||||
"[test.cpp:5] -> [test.cpp:3]: (warning) Either the condition 'tok3' is redundant or there is possible null pointer dereference: tok3.\n",
|
"[test.cpp:5] -> [test.cpp:3]: (warning) Either the condition 'tok3' is redundant or there is possible null pointer dereference: tok3.\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
|
@ -1864,7 +1864,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
" if (!t1 || !t2)\n"
|
" if (!t1 || !t2)\n"
|
||||||
" return;\n"
|
" return;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("bool f(int* i);\n"
|
check("bool f(int* i);\n"
|
||||||
|
@ -1872,7 +1872,7 @@ private:
|
||||||
" while(f(i) && *i == 0)\n"
|
" while(f(i) && *i == 0)\n"
|
||||||
" i++;\n"
|
" i++;\n"
|
||||||
" if (!i) {}\n"
|
" if (!i) {}\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1884,7 +1884,7 @@ private:
|
||||||
" ListEntry *prev = NULL;\n"
|
" ListEntry *prev = NULL;\n"
|
||||||
" for (ListEntry *cursor = listHead; cursor != NULL; prev = cursor, cursor = cursor->next) {}\n"
|
" for (ListEntry *cursor = listHead; cursor != NULL; prev = cursor, cursor = cursor->next) {}\n"
|
||||||
" if (prev) {}\n"
|
" if (prev) {}\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2908,7 +2908,7 @@ private:
|
||||||
"void f(int* x) {\n"
|
"void f(int* x) {\n"
|
||||||
" if (x)\n"
|
" if (x)\n"
|
||||||
" g(x);\n"
|
" g(x);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3134,42 +3134,42 @@ private:
|
||||||
"void f(std::shared_ptr<Fred> p) {\n"
|
"void f(std::shared_ptr<Fred> p) {\n"
|
||||||
" if (p) {}\n"
|
" if (p) {}\n"
|
||||||
" dostuff(p->x);\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());
|
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"
|
check("struct Fred { int x; };\n"
|
||||||
"void f(std::shared_ptr<Fred> p) {\n"
|
"void f(std::shared_ptr<Fred> p) {\n"
|
||||||
" p = nullptr;\n"
|
" p = nullptr;\n"
|
||||||
" dostuff(p->x);\n"
|
" dostuff(p->x);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str());
|
||||||
|
|
||||||
check("struct Fred { int x; };\n"
|
check("struct Fred { int x; };\n"
|
||||||
"void f(std::unique_ptr<Fred> p) {\n"
|
"void f(std::unique_ptr<Fred> p) {\n"
|
||||||
" if (p) {}\n"
|
" if (p) {}\n"
|
||||||
" dostuff(p->x);\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());
|
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"
|
check("struct Fred { int x; };\n"
|
||||||
"void f(std::unique_ptr<Fred> p) {\n"
|
"void f(std::unique_ptr<Fred> p) {\n"
|
||||||
" p = nullptr;\n"
|
" p = nullptr;\n"
|
||||||
" dostuff(p->x);\n"
|
" dostuff(p->x);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str());
|
||||||
|
|
||||||
check("struct Fred { int x; };\n"
|
check("struct Fred { int x; };\n"
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" std::shared_ptr<Fred> p;\n"
|
" std::shared_ptr<Fred> p;\n"
|
||||||
" dostuff(p->x);\n"
|
" dostuff(p->x);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str());
|
||||||
|
|
||||||
check("struct Fred { int x; };\n"
|
check("struct Fred { int x; };\n"
|
||||||
"void f(std::shared_ptr<Fred> p) {\n"
|
"void f(std::shared_ptr<Fred> p) {\n"
|
||||||
" p.reset();\n"
|
" p.reset();\n"
|
||||||
" dostuff(p->x);\n"
|
" dostuff(p->x);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str());
|
||||||
|
|
||||||
check("struct Fred { int x; };\n"
|
check("struct Fred { int x; };\n"
|
||||||
|
@ -3177,7 +3177,7 @@ private:
|
||||||
" Fred * pp = nullptr;\n"
|
" Fred * pp = nullptr;\n"
|
||||||
" p.reset(pp);\n"
|
" p.reset(pp);\n"
|
||||||
" dostuff(p->x);\n"
|
" dostuff(p->x);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference: p\n", errout.str());
|
||||||
|
|
||||||
check("struct Fred { int x; };\n"
|
check("struct Fred { int x; };\n"
|
||||||
|
@ -3185,28 +3185,28 @@ private:
|
||||||
" std::shared_ptr<Fred> p;\n"
|
" std::shared_ptr<Fred> p;\n"
|
||||||
" p.reset(&f);\n"
|
" p.reset(&f);\n"
|
||||||
" dostuff(p->x);\n"
|
" dostuff(p->x);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct Fred { int x; };\n"
|
check("struct Fred { int x; };\n"
|
||||||
"void f(std::shared_ptr<Fred> p) {\n"
|
"void f(std::shared_ptr<Fred> p) {\n"
|
||||||
" p.release();\n"
|
" p.release();\n"
|
||||||
" dostuff(p->x);\n"
|
" dostuff(p->x);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str());
|
||||||
|
|
||||||
check("struct Fred { int x; };\n"
|
check("struct Fred { int x; };\n"
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" std::shared_ptr<Fred> p(nullptr);\n"
|
" std::shared_ptr<Fred> p(nullptr);\n"
|
||||||
" dostuff(p->x);\n"
|
" dostuff(p->x);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference: p\n", errout.str());
|
||||||
|
|
||||||
check("struct A {};\n"
|
check("struct A {};\n"
|
||||||
"void f(int n) {\n"
|
"void f(int n) {\n"
|
||||||
" std::unique_ptr<const A*[]> p;\n"
|
" std::unique_ptr<const A*[]> p;\n"
|
||||||
" p.reset(new const A*[n]);\n"
|
" p.reset(new const A*[n]);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// #9216
|
// #9216
|
||||||
|
@ -3217,7 +3217,7 @@ private:
|
||||||
"void g(std::unique_ptr<A> var) {\n"
|
"void g(std::unique_ptr<A> var) {\n"
|
||||||
" var->reset();\n"
|
" var->reset();\n"
|
||||||
" var->f();\n"
|
" var->f();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// #9439
|
// #9439
|
||||||
|
@ -3560,7 +3560,7 @@ private:
|
||||||
" unsigned int j;\n"
|
" unsigned int j;\n"
|
||||||
" for (j = 0; j < b[0].a->size; ++j) {\n"
|
" for (j = 0; j < b[0].a->size; ++j) {\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3584,27 +3584,27 @@ private:
|
||||||
check("void foo(char *s) {\n"
|
check("void foo(char *s) {\n"
|
||||||
" p = s - 20;\n"
|
" p = s - 20;\n"
|
||||||
"}\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",
|
ASSERT_EQUALS("[test.cpp:2]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted.\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
|
|
||||||
check("void foo(char *s) {\n"
|
check("void foo(char *s) {\n"
|
||||||
" if (!s) {}\n"
|
" if (!s) {}\n"
|
||||||
" p = s - 20;\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());
|
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"
|
check("void foo(char *s) {\n"
|
||||||
" s -= 20;\n"
|
" s -= 20;\n"
|
||||||
"}\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",
|
ASSERT_EQUALS("[test.cpp:2]: (error) Overflow in pointer arithmetic, NULL pointer is subtracted.\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
|
|
||||||
check("void foo(char *s) {\n"
|
check("void foo(char *s) {\n"
|
||||||
" if (!s) {}\n"
|
" if (!s) {}\n"
|
||||||
" s -= 20;\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());
|
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; }");
|
check("int* f8() { int *x = NULL; return --x; }");
|
||||||
|
@ -3618,48 +3618,48 @@ private:
|
||||||
check("void foo(char *s) {\n"
|
check("void foo(char *s) {\n"
|
||||||
" char * p = s + 20;\n"
|
" char * p = s + 20;\n"
|
||||||
"}\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());
|
ASSERT_EQUALS("[test.cpp:2]: (error) Pointer addition with NULL pointer.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(char *s) {\n"
|
check("void foo(char *s) {\n"
|
||||||
" if (!s) {}\n"
|
" if (!s) {}\n"
|
||||||
" char * p = s + 20;\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());
|
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"
|
check("void foo(char *s) {\n"
|
||||||
" char * p = 20 + s;\n"
|
" char * p = 20 + s;\n"
|
||||||
"}\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());
|
ASSERT_EQUALS("[test.cpp:2]: (error) Pointer addition with NULL pointer.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(char *s) {\n"
|
check("void foo(char *s) {\n"
|
||||||
" if (!s) {}\n"
|
" if (!s) {}\n"
|
||||||
" char * p = 20 + 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());
|
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"
|
check("void foo(char *s) {\n"
|
||||||
" s += 20;\n"
|
" s += 20;\n"
|
||||||
"}\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());
|
ASSERT_EQUALS("[test.cpp:2]: (error) Pointer addition with NULL pointer.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(char *s) {\n"
|
check("void foo(char *s) {\n"
|
||||||
" if (!s) {}\n"
|
" if (!s) {}\n"
|
||||||
" s += 20;\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());
|
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; }");
|
check("int* f7() { int *x = NULL; return ++x; }");
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (error) Pointer addition with NULL pointer.\n", errout.str());
|
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());
|
ASSERT_EQUALS("[test.cpp:1]: (error) Pointer addition with NULL pointer.\n", errout.str());
|
||||||
|
|
||||||
check("class foo {};\n"
|
check("class foo {};\n"
|
||||||
"const char* get() const { return 0; }\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());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3763,7 +3763,7 @@ private:
|
||||||
"void f(int* x) {\n"
|
"void f(int* x) {\n"
|
||||||
" if (x)\n"
|
" if (x)\n"
|
||||||
" g(x);\n"
|
" g(x);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -329,7 +329,7 @@ private:
|
||||||
"\n"
|
"\n"
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" p++;\n"
|
" p++;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2484,7 +2484,7 @@ private:
|
||||||
void template102() { // #9005
|
void template102() { // #9005
|
||||||
const char code[] = "namespace ns {\n"
|
const char code[] = "namespace ns {\n"
|
||||||
"template <class T>\n"
|
"template <class T>\n"
|
||||||
"struct is_floating_point \n"
|
"struct is_floating_point\n"
|
||||||
": std::integral_constant<bool, std::is_floating_point<T>::value || true>\n"
|
": std::integral_constant<bool, std::is_floating_point<T>::value || true>\n"
|
||||||
"{};\n"
|
"{};\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
|
@ -4563,11 +4563,11 @@ private:
|
||||||
|
|
||||||
void syntax_error_templates_1() {
|
void syntax_error_templates_1() {
|
||||||
// ok code.. using ">" for a comparison
|
// ok code.. using ">" for a comparison
|
||||||
tok("x<y>z> xyz;\n");
|
tok("x<y>z> xyz;");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// ok code
|
// ok code
|
||||||
tok("template<class T> operator<(T a, T b) { }\n");
|
tok("template<class T> operator<(T a, T b) { }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// ok code (ticket #1984)
|
// ok code (ticket #1984)
|
||||||
|
@ -4604,7 +4604,7 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" A a;\n"
|
" A a;\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
//both of these should work but in cppcheck 2.1 only the first option will work (ticket #9843)
|
//both of these should work but in cppcheck 2.1 only the first option will work (ticket #9843)
|
||||||
|
|
|
@ -3165,7 +3165,7 @@ private:
|
||||||
const char code[] = "void foo()\n"
|
const char code[] = "void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" char *a, *b;\n"
|
" char *a, *b;\n"
|
||||||
" if (x) \n"
|
" if (x)\n"
|
||||||
" delete a, b;\n"
|
" delete a, b;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
ASSERT_EQUALS("void foo ( ) { char * a ; char * b ; if ( x ) { delete a ; b ; } }", tok(code));
|
ASSERT_EQUALS("void foo ( ) { char * a ; char * b ; if ( x ) { delete a ; b ; } }", tok(code));
|
||||||
|
|
|
@ -223,7 +223,7 @@ private:
|
||||||
" Y = sizeof(f(g() << h())) == sizeof(A),\n"
|
" Y = sizeof(f(g() << h())) == sizeof(A),\n"
|
||||||
" Z = X & Y\n"
|
" Z = X & Y\n"
|
||||||
" };\n"
|
" };\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,8 +231,7 @@ private:
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" int a[10];\n"
|
" int a[10];\n"
|
||||||
" std::cout << sizeof(a) / sizeof(int) << std::endl;\n"
|
" std::cout << sizeof(a) / sizeof(int) << std::endl;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
|
@ -240,8 +239,7 @@ private:
|
||||||
" unsigned int b = 2;\n"
|
" unsigned int b = 2;\n"
|
||||||
" int c[(a+b)];\n"
|
" int c[(a+b)];\n"
|
||||||
" std::cout << sizeof(c) / sizeof(int) << std::endl;\n"
|
" std::cout << sizeof(c) / sizeof(int) << std::endl;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
|
@ -249,8 +247,7 @@ private:
|
||||||
" unsigned int b[] = { 0 };\n"
|
" unsigned int b[] = { 0 };\n"
|
||||||
" int c[a[b[0]]];\n"
|
" int c[a[b[0]]];\n"
|
||||||
" std::cout << sizeof(c) / sizeof(int) << std::endl;\n"
|
" std::cout << sizeof(c) / sizeof(int) << std::endl;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
|
||||||
|
@ -259,42 +256,36 @@ private:
|
||||||
" unsigned int b = 2;\n"
|
" unsigned int b = 2;\n"
|
||||||
" int c[(a[0]+b)];\n"
|
" int c[(a[0]+b)];\n"
|
||||||
" std::cout << sizeof(c) / sizeof(int) << std::endl;\n"
|
" std::cout << sizeof(c) / sizeof(int) << std::endl;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" int a[] = { 1, 2, 3 };\n"
|
" int a[] = { 1, 2, 3 };\n"
|
||||||
" std::cout << sizeof(a) / sizeof(int) << std::endl;\n"
|
" std::cout << sizeof(a) / sizeof(int) << std::endl;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" int a[3] = { 1, 2, 3 };\n"
|
" int a[3] = { 1, 2, 3 };\n"
|
||||||
" std::cout << sizeof(a) / sizeof(int) << std::endl;\n"
|
" std::cout << sizeof(a) / sizeof(int) << std::endl;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f( int a[]) {\n"
|
check("void f( int a[]) {\n"
|
||||||
" std::cout << sizeof(a) / sizeof(int) << std::endl;\n"
|
" std::cout << sizeof(a) / sizeof(int) << std::endl;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Using 'sizeof' on array given as "
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Using 'sizeof' on array given as "
|
||||||
"function argument returns size of a pointer.\n", errout.str());
|
"function argument returns size of a pointer.\n", errout.str());
|
||||||
|
|
||||||
check("void f( int a[]) {\n"
|
check("void f( int a[]) {\n"
|
||||||
" std::cout << sizeof a / sizeof(int) << std::endl;\n"
|
" std::cout << sizeof a / sizeof(int) << std::endl;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Using 'sizeof' on array given as "
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Using 'sizeof' on array given as "
|
||||||
"function argument returns size of a pointer.\n", errout.str());
|
"function argument returns size of a pointer.\n", errout.str());
|
||||||
|
|
||||||
check("void f( int a[3] ) {\n"
|
check("void f( int a[3] ) {\n"
|
||||||
" std::cout << sizeof(a) / sizeof(int) << std::endl;\n"
|
" std::cout << sizeof(a) / sizeof(int) << std::endl;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Using 'sizeof' on array given as "
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Using 'sizeof' on array given as "
|
||||||
"function argument returns size of a pointer.\n", errout.str());
|
"function argument returns size of a pointer.\n", errout.str());
|
||||||
|
|
||||||
|
@ -302,22 +293,19 @@ private:
|
||||||
"int f2(Fixname& f2v) {\n"
|
"int f2(Fixname& f2v) {\n"
|
||||||
" int i = sizeof(f2v);\n"
|
" int i = sizeof(f2v);\n"
|
||||||
" printf(\"sizeof f2v %d\", i);\n"
|
" printf(\"sizeof f2v %d\", i);\n"
|
||||||
" }\n"
|
" }");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f(int *p) {\n"
|
check("void f(int *p) {\n"
|
||||||
" p[0] = 0;\n"
|
" p[0] = 0;\n"
|
||||||
" int unused = sizeof(p);\n"
|
" int unused = sizeof(p);\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" char p[] = \"test\";\n"
|
" char p[] = \"test\";\n"
|
||||||
" int unused = sizeof(p);\n"
|
" int unused = sizeof(p);\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// ticket #2495
|
// ticket #2495
|
||||||
|
@ -331,38 +319,33 @@ private:
|
||||||
" {1,0,1},\n"
|
" {1,0,1},\n"
|
||||||
" };\n"
|
" };\n"
|
||||||
" const int COL_MAX=sizeof(col)/sizeof(col[0]);\n"
|
" const int COL_MAX=sizeof(col)/sizeof(col[0]);\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// ticket #155
|
// ticket #155
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" char buff1[1024*64],buff2[sizeof(buff1)*2];\n"
|
" char buff1[1024*64],buff2[sizeof(buff1)*2];\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// ticket #2510
|
// ticket #2510
|
||||||
check("void f( int a[], int b) {\n"
|
check("void f( int a[], int b) {\n"
|
||||||
" std::cout << sizeof(a) / sizeof(int) << std::endl;\n"
|
" std::cout << sizeof(a) / sizeof(int) << std::endl;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Using 'sizeof' on array given as "
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Using 'sizeof' on array given as "
|
||||||
"function argument returns size of a pointer.\n", errout.str());
|
"function argument returns size of a pointer.\n", errout.str());
|
||||||
|
|
||||||
// ticket #2510
|
// ticket #2510
|
||||||
check("void f( int a[3] , int b[2] ) {\n"
|
check("void f( int a[3] , int b[2] ) {\n"
|
||||||
" std::cout << sizeof(a) / sizeof(int) << std::endl;\n"
|
" std::cout << sizeof(a) / sizeof(int) << std::endl;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Using 'sizeof' on array given as "
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Using 'sizeof' on array given as "
|
||||||
"function argument returns size of a pointer.\n", errout.str());
|
"function argument returns size of a pointer.\n", errout.str());
|
||||||
|
|
||||||
// ticket #2510
|
// ticket #2510
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" char buff1[1024*64],buff2[sizeof(buff1)*(2+1)];\n"
|
" char buff1[1024*64],buff2[sizeof(buff1)*(2+1)];\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -370,22 +353,22 @@ private:
|
||||||
void sizeofForNumericParameter() {
|
void sizeofForNumericParameter() {
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" std::cout << sizeof(10) << std::endl;\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());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter.\n", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" std::cout << sizeof(-10) << std::endl;\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());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter.\n", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" std::cout << sizeof 10 << std::endl;\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());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter.\n", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" std::cout << sizeof -10 << std::endl;\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());
|
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"
|
" char x = *((char*)(foo.data+1));\n"
|
||||||
" foo.data++;\n"
|
" foo.data++;\n"
|
||||||
" return x;\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"
|
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());
|
"[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"
|
"};\n"
|
||||||
"void f4(struct BOO* boo) {\n"
|
"void f4(struct BOO* boo) {\n"
|
||||||
" char c = *((char*)boo->data.data + 1);\n"
|
" char c = *((char*)boo->data.data + 1);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("struct FOO {\n"
|
check("struct FOO {\n"
|
||||||
|
@ -882,7 +865,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"char f(struct FOO* foo) {\n"
|
"char f(struct FOO* foo) {\n"
|
||||||
" *(foo[1].data + 1) = 0;\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());
|
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"
|
check("struct FOO {\n"
|
||||||
|
@ -895,7 +878,7 @@ private:
|
||||||
|
|
||||||
// #6050 arithmetic on void**
|
// #6050 arithmetic on void**
|
||||||
check("void* array[10];\n"
|
check("void* array[10];\n"
|
||||||
"void** b = array + 3;\n");
|
"void** b = array + 3;");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -904,7 +887,7 @@ private:
|
||||||
check("char strncat ();\n"
|
check("char strncat ();\n"
|
||||||
"int main () {\n"
|
"int main () {\n"
|
||||||
" return strncat ();\n"
|
" return strncat ();\n"
|
||||||
"}\n");
|
"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
162
test/teststl.cpp
162
test/teststl.cpp
|
@ -225,7 +225,7 @@ private:
|
||||||
checkNormal("void f(std::vector<int> v) {\n"
|
checkNormal("void f(std::vector<int> v) {\n"
|
||||||
" v.front();\n"
|
" v.front();\n"
|
||||||
" if (v.empty()) {}\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"
|
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:3:note:condition 'v.empty()'\n"
|
||||||
"test.cpp:2:note:Access out of bounds\n", errout.str());
|
"test.cpp:2:note:Access out of bounds\n", errout.str());
|
||||||
|
@ -233,7 +233,7 @@ private:
|
||||||
checkNormal("void f(std::vector<int> v) {\n"
|
checkNormal("void f(std::vector<int> v) {\n"
|
||||||
" if (v.size() == 3) {}\n"
|
" if (v.size() == 3) {}\n"
|
||||||
" v[16] = 0;\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"
|
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:2:note:condition 'v.size()==3'\n"
|
||||||
"test.cpp:3:note:Access out of bounds\n", errout.str());
|
"test.cpp:3:note:Access out of bounds\n", errout.str());
|
||||||
|
@ -243,7 +243,7 @@ private:
|
||||||
" if (v.size() == 3) {\n"
|
" if (v.size() == 3) {\n"
|
||||||
" v[i] = 0;\n"
|
" v[i] = 0;\n"
|
||||||
" }\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"
|
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:3:note:condition 'v.size()==3'\n"
|
||||||
"test.cpp:4:note:Access out of bounds\n", errout.str());
|
"test.cpp:4:note:Access out of bounds\n", errout.str());
|
||||||
|
@ -251,19 +251,19 @@ private:
|
||||||
checkNormal("void f(std::vector<int> v, int i) {\n"
|
checkNormal("void f(std::vector<int> v, int i) {\n"
|
||||||
" if (v.size() == 3 || i == 16) {}\n"
|
" if (v.size() == 3 || i == 16) {}\n"
|
||||||
" v[i] = 0;\n"
|
" v[i] = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkNormal("void f(std::map<int,int> x) {\n"
|
checkNormal("void f(std::map<int,int> x) {\n"
|
||||||
" if (x.empty()) { x[1] = 2; }\n"
|
" if (x.empty()) { x[1] = 2; }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkNormal("void f(std::string s) {\n"
|
checkNormal("void f(std::string s) {\n"
|
||||||
" if (s.size() == 1) {\n"
|
" if (s.size() == 1) {\n"
|
||||||
" s[2] = 0;\n"
|
" s[2] = 0;\n"
|
||||||
" }\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"
|
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:2:note:condition 's.size()==1'\n"
|
||||||
"test.cpp:3:note:Access out of bounds\n", errout.str());
|
"test.cpp:3:note:Access out of bounds\n", errout.str());
|
||||||
|
@ -273,47 +273,47 @@ private:
|
||||||
" std::string b[];\n"
|
" std::string b[];\n"
|
||||||
" for (auto c : b)\n"
|
" for (auto c : b)\n"
|
||||||
" c.data();\n"
|
" c.data();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkNormal("std::string f(std::string x) {\n"
|
checkNormal("std::string f(std::string x) {\n"
|
||||||
" if (x.empty()) return {};\n"
|
" if (x.empty()) return {};\n"
|
||||||
" x[0];\n"
|
" x[0];\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkNormal("std::string f(std::string x) {\n"
|
checkNormal("std::string f(std::string x) {\n"
|
||||||
" if (x.empty()) return std::string{};\n"
|
" if (x.empty()) return std::string{};\n"
|
||||||
" x[0];\n"
|
" x[0];\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkNormal("void f() {\n"
|
checkNormal("void f() {\n"
|
||||||
" std::string s;\n"
|
" std::string s;\n"
|
||||||
" x = s.begin() + 1;\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());
|
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"
|
checkNormal("void f(int x) {\n"
|
||||||
" std::string s;\n"
|
" std::string s;\n"
|
||||||
" x = s.begin() + x;\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());
|
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 = \"<a><b>\"; return s[42]; }\n"
|
checkNormal("char fstr1(){const std::string s = \"<a><b>\"; return s[42]; }\n"
|
||||||
"wchar_t fwstr1(){const std::wstring s = L\"<a><b>\"; return s[42]; }\n");
|
"wchar_t fwstr1(){const std::wstring s = L\"<a><b>\"; 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"
|
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());
|
"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 = \"<a><b>\"; return s[1]; }\n"
|
checkNormal("char fstr1(){const std::string s = \"<a><b>\"; return s[1]; }\n"
|
||||||
"wchar_t fwstr1(){const std::wstring s = L\"<a><b>\"; return s[1]; }\n");
|
"wchar_t fwstr1(){const std::wstring s = L\"<a><b>\"; return s[1]; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkNormal("int f() {\n"
|
checkNormal("int f() {\n"
|
||||||
" std::vector<int> v;\n"
|
" std::vector<int> v;\n"
|
||||||
" std::vector<int> * pv = &v;\n"
|
" std::vector<int> * pv = &v;\n"
|
||||||
" return (*pv)[42];\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());
|
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"
|
checkNormal("void f() {\n"
|
||||||
|
@ -328,14 +328,14 @@ private:
|
||||||
" int x = 6;\n"
|
" int x = 6;\n"
|
||||||
" if(b) ++x;\n"
|
" if(b) ++x;\n"
|
||||||
" return s[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());
|
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"
|
checkNormal("void f() {\n"
|
||||||
" static const int N = 4;\n"
|
" static const int N = 4;\n"
|
||||||
" std::array<int, N> x;\n"
|
" std::array<int, N> x;\n"
|
||||||
" x[0] = 0;\n"
|
" x[0] = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkNormal("void f(bool b) {\n"
|
checkNormal("void f(bool b) {\n"
|
||||||
|
@ -1165,7 +1165,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"bool A::B::operator==(const A::B& b) const {\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"
|
" return std::tie(x, y, z) == std::tie(b.x, b.y, b.z);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1173,29 +1173,29 @@ private:
|
||||||
// #9556
|
// #9556
|
||||||
check("void f(int a, int b) {\n"
|
check("void f(int a, int b) {\n"
|
||||||
" if (&a == &b) {}\n"
|
" if (&a == &b) {}\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f(int a, int b) {\n"
|
check("void f(int a, int b) {\n"
|
||||||
" if (std::for_each(&a, &b + 1, [](auto) {})) {}\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",
|
ASSERT_EQUALS("[test.cpp:2]: (error) Iterators of different containers 'a' and 'b' are used together.\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
|
|
||||||
check("void f(int a, int b) {\n"
|
check("void f(int a, int b) {\n"
|
||||||
" if (std::for_each(&a, &b, [](auto) {})) {}\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",
|
ASSERT_EQUALS("[test.cpp:2]: (error) Iterators of different containers 'a' and 'b' are used together.\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
|
|
||||||
check("void f(int a) {\n"
|
check("void f(int a) {\n"
|
||||||
" if (std::for_each(&a, &a, [](auto) {})) {}\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());
|
ASSERT_EQUALS("[test.cpp:2]: (style) Same iterators expression are used for algorithm.\n", errout.str());
|
||||||
|
|
||||||
check("void f(int a) {\n"
|
check("void f(int a) {\n"
|
||||||
" if (std::for_each(&a, &a + 1, [](auto) {})) {}\n"
|
" if (std::for_each(&a, &a + 1, [](auto) {})) {}\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1208,7 +1208,7 @@ private:
|
||||||
" bool operator()(const S& lhs, const S& rhs) const {\n"
|
" bool operator()(const S& lhs, const S& rhs) const {\n"
|
||||||
" return &lhs.v != &rhs.v;\n"
|
" return &lhs.v != &rhs.v;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1217,21 +1217,21 @@ private:
|
||||||
"std::vector<int>& g();\n"
|
"std::vector<int>& g();\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" (void)std::find(f().begin(), g().end(), 0);\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());
|
ASSERT_EQUALS("[test.cpp:4]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together.\n", errout.str());
|
||||||
|
|
||||||
check("std::vector<int>& f();\n"
|
check("std::vector<int>& f();\n"
|
||||||
"std::vector<int>& g();\n"
|
"std::vector<int>& g();\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" if(f().begin() == g().end()) {}\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());
|
ASSERT_EQUALS("[test.cpp:4]: (warning) Iterators to containers from different expressions 'f()' and 'g()' are used together.\n", errout.str());
|
||||||
|
|
||||||
check("std::vector<int>& f();\n"
|
check("std::vector<int>& f();\n"
|
||||||
"std::vector<int>& g();\n"
|
"std::vector<int>& g();\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" auto size = f().end() - g().begin();\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());
|
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"
|
check("struct A {\n"
|
||||||
|
@ -1240,7 +1240,7 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" (void)std::find(A().f().begin(), A().g().end(), 0);\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());
|
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"
|
check("struct A {\n"
|
||||||
|
@ -1249,14 +1249,14 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" (void)std::find(A{} .f().begin(), A{} .g().end(), 0);\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());
|
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<int>& f();\n"
|
check("std::vector<int>& f();\n"
|
||||||
"std::vector<int>& g();\n"
|
"std::vector<int>& g();\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" (void)std::find(begin(f()), end(g()), 0);\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());
|
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"
|
check("struct A {\n"
|
||||||
|
@ -1265,14 +1265,14 @@ private:
|
||||||
"};\n"
|
"};\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" (void)std::find(A().f().begin(), A().f().end(), 0);\n"
|
" (void)std::find(A().f().begin(), A().f().end(), 0);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("std::vector<int>& f();\n"
|
check("std::vector<int>& f();\n"
|
||||||
"std::vector<int>& g();\n"
|
"std::vector<int>& g();\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" if(bar(f().begin()) == g().end()) {}\n"
|
" if(bar(f().begin()) == g().end()) {}\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("std::vector<int>& f();\n"
|
check("std::vector<int>& f();\n"
|
||||||
|
@ -1297,7 +1297,7 @@ private:
|
||||||
" (void)std::find(begin(f()) + 1, end(f()), 0);\n"
|
" (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()), end(f()) - 1, 0);\n"
|
||||||
" (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\n"
|
" (void)std::find(begin(f()) + 1, end(f()) - 1, 0);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("std::vector<int>& f();\n"
|
check("std::vector<int>& f();\n"
|
||||||
|
@ -1307,65 +1307,65 @@ private:
|
||||||
" if(f().begin() == f().end()+1) {}\n"
|
" if(f().begin() == f().end()+1) {}\n"
|
||||||
" if(f().begin()+1 == f().end()) {}\n"
|
" if(f().begin()+1 == f().end()) {}\n"
|
||||||
" if(f().begin()+1 == f().end()+1) {}\n"
|
" if(f().begin()+1 == f().end()+1) {}\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("template<int N>\n"
|
check("template<int N>\n"
|
||||||
"std::vector<int>& f();\n"
|
"std::vector<int>& f();\n"
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" if(f<1>().begin() == f<1>().end()) {}\n"
|
" if(f<1>().begin() == f<1>().end()) {}\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" if (a.begin().x == b.begin().x) {}\n"
|
" if (a.begin().x == b.begin().x) {}\n"
|
||||||
" if (begin(a).x == begin(b).x) {}\n"
|
" if (begin(a).x == begin(b).x) {}\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f(std::list<int*> a, std::list<int*> b) {\n"
|
check("void f(std::list<int*> a, std::list<int*> b) {\n"
|
||||||
" if (*a.begin() == *b.begin()) {}\n"
|
" if (*a.begin() == *b.begin()) {}\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" if(f().begin(1) == f().end()) {}\n"
|
" if(f().begin(1) == f().end()) {}\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void iteratorSameExpression() {
|
void iteratorSameExpression() {
|
||||||
check("void f(std::vector<int> v) {\n"
|
check("void f(std::vector<int> v) {\n"
|
||||||
" std::for_each(v.begin(), v.begin(), [](int){});\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());
|
ASSERT_EQUALS("[test.cpp:2]: (style) Same iterators expression are used for algorithm.\n", errout.str());
|
||||||
|
|
||||||
check("std::vector<int>& g();\n"
|
check("std::vector<int>& g();\n"
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" std::for_each(g().begin(), g().begin(), [](int){});\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());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Same iterators expression are used for algorithm.\n", errout.str());
|
||||||
|
|
||||||
check("void f(std::vector<int> v) {\n"
|
check("void f(std::vector<int> v) {\n"
|
||||||
" std::for_each(v.end(), v.end(), [](int){});\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());
|
ASSERT_EQUALS("[test.cpp:2]: (style) Same iterators expression are used for algorithm.\n", errout.str());
|
||||||
|
|
||||||
check("std::vector<int>& g();\n"
|
check("std::vector<int>& g();\n"
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" std::for_each(g().end(), g().end(), [](int){});\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());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Same iterators expression are used for algorithm.\n", errout.str());
|
||||||
|
|
||||||
check("std::vector<int>::iterator g();\n"
|
check("std::vector<int>::iterator g();\n"
|
||||||
"void f(std::vector<int> v) {\n"
|
"void f(std::vector<int> v) {\n"
|
||||||
" std::for_each(g(), g(), [](int){});\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());
|
ASSERT_EQUALS("[test.cpp:3]: (style) Same iterators expression are used for algorithm.\n", errout.str());
|
||||||
|
|
||||||
check("void f(std::vector<int>::iterator it) {\n"
|
check("void f(std::vector<int>::iterator it) {\n"
|
||||||
" std::for_each(it, it, [](int){});\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());
|
ASSERT_EQUALS("[test.cpp:2]: (style) Same iterators expression are used for algorithm.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1374,13 +1374,13 @@ private:
|
||||||
" std::vector<int> a, b;\n"
|
" std::vector<int> a, b;\n"
|
||||||
" a.insert(b.end(), value);\n"
|
" a.insert(b.end(), value);\n"
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Iterator 'b.end()' from different container 'a' are used together.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Iterator 'b.end()' from different container 'a' are used together.\n", errout.str());
|
||||||
|
|
||||||
check("std::vector<int> f(std::vector<int> a, std::vector<int> b) {\n"
|
check("std::vector<int> f(std::vector<int> a, std::vector<int> b) {\n"
|
||||||
" a.erase(b.begin());\n"
|
" a.erase(b.begin());\n"
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (error) Iterator 'b.begin()' from different container 'a' are used together.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (error) Iterator 'b.begin()' from different container 'a' are used together.\n", errout.str());
|
||||||
|
|
||||||
// #9973
|
// #9973
|
||||||
|
@ -1643,7 +1643,7 @@ private:
|
||||||
" return a[x - 5];\n"
|
" return a[x - 5];\n"
|
||||||
" else\n"
|
" else\n"
|
||||||
" return a[4 - x];\n"
|
" return a[4 - x];\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3504,8 +3504,8 @@ private:
|
||||||
" x < vector < EffectivityRangeData<int >> >();\n"
|
" x < vector < EffectivityRangeData<int >> >();\n"
|
||||||
" EffectivityRange<int> er;\n"
|
" EffectivityRange<int> er;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" void shift() { EffectivityRangeData<int>::iterator it; } \n"
|
" void shift() { EffectivityRangeData<int>::iterator it; }\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3515,7 +3515,7 @@ private:
|
||||||
" if (std::isalpha(*i) && i != str.end()) {\n"
|
" if (std::isalpha(*i) && i != str.end()) {\n"
|
||||||
" std::cout << *i;\n"
|
" std::cout << *i;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout.str());
|
||||||
|
|
||||||
check("void foo(std::string::iterator& i) {\n"
|
check("void foo(std::string::iterator& i) {\n"
|
||||||
|
@ -3523,7 +3523,7 @@ private:
|
||||||
" else if (std::isalpha(*i) && i != str.end()) {\n"
|
" else if (std::isalpha(*i) && i != str.end()) {\n"
|
||||||
" std::cout << *i;\n"
|
" std::cout << *i;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Possible dereference of an invalid iterator: i\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (warning) Possible dereference of an invalid iterator: i\n", errout.str());
|
||||||
|
|
||||||
// Test suggested correction doesn't report an error
|
// Test suggested correction doesn't report an error
|
||||||
|
@ -3531,7 +3531,7 @@ private:
|
||||||
" if (i != str.end() && std::isalpha(*i)) {\n"
|
" if (i != str.end() && std::isalpha(*i)) {\n"
|
||||||
" std::cout << *i;\n"
|
" std::cout << *i;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// Test "while" with "&&" case
|
// Test "while" with "&&" case
|
||||||
|
@ -3540,7 +3540,7 @@ private:
|
||||||
" std::cout << *i;\n"
|
" std::cout << *i;\n"
|
||||||
" i ++;\n"
|
" i ++;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout.str());
|
||||||
|
|
||||||
check("void foo(std::string::iterator& i) {\n"
|
check("void foo(std::string::iterator& i) {\n"
|
||||||
|
@ -3548,7 +3548,7 @@ private:
|
||||||
" std::cout << *i;\n"
|
" std::cout << *i;\n"
|
||||||
" i ++;\n"
|
" i ++;\n"
|
||||||
" } while (std::isalpha(*i) && i != str.end());\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());
|
ASSERT_EQUALS("[test.cpp:5]: (warning) Possible dereference of an invalid iterator: i\n", errout.str());
|
||||||
|
|
||||||
// Test "while" with "||" case
|
// Test "while" with "||" case
|
||||||
|
@ -3557,7 +3557,7 @@ private:
|
||||||
" std::cout << *i;\n"
|
" std::cout << *i;\n"
|
||||||
" i ++;\n"
|
" i ++;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout.str());
|
||||||
|
|
||||||
// Test fix for "while" with "||" case
|
// Test fix for "while" with "||" case
|
||||||
|
@ -3566,7 +3566,7 @@ private:
|
||||||
" std::cout << *i;\n"
|
" std::cout << *i;\n"
|
||||||
" i ++;\n"
|
" i ++;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// Test "for" with "&&" case
|
// Test "for" with "&&" case
|
||||||
|
@ -3575,7 +3575,7 @@ private:
|
||||||
" std::cout << *i;\n"
|
" std::cout << *i;\n"
|
||||||
" i ++;\n"
|
" i ++;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout.str());
|
||||||
|
|
||||||
// Test "for" with "||" case
|
// Test "for" with "||" case
|
||||||
|
@ -3584,7 +3584,7 @@ private:
|
||||||
" std::cout << *i;\n"
|
" std::cout << *i;\n"
|
||||||
" i ++;\n"
|
" i ++;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout.str());
|
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"
|
// Test that a dereference outside the condition part of a "for"
|
||||||
|
@ -3594,7 +3594,7 @@ private:
|
||||||
" std::cout << c;\n"
|
" std::cout << c;\n"
|
||||||
" i ++;\n"
|
" i ++;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// Test that other "&&" terms in the condition don't invalidate the check
|
// 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"
|
" if (*c && std::isalpha(*i) && i != str.end()) {\n"
|
||||||
" std::cout << *i;\n"
|
" std::cout << *i;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout.str());
|
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
|
// 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"
|
" if (std::isalpha(*c) && i != str.end()) {\n"
|
||||||
" std::cout << *c;\n"
|
" std::cout << *c;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// Test case involving "rend()" instead of "end()"
|
// Test case involving "rend()" instead of "end()"
|
||||||
|
@ -3619,7 +3619,7 @@ private:
|
||||||
" std::cout << *i;\n"
|
" std::cout << *i;\n"
|
||||||
" i ++;\n"
|
" i ++;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Possible dereference of an invalid iterator: i\n", errout.str());
|
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
|
// 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"
|
" if ((i == str.end() || *i) || (isFoo() && i != str.end())) {\n"
|
||||||
" std::cout << \"foo\";\n"
|
" std::cout << \"foo\";\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
|
@ -3783,11 +3783,11 @@ private:
|
||||||
" ++m_ptr.m_place;\n"
|
" ++m_ptr.m_place;\n"
|
||||||
" return *this;\n"
|
" return *this;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }; \n"
|
" };\n"
|
||||||
" iterator begin() {\n"
|
" iterator begin() {\n"
|
||||||
" iterator it; \n"
|
" iterator it;\n"
|
||||||
" it->m_place = 0;\n"
|
" it->m_place = 0;\n"
|
||||||
" return it; \n"
|
" return it;\n"
|
||||||
"}\n", true);
|
"}\n", true);
|
||||||
ASSERT_EQUALS("[test.cpp:18]: (error, inconclusive) Invalid iterator 'it' used.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:18]: (error, inconclusive) Invalid iterator 'it' used.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -4045,7 +4045,7 @@ private:
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" for(int& x:v) {\n"
|
" for(int& x:v) {\n"
|
||||||
" if (pred(x)) {\n"
|
" if (pred(x)) {\n"
|
||||||
" x = 1; \n"
|
" x = 1;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
|
@ -4057,7 +4057,7 @@ private:
|
||||||
" int n = 0;\n"
|
" int n = 0;\n"
|
||||||
" for(int x:v) {\n"
|
" for(int x:v) {\n"
|
||||||
" if (pred(x)) {\n"
|
" if (pred(x)) {\n"
|
||||||
" n += x; \n"
|
" n += x;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
|
@ -4069,7 +4069,7 @@ private:
|
||||||
" int n = 0;\n"
|
" int n = 0;\n"
|
||||||
" for(int x:v) {\n"
|
" for(int x:v) {\n"
|
||||||
" if (pred(x)) {\n"
|
" if (pred(x)) {\n"
|
||||||
" n += 1; \n"
|
" n += 1;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
|
@ -4081,7 +4081,7 @@ private:
|
||||||
" int n = 0;\n"
|
" int n = 0;\n"
|
||||||
" for(int x:v) {\n"
|
" for(int x:v) {\n"
|
||||||
" if (pred(x)) {\n"
|
" if (pred(x)) {\n"
|
||||||
" n++; \n"
|
" n++;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
|
@ -4092,7 +4092,7 @@ private:
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" for(int& x:v) {\n"
|
" for(int& x:v) {\n"
|
||||||
" if (pred(x)) {\n"
|
" if (pred(x)) {\n"
|
||||||
" x = x + 1; \n"
|
" x = x + 1;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
|
@ -4104,7 +4104,7 @@ private:
|
||||||
" std::vector<int> c;\n"
|
" std::vector<int> c;\n"
|
||||||
" for(int x:v) {\n"
|
" for(int x:v) {\n"
|
||||||
" if (pred(x)) {\n"
|
" if (pred(x)) {\n"
|
||||||
" c.push_back(x); \n"
|
" c.push_back(x);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
|
@ -4115,7 +4115,7 @@ private:
|
||||||
"bool foo() {\n"
|
"bool foo() {\n"
|
||||||
" for(int x:v) {\n"
|
" for(int x:v) {\n"
|
||||||
" if (pred(x)) {\n"
|
" if (pred(x)) {\n"
|
||||||
" return false; \n"
|
" return false;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" return true;\n"
|
" return true;\n"
|
||||||
|
@ -4127,7 +4127,7 @@ private:
|
||||||
"bool foo() {\n"
|
"bool foo() {\n"
|
||||||
" for(int x:v) {\n"
|
" for(int x:v) {\n"
|
||||||
" if (pred(x)) {\n"
|
" if (pred(x)) {\n"
|
||||||
" break; \n"
|
" break;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" return true;\n"
|
" return true;\n"
|
||||||
|
@ -4140,8 +4140,8 @@ private:
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" for(int x:v) {\n"
|
" for(int x:v) {\n"
|
||||||
" if (pred(x)) {\n"
|
" if (pred(x)) {\n"
|
||||||
" f(); \n"
|
" f();\n"
|
||||||
" break; \n"
|
" break;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
|
@ -4153,8 +4153,8 @@ private:
|
||||||
"void foo() {\n"
|
"void foo() {\n"
|
||||||
" for(int x:v) {\n"
|
" for(int x:v) {\n"
|
||||||
" if (pred(x)) {\n"
|
" if (pred(x)) {\n"
|
||||||
" f(x); \n"
|
" f(x);\n"
|
||||||
" break; \n"
|
" break;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
|
@ -4205,7 +4205,7 @@ private:
|
||||||
"bool foo() {\n"
|
"bool foo() {\n"
|
||||||
" for(int x:v) {\n"
|
" for(int x:v) {\n"
|
||||||
" if (pred(x)) {\n"
|
" if (pred(x)) {\n"
|
||||||
" return false; \n"
|
" return false;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" return true;\n"
|
" return true;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
|
@ -4219,7 +4219,7 @@ private:
|
||||||
" std::vector<int> c;\n"
|
" std::vector<int> c;\n"
|
||||||
" for(int x:v) {\n"
|
" for(int x:v) {\n"
|
||||||
" if (pred(x)) {\n"
|
" if (pred(x)) {\n"
|
||||||
" c.push_back(x + 1); \n"
|
" c.push_back(x + 1);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
|
@ -4231,7 +4231,7 @@ private:
|
||||||
" for(int& x:v) {\n"
|
" for(int& x:v) {\n"
|
||||||
" x++;\n"
|
" x++;\n"
|
||||||
" if (pred(x)) {\n"
|
" if (pred(x)) {\n"
|
||||||
" x = 1; \n"
|
" x = 1;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
|
@ -4244,7 +4244,7 @@ private:
|
||||||
" for(int x:v) {\n"
|
" for(int x:v) {\n"
|
||||||
" if (pred(x)) {\n"
|
" if (pred(x)) {\n"
|
||||||
" if(x) { return; }\n"
|
" if(x) { return; }\n"
|
||||||
" break; \n"
|
" break;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
|
|
|
@ -710,7 +710,7 @@ private:
|
||||||
"_asm\n"
|
"_asm\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" // cppcheck-suppress syntaxError\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"
|
" mov EAX,Real10 ; get the address pointed to by Real10\n"
|
||||||
" fld TBYTE PTR [EAX] ; load an extended real (10 bytes)\n"
|
" fld TBYTE PTR [EAX] ; load an extended real (10 bytes)\n"
|
||||||
" fstp QWORD PTR result ; store a double (8 bytes)\n"
|
" fstp QWORD PTR result ; store a double (8 bytes)\n"
|
||||||
|
|
|
@ -922,7 +922,7 @@ private:
|
||||||
|
|
||||||
void VariableValueType1() {
|
void VariableValueType1() {
|
||||||
GET_SYMBOL_DB("typedef uint8_t u8;\n"
|
GET_SYMBOL_DB("typedef uint8_t u8;\n"
|
||||||
"static u8 x;\n");
|
"static u8 x;");
|
||||||
const Variable* x = db->getVariableFromVarId(1);
|
const Variable* x = db->getVariableFromVarId(1);
|
||||||
ASSERT_EQUALS("x", x->name());
|
ASSERT_EQUALS("x", x->name());
|
||||||
ASSERT(x->valueType()->isIntegral());
|
ASSERT(x->valueType()->isIntegral());
|
||||||
|
@ -930,7 +930,7 @@ private:
|
||||||
|
|
||||||
void VariableValueType2() {
|
void VariableValueType2() {
|
||||||
GET_SYMBOL_DB("using u8 = uint8_t;\n"
|
GET_SYMBOL_DB("using u8 = uint8_t;\n"
|
||||||
"static u8 x;\n");
|
"static u8 x;");
|
||||||
const Variable* x = db->getVariableFromVarId(1);
|
const Variable* x = db->getVariableFromVarId(1);
|
||||||
ASSERT_EQUALS("x", x->name());
|
ASSERT_EQUALS("x", x->name());
|
||||||
ASSERT(x->valueType()->isIntegral());
|
ASSERT(x->valueType()->isIntegral());
|
||||||
|
@ -939,7 +939,7 @@ private:
|
||||||
void VariableValueType3() {
|
void VariableValueType3() {
|
||||||
// std::string::size_type
|
// 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);
|
const Variable* const x = db->getVariableFromVarId(1);
|
||||||
ASSERT_EQUALS("x", x->name());
|
ASSERT_EQUALS("x", x->name());
|
||||||
// TODO: Configure std::string::size_type somehow.
|
// TODO: Configure std::string::size_type somehow.
|
||||||
|
@ -948,7 +948,7 @@ private:
|
||||||
}
|
}
|
||||||
// std::wstring::size_type
|
// 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);
|
const Variable* const x = db->getVariableFromVarId(1);
|
||||||
ASSERT_EQUALS("x", x->name());
|
ASSERT_EQUALS("x", x->name());
|
||||||
// TODO: Configure std::wstring::size_type somehow.
|
// TODO: Configure std::wstring::size_type somehow.
|
||||||
|
@ -957,7 +957,7 @@ private:
|
||||||
}
|
}
|
||||||
// std::u16string::size_type
|
// 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);
|
const Variable* const x = db->getVariableFromVarId(1);
|
||||||
ASSERT_EQUALS("x", x->name());
|
ASSERT_EQUALS("x", x->name());
|
||||||
// TODO: Configure std::u16string::size_type somehow.
|
// TODO: Configure std::u16string::size_type somehow.
|
||||||
|
@ -966,7 +966,7 @@ private:
|
||||||
}
|
}
|
||||||
// std::u32string::size_type
|
// 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);
|
const Variable* const x = db->getVariableFromVarId(1);
|
||||||
ASSERT_EQUALS("x", x->name());
|
ASSERT_EQUALS("x", x->name());
|
||||||
// TODO: Configure std::u32string::size_type somehow.
|
// TODO: Configure std::u32string::size_type somehow.
|
||||||
|
@ -988,7 +988,7 @@ private:
|
||||||
|
|
||||||
void VariableValueType5() {
|
void VariableValueType5() {
|
||||||
GET_SYMBOL_DB("class C {};\n"
|
GET_SYMBOL_DB("class C {};\n"
|
||||||
"void foo(std::shared_ptr<C>* p) {}\n");
|
"void foo(std::shared_ptr<C>* p) {}");
|
||||||
|
|
||||||
const Variable* const p = db->getVariableFromVarId(1);
|
const Variable* const p = db->getVariableFromVarId(1);
|
||||||
ASSERT(p->valueType());
|
ASSERT(p->valueType());
|
||||||
|
@ -1294,7 +1294,7 @@ private:
|
||||||
|
|
||||||
void variableVolatile() {
|
void variableVolatile() {
|
||||||
GET_SYMBOL_DB("std::atomic<int> x;\n"
|
GET_SYMBOL_DB("std::atomic<int> x;\n"
|
||||||
"volatile int y;\n");
|
"volatile int y;");
|
||||||
|
|
||||||
const Token *x = Token::findsimplematch(tokenizer.tokens(), "x");
|
const Token *x = Token::findsimplematch(tokenizer.tokens(), "x");
|
||||||
ASSERT(x);
|
ASSERT(x);
|
||||||
|
@ -1395,7 +1395,7 @@ private:
|
||||||
|
|
||||||
void getVariableFromVarIdBoundsCheck() {
|
void getVariableFromVarIdBoundsCheck() {
|
||||||
GET_SYMBOL_DB("int x;\n"
|
GET_SYMBOL_DB("int x;\n"
|
||||||
"int y;\n");
|
"int y;");
|
||||||
|
|
||||||
const Variable* v = db->getVariableFromVarId(2);
|
const Variable* v = db->getVariableFromVarId(2);
|
||||||
// three elements: varId 0 also counts via a fake-entry
|
// three elements: varId 0 also counts via a fake-entry
|
||||||
|
@ -1405,7 +1405,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void hasRegularFunction() {
|
void hasRegularFunction() {
|
||||||
GET_SYMBOL_DB("void func() { }\n");
|
GET_SYMBOL_DB("void func() { }");
|
||||||
|
|
||||||
// 2 scopes: Global and Function
|
// 2 scopes: Global and Function
|
||||||
ASSERT(db && db->scopeList.size() == 2);
|
ASSERT(db && db->scopeList.size() == 2);
|
||||||
|
@ -1447,7 +1447,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void hasInlineClassFunction() {
|
void hasInlineClassFunction() {
|
||||||
GET_SYMBOL_DB("class Fred { void func() { } };\n");
|
GET_SYMBOL_DB("class Fred { void func() { } };");
|
||||||
|
|
||||||
// 3 scopes: Global, Class, and Function
|
// 3 scopes: Global, Class, and Function
|
||||||
ASSERT(db && db->scopeList.size() == 3);
|
ASSERT(db && db->scopeList.size() == 3);
|
||||||
|
@ -1498,7 +1498,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void hasMissingInlineClassFunction() {
|
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)
|
// 2 scopes: Global and Class (no Function scope because there is no function implementation)
|
||||||
ASSERT(db && db->scopeList.size() == 2);
|
ASSERT(db && db->scopeList.size() == 2);
|
||||||
|
@ -1542,7 +1542,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void hasClassFunction() {
|
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
|
// 3 scopes: Global, Class, and Function
|
||||||
ASSERT(db && db->scopeList.size() == 3);
|
ASSERT(db && db->scopeList.size() == 3);
|
||||||
|
@ -1564,7 +1564,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void hasClassFunction_trailingReturnType() {
|
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
|
// 3 scopes: Global, Class, and Function
|
||||||
ASSERT(db && db->scopeList.size() == 3);
|
ASSERT(db && db->scopeList.size() == 3);
|
||||||
|
@ -1586,7 +1586,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void hasRegularFunctionReturningFunctionPointer() {
|
void hasRegularFunctionReturningFunctionPointer() {
|
||||||
GET_SYMBOL_DB("void (*func(int f))(char) { }\n");
|
GET_SYMBOL_DB("void (*func(int f))(char) { }");
|
||||||
|
|
||||||
// 2 scopes: Global and Function
|
// 2 scopes: Global and Function
|
||||||
ASSERT(db && db->scopeList.size() == 2);
|
ASSERT(db && db->scopeList.size() == 2);
|
||||||
|
@ -1605,7 +1605,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void hasInlineClassFunctionReturningFunctionPointer() {
|
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
|
// 3 scopes: Global, Class, and Function
|
||||||
ASSERT(db && db->scopeList.size() == 3);
|
ASSERT(db && db->scopeList.size() == 3);
|
||||||
|
@ -1624,7 +1624,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void hasMissingInlineClassFunctionReturningFunctionPointer() {
|
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)
|
// 2 scopes: Global and Class (no Function scope because there is no function implementation)
|
||||||
ASSERT(db && db->scopeList.size() == 2);
|
ASSERT(db && db->scopeList.size() == 2);
|
||||||
|
@ -1643,7 +1643,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void hasClassFunctionReturningFunctionPointer() {
|
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
|
// 3 scopes: Global, Class, and Function
|
||||||
ASSERT(db && db->scopeList.size() == 3);
|
ASSERT(db && db->scopeList.size() == 3);
|
||||||
|
@ -1662,7 +1662,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void methodWithRedundantScope() {
|
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
|
// 3 scopes: Global, Class, and Function
|
||||||
ASSERT(db && db->scopeList.size() == 3);
|
ASSERT(db && db->scopeList.size() == 3);
|
||||||
|
@ -1971,7 +1971,7 @@ private:
|
||||||
|
|
||||||
void parseFunctionCorrect() {
|
void parseFunctionCorrect() {
|
||||||
// ticket 3188 - "if" statement parsed as function
|
// 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);
|
ASSERT(db != nullptr);
|
||||||
|
|
||||||
// 3 scopes: Global, function, if
|
// 3 scopes: Global, function, if
|
||||||
|
@ -1998,7 +1998,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void hasGlobalVariables1() {
|
void hasGlobalVariables1() {
|
||||||
GET_SYMBOL_DB("int i;\n");
|
GET_SYMBOL_DB("int i;");
|
||||||
|
|
||||||
ASSERT(db && db->scopeList.size() == 1);
|
ASSERT(db && db->scopeList.size() == 1);
|
||||||
|
|
||||||
|
@ -2010,7 +2010,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void hasGlobalVariables2() {
|
void hasGlobalVariables2() {
|
||||||
GET_SYMBOL_DB("int array[2][2];\n");
|
GET_SYMBOL_DB("int array[2][2];");
|
||||||
|
|
||||||
ASSERT(db && db->scopeList.size() == 1);
|
ASSERT(db && db->scopeList.size() == 1);
|
||||||
|
|
||||||
|
@ -2023,7 +2023,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void hasGlobalVariables3() {
|
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);
|
ASSERT(db && db->scopeList.size() == 1);
|
||||||
|
|
||||||
|
@ -2215,7 +2215,7 @@ private:
|
||||||
"int foo(struct AB *ab);\n"
|
"int foo(struct AB *ab);\n"
|
||||||
"void bar() {\n"
|
"void bar() {\n"
|
||||||
" struct AB ab;\n"
|
" struct AB ab;\n"
|
||||||
" foo(&ab); \n"
|
" foo(&ab);\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS(true, db != nullptr);
|
ASSERT_EQUALS(true, db != nullptr);
|
||||||
const Token *f = Token::findsimplematch(tokenizer.tokens(), "foo ( & ab");
|
const Token *f = Token::findsimplematch(tokenizer.tokens(), "foo ( & ab");
|
||||||
|
@ -2230,7 +2230,7 @@ private:
|
||||||
"int foo(AB *ab);\n"
|
"int foo(AB *ab);\n"
|
||||||
"void bar() {\n"
|
"void bar() {\n"
|
||||||
" struct AB ab;\n"
|
" struct AB ab;\n"
|
||||||
" foo(&ab); \n"
|
" foo(&ab);\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS(true, db != nullptr);
|
ASSERT_EQUALS(true, db != nullptr);
|
||||||
const Token *f = Token::findsimplematch(tokenizer.tokens(), "foo ( & ab");
|
const Token *f = Token::findsimplematch(tokenizer.tokens(), "foo ( & ab");
|
||||||
|
@ -2245,7 +2245,7 @@ private:
|
||||||
"int foo(struct AB *ab);\n"
|
"int foo(struct AB *ab);\n"
|
||||||
"void bar() {\n"
|
"void bar() {\n"
|
||||||
" AB ab;\n"
|
" AB ab;\n"
|
||||||
" foo(&ab); \n"
|
" foo(&ab);\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS(true, db != nullptr);
|
ASSERT_EQUALS(true, db != nullptr);
|
||||||
const Token *f = Token::findsimplematch(tokenizer.tokens(), "foo ( & ab");
|
const Token *f = Token::findsimplematch(tokenizer.tokens(), "foo ( & ab");
|
||||||
|
@ -2260,7 +2260,7 @@ private:
|
||||||
"int foo(AB *ab);\n"
|
"int foo(AB *ab);\n"
|
||||||
"void bar() {\n"
|
"void bar() {\n"
|
||||||
" AB ab;\n"
|
" AB ab;\n"
|
||||||
" foo(&ab); \n"
|
" foo(&ab);\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS(true, db != nullptr);
|
ASSERT_EQUALS(true, db != nullptr);
|
||||||
const Token *f = Token::findsimplematch(tokenizer.tokens(), "foo ( & ab");
|
const Token *f = Token::findsimplematch(tokenizer.tokens(), "foo ( & ab");
|
||||||
|
@ -2598,7 +2598,7 @@ private:
|
||||||
check("static void function_declaration_before(void) __attribute__((__used__));\n"
|
check("static void function_declaration_before(void) __attribute__((__used__));\n"
|
||||||
"static void function_declaration_before(void) {}\n"
|
"static void function_declaration_before(void) {}\n"
|
||||||
"static void function_declaration_after(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());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("main(int argc, char *argv[]) { }", true, "test.c");
|
check("main(int argc, char *argv[]) { }", true, "test.c");
|
||||||
|
@ -2769,7 +2769,7 @@ private:
|
||||||
// ticket 3437 (segmentation fault)
|
// ticket 3437 (segmentation fault)
|
||||||
void symboldatabase22() {
|
void symboldatabase22() {
|
||||||
check("template <class C> struct A {};\n"
|
check("template <class C> struct A {};\n"
|
||||||
"A<int> a;\n");
|
"A<int> a;");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2898,7 +2898,7 @@ private:
|
||||||
"::Foo::Sub::Sub() { }\n"
|
"::Foo::Sub::Sub() { }\n"
|
||||||
"class Foo;\n"
|
"class Foo;\n"
|
||||||
"class Bar;\n"
|
"class Bar;\n"
|
||||||
"class Sub;\n");
|
"class Sub;");
|
||||||
ASSERT(db && db->typeList.size() == 5);
|
ASSERT(db && db->typeList.size() == 5);
|
||||||
|
|
||||||
std::list<Type>::const_iterator i = db->typeList.begin();
|
std::list<Type>::const_iterator i = db->typeList.begin();
|
||||||
|
@ -2966,7 +2966,7 @@ private:
|
||||||
" Fred(const struct Barney & b) { barney = b; }\n"
|
" Fred(const struct Barney & b) { barney = b; }\n"
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" struct Barney barney;\n"
|
" struct Barney barney;\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT(db && db->typeList.size() == 3);
|
ASSERT(db && db->typeList.size() == 3);
|
||||||
|
|
||||||
std::list<Type>::const_iterator i = db->typeList.begin();
|
std::list<Type>::const_iterator i = db->typeList.begin();
|
||||||
|
@ -2999,17 +2999,17 @@ private:
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" try { }\n"
|
" try { }\n"
|
||||||
" catch (std::bad_alloc) { }\n"
|
" catch (std::bad_alloc) { }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void symboldatabase41() { // ticket #5197 (unknown macro)
|
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());
|
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
|
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);
|
ASSERT(db != nullptr);
|
||||||
const Scope * const fscope = db ? db->findScopeByName("f") : nullptr;
|
const Scope * const fscope = db ? db->findScopeByName("f") : nullptr;
|
||||||
ASSERT(fscope != nullptr);
|
ASSERT(fscope != nullptr);
|
||||||
|
@ -3019,7 +3019,7 @@ private:
|
||||||
void symboldatabase43() { // ticket #4738
|
void symboldatabase43() { // ticket #4738
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" new int;\n"
|
" new int;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3111,7 +3111,7 @@ private:
|
||||||
"}\n"
|
"}\n"
|
||||||
"using namespace NS;\n"
|
"using namespace NS;\n"
|
||||||
"MyClass::~MyClass() { }\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());
|
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 ( ) ;");
|
const Token *f = Token::findsimplematch(tokenizer.tokens(), "MyClass ( ) ;");
|
||||||
|
@ -3126,7 +3126,7 @@ private:
|
||||||
GET_SYMBOL_DB("namespace Ns { class C; }\n"
|
GET_SYMBOL_DB("namespace Ns { class C; }\n"
|
||||||
"void f1() { char *p; *p = 0; }\n"
|
"void f1() { char *p; *p = 0; }\n"
|
||||||
"class Ns::C* p;\n"
|
"class Ns::C* p;\n"
|
||||||
"void f2() { char *p; *p = 0; }\n");
|
"void f2() { char *p; *p = 0; }");
|
||||||
ASSERT(db != nullptr);
|
ASSERT(db != nullptr);
|
||||||
const Token *f = Token::findsimplematch(tokenizer.tokens(), "p ; void f2");
|
const Token *f = Token::findsimplematch(tokenizer.tokens(), "p ; void f2");
|
||||||
ASSERT_EQUALS(true, db && f && f->variable());
|
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 f3 = 2 * std::foo3(a, b);\n"
|
||||||
"static const float f4 = c * foo4(a, b);\n"
|
"static const float f4 = c * foo4(a, b);\n"
|
||||||
"static const int i1 = 2 & foo5(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(db != nullptr);
|
||||||
ASSERT(findFunctionByName("foo1", &db->scopeList.front()) == nullptr);
|
ASSERT(findFunctionByName("foo1", &db->scopeList.front()) == nullptr);
|
||||||
ASSERT(findFunctionByName("foo2", &db->scopeList.front()) == nullptr);
|
ASSERT(findFunctionByName("foo2", &db->scopeList.front()) == nullptr);
|
||||||
|
@ -3248,7 +3248,7 @@ private:
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
GET_SYMBOL_DB_C("friend f1();\n"
|
GET_SYMBOL_DB_C("friend f1();\n"
|
||||||
"friend f2() { }\n");
|
"friend f2() { }");
|
||||||
|
|
||||||
ASSERT(db != nullptr);
|
ASSERT(db != nullptr);
|
||||||
ASSERT_EQUALS(2U, db->scopeList.size());
|
ASSERT_EQUALS(2U, db->scopeList.size());
|
||||||
|
@ -3816,7 +3816,7 @@ private:
|
||||||
" ~impl() { }\n"
|
" ~impl() { }\n"
|
||||||
" impl(const impl &) { }\n"
|
" impl(const impl &) { }\n"
|
||||||
" void foo(const impl &, const impl &) const { }\n"
|
" void foo(const impl &, const impl &) const { }\n"
|
||||||
"};\n");
|
"};");
|
||||||
|
|
||||||
ASSERT(db != nullptr);
|
ASSERT(db != nullptr);
|
||||||
ASSERT(db && db->scopeList.size() == 7);
|
ASSERT(db && db->scopeList.size() == 7);
|
||||||
|
@ -3859,7 +3859,7 @@ private:
|
||||||
"template <typename A> Fred<A>::impl::impl() { }\n"
|
"template <typename A> Fred<A>::impl::impl() { }\n"
|
||||||
"template <typename A> Fred<A>::impl::~impl() { }\n"
|
"template <typename A> Fred<A>::impl::~impl() { }\n"
|
||||||
"template <typename A> Fred<A>::impl::impl(const Fred<A>::impl &) { }\n"
|
"template <typename A> Fred<A>::impl::impl(const Fred<A>::impl &) { }\n"
|
||||||
"template <typename A> void Fred<A>::impl::foo(const Fred<A>::impl &, const Fred<A>::impl &) const { }\n");
|
"template <typename A> void Fred<A>::impl::foo(const Fred<A>::impl &, const Fred<A>::impl &) const { }");
|
||||||
|
|
||||||
ASSERT(db != nullptr);
|
ASSERT(db != nullptr);
|
||||||
ASSERT(db && db->scopeList.size() == 7);
|
ASSERT(db && db->scopeList.size() == 7);
|
||||||
|
@ -3990,7 +3990,7 @@ private:
|
||||||
"template <typename A> NS::Fred<A>::impl::impl() { }\n"
|
"template <typename A> NS::Fred<A>::impl::impl() { }\n"
|
||||||
"template <typename A> NS::Fred<A>::impl::~impl() { }\n"
|
"template <typename A> NS::Fred<A>::impl::~impl() { }\n"
|
||||||
"template <typename A> NS::Fred<A>::impl::impl(const NS::Fred<A>::impl &) { }\n"
|
"template <typename A> NS::Fred<A>::impl::impl(const NS::Fred<A>::impl &) { }\n"
|
||||||
"template <typename A> void NS::Fred<A>::impl::foo(const NS::Fred<A>::impl &, const NS::Fred<A>::impl &) const { }\n");
|
"template <typename A> void NS::Fred<A>::impl::foo(const NS::Fred<A>::impl &, const NS::Fred<A>::impl &) const { }");
|
||||||
|
|
||||||
ASSERT(db != nullptr);
|
ASSERT(db != nullptr);
|
||||||
ASSERT(db && db->scopeList.size() == 8);
|
ASSERT(db && db->scopeList.size() == 8);
|
||||||
|
@ -4076,7 +4076,7 @@ private:
|
||||||
"template <typename A> NS::Fred<A>::impl::impl() { }\n"
|
"template <typename A> NS::Fred<A>::impl::impl() { }\n"
|
||||||
"template <typename A> NS::Fred<A>::impl::~impl() { }\n"
|
"template <typename A> NS::Fred<A>::impl::~impl() { }\n"
|
||||||
"template <typename A> NS::Fred<A>::impl::impl(const NS::Fred<A>::impl &) { }\n"
|
"template <typename A> NS::Fred<A>::impl::impl(const NS::Fred<A>::impl &) { }\n"
|
||||||
"template <typename A> void NS::Fred<A>::impl::foo(const NS::Fred<A>::impl &, const NS::Fred<A>::impl &) const { }\n");
|
"template <typename A> void NS::Fred<A>::impl::foo(const NS::Fred<A>::impl &, const NS::Fred<A>::impl &) const { }");
|
||||||
|
|
||||||
ASSERT(db != nullptr);
|
ASSERT(db != nullptr);
|
||||||
ASSERT(db && db->scopeList.size() == 8);
|
ASSERT(db && db->scopeList.size() == 8);
|
||||||
|
@ -4169,7 +4169,7 @@ private:
|
||||||
"template <typename A> Fred<A>::impl::impl() { }\n"
|
"template <typename A> Fred<A>::impl::impl() { }\n"
|
||||||
"template <typename A> Fred<A>::impl::~impl() { }\n"
|
"template <typename A> Fred<A>::impl::~impl() { }\n"
|
||||||
"template <typename A> Fred<A>::impl::impl(const Fred<A>::impl &) { }\n"
|
"template <typename A> Fred<A>::impl::impl(const Fred<A>::impl &) { }\n"
|
||||||
"template <typename A> void Fred<A>::impl::foo(const Fred<A>::impl &, const Fred<A>::impl &) const { }\n");
|
"template <typename A> void Fred<A>::impl::foo(const Fred<A>::impl &, const Fred<A>::impl &) const { }");
|
||||||
|
|
||||||
ASSERT(db != nullptr);
|
ASSERT(db != nullptr);
|
||||||
ASSERT(db && db->scopeList.size() == 8);
|
ASSERT(db && db->scopeList.size() == 8);
|
||||||
|
@ -4822,7 +4822,7 @@ private:
|
||||||
"int b[A];\n"
|
"int b[A];\n"
|
||||||
"int c[A + 2];\n"
|
"int c[A + 2];\n"
|
||||||
"int d[10 + B];\n"
|
"int d[10 + B];\n"
|
||||||
"int e[A + B];\n");
|
"int e[A + B];");
|
||||||
ASSERT(db != nullptr);
|
ASSERT(db != nullptr);
|
||||||
|
|
||||||
ASSERT_EQUALS(2U, db->scopeList.size());
|
ASSERT_EQUALS(2U, db->scopeList.size());
|
||||||
|
@ -4916,7 +4916,7 @@ private:
|
||||||
"char array9[sizeof(EL)];\n"
|
"char array9[sizeof(EL)];\n"
|
||||||
"char array10[sizeof(L)];\n"
|
"char array10[sizeof(L)];\n"
|
||||||
"char array11[sizeof(ELL)];\n"
|
"char array11[sizeof(ELL)];\n"
|
||||||
"char array12[sizeof(LL)];\n");
|
"char array12[sizeof(LL)];");
|
||||||
ASSERT(db != nullptr);
|
ASSERT(db != nullptr);
|
||||||
|
|
||||||
ASSERT(db->variableList().size() == 13); // the first one is not used
|
ASSERT(db->variableList().size() == 13); // the first one is not used
|
||||||
|
@ -5419,7 +5419,7 @@ private:
|
||||||
"void S::g() &&{ }\n"
|
"void S::g() &&{ }\n"
|
||||||
"void S::g() const { }\n"
|
"void S::g() const { }\n"
|
||||||
"void S::g() const & { }\n"
|
"void S::g() const & { }\n"
|
||||||
"void S::g() const &&{ }\n");
|
"void S::g() const &&{ }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
const Token *f = Token::findsimplematch(tokenizer.tokens(), "f ( ) {");
|
const Token *f = Token::findsimplematch(tokenizer.tokens(), "f ( ) {");
|
||||||
|
@ -6463,7 +6463,7 @@ private:
|
||||||
GET_SYMBOL_DB("void func1() noexcept;\n"
|
GET_SYMBOL_DB("void func1() noexcept;\n"
|
||||||
"void func2() noexcept { }\n"
|
"void func2() noexcept { }\n"
|
||||||
"void func3() noexcept(true);\n"
|
"void func3() noexcept(true);\n"
|
||||||
"void func4() noexcept(true) { }\n");
|
"void func4() noexcept(true) { }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
ASSERT_EQUALS(true, db != nullptr); // not null
|
ASSERT_EQUALS(true, db != nullptr); // not null
|
||||||
|
|
||||||
|
@ -6474,7 +6474,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void noexceptFunction2() {
|
void noexceptFunction2() {
|
||||||
GET_SYMBOL_DB("template <class T> void self_assign(T& t) noexcept(noexcept(t = t)) {t = t; }\n");
|
GET_SYMBOL_DB("template <class T> void self_assign(T& t) noexcept(noexcept(t = t)) {t = t; }");
|
||||||
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
ASSERT_EQUALS(true, db != nullptr); // not null
|
ASSERT_EQUALS(true, db != nullptr); // not null
|
||||||
|
@ -6535,7 +6535,7 @@ private:
|
||||||
" A a;\n"
|
" A a;\n"
|
||||||
" B(B&& b) noexcept\n"
|
" B(B&& b) noexcept\n"
|
||||||
" :a(std::move(b.a)) { }\n"
|
" :a(std::move(b.a)) { }\n"
|
||||||
"};\n");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
ASSERT(db != nullptr); // not null
|
ASSERT(db != nullptr); // not null
|
||||||
const Scope *b = db->findScopeByName("B");
|
const Scope *b = db->findScopeByName("B");
|
||||||
|
@ -6553,7 +6553,7 @@ private:
|
||||||
GET_SYMBOL_DB("void func1() throw();\n"
|
GET_SYMBOL_DB("void func1() throw();\n"
|
||||||
"void func2() throw() { }\n"
|
"void func2() throw() { }\n"
|
||||||
"void func3() throw(int);\n"
|
"void func3() throw(int);\n"
|
||||||
"void func4() throw(int) { }\n");
|
"void func4() throw(int) { }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
ASSERT(db != nullptr); // not null
|
ASSERT(db != nullptr); // not null
|
||||||
|
|
||||||
|
@ -6604,7 +6604,7 @@ private:
|
||||||
|
|
||||||
void nothrowAttributeFunction() {
|
void nothrowAttributeFunction() {
|
||||||
GET_SYMBOL_DB("void func() __attribute__((nothrow));\n"
|
GET_SYMBOL_DB("void func() __attribute__((nothrow));\n"
|
||||||
"void func() { }\n");
|
"void func() { }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
ASSERT_EQUALS(true, db != nullptr); // not null
|
ASSERT_EQUALS(true, db != nullptr); // not null
|
||||||
|
|
||||||
|
@ -6614,7 +6614,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void nothrowDeclspecFunction() {
|
void nothrowDeclspecFunction() {
|
||||||
GET_SYMBOL_DB("void __declspec(nothrow) func() { }\n");
|
GET_SYMBOL_DB("void __declspec(nothrow) func() { }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
ASSERT_EQUALS(true, db != nullptr); // not null
|
ASSERT_EQUALS(true, db != nullptr); // not null
|
||||||
|
|
||||||
|
@ -6847,7 +6847,7 @@ private:
|
||||||
GET_SYMBOL_DB("class Fred {\n"
|
GET_SYMBOL_DB("class Fred {\n"
|
||||||
" void foo(const std::string & a = \"\");\n"
|
" void foo(const std::string & a = \"\");\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"Fred::foo(const std::string & b) { }\n");
|
"Fred::foo(const std::string & b) { }");
|
||||||
|
|
||||||
ASSERT(db && db->scopeList.size() == 3);
|
ASSERT(db && db->scopeList.size() == 3);
|
||||||
std::list<Scope>::const_iterator scope = db->scopeList.begin();
|
std::list<Scope>::const_iterator scope = db->scopeList.begin();
|
||||||
|
|
|
@ -1083,7 +1083,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void canFindMatchingBracketsWithTooManyClosing() const {
|
void canFindMatchingBracketsWithTooManyClosing() const {
|
||||||
givenACodeSampleToTokenize var("X< 1>2 > x1;\n");
|
givenACodeSampleToTokenize var("X< 1>2 > x1;");
|
||||||
|
|
||||||
const Token* const t = var.tokens()->next()->findClosingBracket();
|
const Token* const t = var.tokens()->next()->findClosingBracket();
|
||||||
ASSERT_EQUALS(">", t->str());
|
ASSERT_EQUALS(">", t->str());
|
||||||
|
@ -1091,7 +1091,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void canFindMatchingBracketsWithTooManyOpening() const {
|
void canFindMatchingBracketsWithTooManyOpening() const {
|
||||||
givenACodeSampleToTokenize var("X < (2 < 1) > x1;\n");
|
givenACodeSampleToTokenize var("X < (2 < 1) > x1;");
|
||||||
|
|
||||||
const Token* t = var.tokens()->next()->findClosingBracket();
|
const Token* t = var.tokens()->next()->findClosingBracket();
|
||||||
ASSERT(t != nullptr && t->str() == ">");
|
ASSERT(t != nullptr && t->str() == ">");
|
||||||
|
|
|
@ -3295,7 +3295,7 @@ private:
|
||||||
"{}\n"), InternalError);
|
"{}\n"), InternalError);
|
||||||
|
|
||||||
tokenizeAndStringify("void foo(int, int)\n"
|
tokenizeAndStringify("void foo(int, int)\n"
|
||||||
"{}\n");
|
"{}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// #3848 - Don't hang
|
// #3848 - Don't hang
|
||||||
|
|
|
@ -171,7 +171,7 @@ private:
|
||||||
" if (k > 32)\n"
|
" if (k > 32)\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
" return rm>> k;\n"
|
" return rm>> k;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS(
|
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",
|
"[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());
|
errout.str());
|
||||||
|
@ -183,7 +183,7 @@ private:
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
" else\n"
|
" else\n"
|
||||||
" return rm>> k;\n"
|
" return rm>> k;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS(
|
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",
|
"[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());
|
errout.str());
|
||||||
|
@ -195,14 +195,14 @@ private:
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
" else\n"
|
" else\n"
|
||||||
" return rm>> k;\n"
|
" return rm>> k;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("static long long f(int x, long long y) {\n"
|
check("static long long f(int x, long long y) {\n"
|
||||||
" if (x >= 64)\n"
|
" if (x >= 64)\n"
|
||||||
" return 0;\n"
|
" return 0;\n"
|
||||||
" return -(y << (x-1));\n"
|
" return -(y << (x-1));\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,7 +258,7 @@ private:
|
||||||
check("unsigned int dostuff(int x) {\n" // x is signed
|
check("unsigned int dostuff(int x) {\n" // x is signed
|
||||||
" if (x==0) {}\n"
|
" if (x==0) {}\n"
|
||||||
" return (x-1)*sizeof(int);\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());
|
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
|
check("unsigned int f1(signed int x, unsigned int y) {" // x is signed
|
||||||
|
@ -360,27 +360,27 @@ private:
|
||||||
|
|
||||||
check("void f(void) {\n"
|
check("void f(void) {\n"
|
||||||
" return (int)1E100;\n"
|
" return (int)1E100;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str()));
|
ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str()));
|
||||||
|
|
||||||
check("void f(void) {\n"
|
check("void f(void) {\n"
|
||||||
" return (int)-1E100;\n"
|
" return (int)-1E100;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str()));
|
ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str()));
|
||||||
|
|
||||||
check("void f(void) {\n"
|
check("void f(void) {\n"
|
||||||
" return (short)1E6;\n"
|
" return (short)1E6;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str()));
|
ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str()));
|
||||||
|
|
||||||
check("void f(void) {\n"
|
check("void f(void) {\n"
|
||||||
" return (unsigned char)256.0;\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()));
|
ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str()));
|
||||||
|
|
||||||
check("void f(void) {\n"
|
check("void f(void) {\n"
|
||||||
" return (unsigned char)255.5;\n"
|
" return (unsigned char)255.5;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", removeFloat(errout.str()));
|
ASSERT_EQUALS("", removeFloat(errout.str()));
|
||||||
|
|
||||||
check("void f(void) {\n"
|
check("void f(void) {\n"
|
||||||
|
|
|
@ -1586,7 +1586,7 @@ private:
|
||||||
" vertices[i][1][2] = 4.0;\n"
|
" vertices[i][1][2] = 4.0;\n"
|
||||||
" vertices[i][1][3] = 5.0;\n"
|
" vertices[i][1][3] = 5.0;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: vertices\n",
|
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: vertices\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
}
|
}
|
||||||
|
@ -1778,10 +1778,10 @@ private:
|
||||||
|
|
||||||
// #7623 - new can also initialize the memory, don't warn in this case
|
// #7623 - new can also initialize the memory, don't warn in this case
|
||||||
checkUninitVar("void foo(){\n"
|
checkUninitVar("void foo(){\n"
|
||||||
" int* p1 = new int(314); \n"
|
" int* p1 = new int(314);\n"
|
||||||
" int* p2 = new int(); \n"
|
" int* p2 = new int();\n"
|
||||||
" int* arr = new int[5](); \n"
|
" int* arr = new int[5]();\n"
|
||||||
" std::cout << *p1 << *p2 << arr[0]; \n"
|
" std::cout << *p1 << *p2 << arr[0];\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
@ -3184,7 +3184,7 @@ private:
|
||||||
" struct AB ab;\n"
|
" struct AB ab;\n"
|
||||||
" ab.a = 0;\n"
|
" ab.a = 0;\n"
|
||||||
" do_something(ab);\n"
|
" do_something(ab);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkUninitVar("struct AB { int a; int b; };\n"
|
checkUninitVar("struct AB { int a; int b; };\n"
|
||||||
|
@ -3389,7 +3389,7 @@ private:
|
||||||
" struct AB ab;\n"
|
" struct AB ab;\n"
|
||||||
" ab.set();\n"
|
" ab.set();\n"
|
||||||
" x = ab;\n"
|
" x = ab;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkUninitVar("struct AB { int a; int get() const; };\n"
|
checkUninitVar("struct AB { int a; int get() const; };\n"
|
||||||
|
@ -3397,7 +3397,7 @@ private:
|
||||||
" struct AB ab;\n"
|
" struct AB ab;\n"
|
||||||
" ab.get();\n"
|
" ab.get();\n"
|
||||||
" x = ab;\n"
|
" x = ab;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized struct member: ab.a\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized struct member: ab.a\n", errout.str());
|
||||||
|
|
||||||
checkUninitVar("struct AB { int a; void dostuff() {} };\n"
|
checkUninitVar("struct AB { int a; void dostuff() {} };\n"
|
||||||
|
@ -3405,7 +3405,7 @@ private:
|
||||||
" struct AB ab;\n"
|
" struct AB ab;\n"
|
||||||
" ab.dostuff();\n"
|
" ab.dostuff();\n"
|
||||||
" x = ab;\n"
|
" x = ab;\n"
|
||||||
"}\n");
|
"}");
|
||||||
TODO_ASSERT_EQUALS("error", "", errout.str());
|
TODO_ASSERT_EQUALS("error", "", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4055,10 +4055,10 @@ private:
|
||||||
|
|
||||||
void trac_5970() { // Ticket #5970
|
void trac_5970() { // Ticket #5970
|
||||||
checkUninitVar("void DES_ede3_ofb64_encrypt() {\n"
|
checkUninitVar("void DES_ede3_ofb64_encrypt() {\n"
|
||||||
" DES_cblock d; \n"
|
" DES_cblock d;\n"
|
||||||
" char *dp; \n"
|
" char *dp;\n"
|
||||||
" dp=(char *)d; \n"
|
" dp=(char *)d;\n"
|
||||||
" init(dp); \n"
|
" init(dp);\n"
|
||||||
"}", "test.c");
|
"}", "test.c");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
@ -4419,7 +4419,7 @@ private:
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
" int* v = &i;\n"
|
" int* v = &i;\n"
|
||||||
" sscanf(\"0\", \"%d\", v);\n"
|
" sscanf(\"0\", \"%d\", v);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
valueFlowUninit("void test(int p) {\n"
|
valueFlowUninit("void test(int p) {\n"
|
||||||
|
@ -4428,7 +4428,7 @@ private:
|
||||||
" f = 0;\n"
|
" f = 0;\n"
|
||||||
" if (p > 1)\n"
|
" if (p > 1)\n"
|
||||||
" f += 1;\n"
|
" f += 1;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
valueFlowUninit("unsigned char get();\n"
|
valueFlowUninit("unsigned char get();\n"
|
||||||
|
@ -4479,17 +4479,17 @@ private:
|
||||||
"void f(void) {\n"
|
"void f(void) {\n"
|
||||||
" someType_t gVar;\n"
|
" someType_t gVar;\n"
|
||||||
" bar(&gVar);\n"
|
" bar(&gVar);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:5]: (error) Uninitialized variable: flags\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:5]: (error) Uninitialized variable: flags\n", errout.str());
|
||||||
|
|
||||||
valueFlowUninit("typedef struct \n"
|
valueFlowUninit("typedef struct\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int flags[3];\n"
|
" int flags[3];\n"
|
||||||
"} someType_t;\n"
|
"} someType_t;\n"
|
||||||
"void f(void) {\n"
|
"void f(void) {\n"
|
||||||
" someType_t gVar;\n"
|
" someType_t gVar;\n"
|
||||||
" if(gVar.flags[1] == 42){}\n"
|
" if(gVar.flags[1] == 42){}\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: flags\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: flags\n", errout.str());
|
||||||
|
|
||||||
valueFlowUninit("struct pc_data {\n"
|
valueFlowUninit("struct pc_data {\n"
|
||||||
|
@ -4500,7 +4500,7 @@ private:
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" struct pc_data *pcdata;\n"
|
" struct pc_data *pcdata;\n"
|
||||||
" if ( *pcdata->wampiryzm.strefa == '\\0' ) { }\n"
|
" if ( *pcdata->wampiryzm.strefa == '\\0' ) { }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: pcdata\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: pcdata\n", errout.str());
|
||||||
|
|
||||||
// # 9293
|
// # 9293
|
||||||
|
@ -4512,8 +4512,8 @@ private:
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" struct S s1;\n"
|
" struct S s1;\n"
|
||||||
" int * x = &s1.x;\n"
|
" int * x = &s1.x;\n"
|
||||||
" struct S s2 = {*x, 0}; \n"
|
" struct S s2 = {*x, 0};\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:9]: (error) Uninitialized variable: *x\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:9]: (error) Uninitialized variable: *x\n", errout.str());
|
||||||
|
|
||||||
valueFlowUninit("struct S {\n"
|
valueFlowUninit("struct S {\n"
|
||||||
|
@ -4525,8 +4525,8 @@ private:
|
||||||
" struct S s1;\n"
|
" struct S s1;\n"
|
||||||
" struct S s2;\n"
|
" struct S s2;\n"
|
||||||
" int * x = &s1.x;\n"
|
" int * x = &s1.x;\n"
|
||||||
" s2.x = *x; \n"
|
" s2.x = *x;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:10]: (error) Uninitialized variable: *x\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:10]: (error) Uninitialized variable: *x\n", errout.str());
|
||||||
|
|
||||||
valueFlowUninit("void f(bool * x) {\n"
|
valueFlowUninit("void f(bool * x) {\n"
|
||||||
|
@ -4535,7 +4535,7 @@ private:
|
||||||
"void g() {\n"
|
"void g() {\n"
|
||||||
" bool b;\n"
|
" bool b;\n"
|
||||||
" f(&b);\n"
|
" f(&b);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
valueFlowUninit("void f(bool * x) {\n"
|
valueFlowUninit("void f(bool * x) {\n"
|
||||||
|
@ -4545,7 +4545,7 @@ private:
|
||||||
"void g() {\n"
|
"void g() {\n"
|
||||||
" bool x;\n"
|
" bool x;\n"
|
||||||
" f(&x);\n"
|
" f(&x);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
valueFlowUninit("void f() {\n"
|
valueFlowUninit("void f() {\n"
|
||||||
|
@ -4553,7 +4553,7 @@ private:
|
||||||
" bool * x = &b;\n"
|
" bool * x = &b;\n"
|
||||||
" if (x != nullptr)\n"
|
" if (x != nullptr)\n"
|
||||||
" x = 1;\n"
|
" x = 1;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
valueFlowUninit("struct A { bool b; };"
|
valueFlowUninit("struct A { bool b; };"
|
||||||
|
@ -4563,14 +4563,14 @@ private:
|
||||||
"void g() {\n"
|
"void g() {\n"
|
||||||
" A b;\n"
|
" A b;\n"
|
||||||
" f(&b);\n"
|
" f(&b);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
valueFlowUninit("std::string f() {\n"
|
valueFlowUninit("std::string f() {\n"
|
||||||
" std::ostringstream ostr;\n"
|
" std::ostringstream ostr;\n"
|
||||||
" ostr << \"\";\n"
|
" ostr << \"\";\n"
|
||||||
" return ostr.str();\n"
|
" return ostr.str();\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
// #9281
|
// #9281
|
||||||
valueFlowUninit("struct s {\n"
|
valueFlowUninit("struct s {\n"
|
||||||
|
@ -4585,7 +4585,7 @@ private:
|
||||||
"void a() {\n"
|
"void a() {\n"
|
||||||
" struct s s1;\n"
|
" struct s s1;\n"
|
||||||
" b(&s1);\n"
|
" b(&s1);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// # 9290
|
// # 9290
|
||||||
|
@ -4596,7 +4596,7 @@ private:
|
||||||
" A * c;\n"
|
" A * c;\n"
|
||||||
" c->x = 42;\n"
|
" c->x = 42;\n"
|
||||||
" return c->x;\n"
|
" return c->x;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: c\n"
|
ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: c\n"
|
||||||
"[test.cpp:7]: (error) Uninitialized variable: c\n",
|
"[test.cpp:7]: (error) Uninitialized variable: c\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
|
@ -4608,7 +4608,7 @@ private:
|
||||||
" A c;\n"
|
" A c;\n"
|
||||||
" c.x = 42;\n"
|
" c.x = 42;\n"
|
||||||
" return c.x;\n"
|
" return c.x;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
valueFlowUninit("struct A {\n"
|
valueFlowUninit("struct A {\n"
|
||||||
|
@ -4621,7 +4621,7 @@ private:
|
||||||
"double b() {\n"
|
"double b() {\n"
|
||||||
" A c;\n"
|
" A c;\n"
|
||||||
" return d(&c);\n"
|
" return d(&c);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// # 9302
|
// # 9302
|
||||||
|
@ -4634,7 +4634,7 @@ private:
|
||||||
" vz.typ = 42;\n"
|
" vz.typ = 42;\n"
|
||||||
" if (pvz->typ == 0)\n"
|
" if (pvz->typ == 0)\n"
|
||||||
" return;\n"
|
" return;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// # 9305
|
// # 9305
|
||||||
|
@ -4650,7 +4650,7 @@ private:
|
||||||
" set( pb);\n"
|
" set( pb);\n"
|
||||||
" if (pb->x)\n"
|
" if (pb->x)\n"
|
||||||
" return;\n"
|
" return;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// # 9348
|
// # 9348
|
||||||
|
@ -4661,7 +4661,7 @@ private:
|
||||||
"void g() {\n"
|
"void g() {\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
" f(&i);\n"
|
" f(&i);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// # 9631
|
// # 9631
|
||||||
|
@ -4672,7 +4672,7 @@ private:
|
||||||
" size_t bytesCopied;\n"
|
" size_t bytesCopied;\n"
|
||||||
" bool copied_all = true;\n"
|
" bool copied_all = true;\n"
|
||||||
" g(&copied_all, 5, 6, &bytesCopied);\n"
|
" g(&copied_all, 5, 6, &bytesCopied);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:2]: (error) Uninitialized variable: *buflen\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:2]: (error) Uninitialized variable: *buflen\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4684,7 +4684,7 @@ private:
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" C *c;\n"
|
" C *c;\n"
|
||||||
" if (c->x() == 4) {}\n"
|
" if (c->x() == 4) {}\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: c\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: c\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4696,7 +4696,7 @@ private:
|
||||||
"int main() {\n"
|
"int main() {\n"
|
||||||
" Foo* foo;\n"
|
" Foo* foo;\n"
|
||||||
" foo->b\n"
|
" foo->b\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: foo\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: foo\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -226,7 +226,7 @@ private:
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" template<typename T> void foo( T t ) const;\n"
|
" template<typename T> void foo( T t ) const;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"template<typename T> void X::foo( T t ) const { }\n");
|
"template<typename T> void X::foo( T t ) const { }");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'bar' is never used.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'bar' is never used.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,19 +257,19 @@ private:
|
||||||
|
|
||||||
void unusedError() {
|
void unusedError() {
|
||||||
check("void foo() {}\n"
|
check("void foo() {}\n"
|
||||||
"int main()\n");
|
"int main()");
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str());
|
||||||
|
|
||||||
check("void foo() const {}\n"
|
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());
|
ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str());
|
||||||
|
|
||||||
check("void foo() const throw() {}\n"
|
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());
|
ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str());
|
||||||
|
|
||||||
check("void foo() throw() {}\n"
|
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());
|
ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ private:
|
||||||
void lineNumber() {
|
void lineNumber() {
|
||||||
check("void foo() {}\n"
|
check("void foo() {}\n"
|
||||||
"void bar() {}\n"
|
"void bar() {}\n"
|
||||||
"int main()\n");
|
"int main()");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) The function 'bar' is never used.\n"
|
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());
|
"[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 &){ return A(); }\n"
|
||||||
"A operator -- (const A &, const int){ return A(); }\n"
|
"A operator -- (const A &, const int){ return A(); }\n"
|
||||||
"A operator -- (const A &){ 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());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -416,7 +416,7 @@ private:
|
||||||
"}\n"
|
"}\n"
|
||||||
"class A::B {"
|
"class A::B {"
|
||||||
" B() { A a; a.f(); }\n"
|
" B() { A a; a.f(); }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1464,7 +1464,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" printf(\"var.struct1.a = %d\", var.struct1.a);\n"
|
" printf(\"var.struct1.a = %d\", var.struct1.a);\n"
|
||||||
" return 1;\n"
|
" return 1;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3136,7 +3136,7 @@ private:
|
||||||
functionVariableUsage("Padding fun() {\n"
|
functionVariableUsage("Padding fun() {\n"
|
||||||
" Distance d = DISTANCE;\n"
|
" Distance d = DISTANCE;\n"
|
||||||
" return (Padding){ d, d, d, d };\n"
|
" return (Padding){ d, d, d, d };\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3203,7 +3203,7 @@ private:
|
||||||
functionVariableUsage("void fun() {\n"
|
functionVariableUsage("void fun() {\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
" while (c) { x=10; }\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());
|
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"
|
functionVariableUsage("void dostuff(int x);\n"
|
||||||
|
@ -3213,7 +3213,7 @@ private:
|
||||||
" dostuff(x);\n"
|
" dostuff(x);\n"
|
||||||
" if (y) { x=10; break; }\n"
|
" if (y) { x=10; break; }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str());
|
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"
|
functionVariableUsage("void dostuff(int &x);\n"
|
||||||
|
@ -3223,7 +3223,7 @@ private:
|
||||||
" dostuff(x);\n"
|
" dostuff(x);\n"
|
||||||
" if (y) { x=10; break; }\n"
|
" if (y) { x=10; break; }\n"
|
||||||
" }\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
|
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"
|
functionVariableUsage("void fun() {\n"
|
||||||
|
@ -3232,13 +3232,13 @@ private:
|
||||||
" dostuff(x);\n"
|
" dostuff(x);\n"
|
||||||
" x = 10;\n"
|
" x = 10;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
functionVariableUsage("void fun() {\n"
|
functionVariableUsage("void fun() {\n"
|
||||||
" int x = 0;\n"
|
" int x = 0;\n"
|
||||||
" while (x < 10) { x = x + 1; }\n"
|
" while (x < 10) { x = x + 1; }\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
functionVariableUsage("void fun()\n"
|
functionVariableUsage("void fun()\n"
|
||||||
|
@ -5469,7 +5469,7 @@ private:
|
||||||
" goto label;\n"
|
" goto label;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" return false;\n"
|
" return false;\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'X' is assigned a value that is never used.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'X' is assigned a value that is never used.\n", errout.str());
|
||||||
|
|
||||||
// #4558
|
// #4558
|
||||||
|
@ -5721,8 +5721,7 @@ private:
|
||||||
" static int fpUnread{0};\n"
|
" static int fpUnread{0};\n"
|
||||||
" const int var{fpUnread++};\n"
|
" const int var{fpUnread++};\n"
|
||||||
" return var;\n"
|
" return var;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5730,8 +5729,7 @@ private:
|
||||||
functionVariableUsage(
|
functionVariableUsage(
|
||||||
"void fun(Value value) {\n"
|
"void fun(Value value) {\n"
|
||||||
" value[10] = 123;\n"
|
" value[10] = 123;\n"
|
||||||
"}\n"
|
"}");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
functionVariableUsage(
|
functionVariableUsage(
|
||||||
|
@ -5810,8 +5808,7 @@ private:
|
||||||
" else\n"
|
" else\n"
|
||||||
" (*pos).second = number;\n"
|
" (*pos).second = number;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n"
|
"};");
|
||||||
);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,7 +167,7 @@ private:
|
||||||
" return va_arg(ap, const char*);\n"
|
" return va_arg(ap, const char*);\n"
|
||||||
" });\n"
|
" });\n"
|
||||||
" va_end(ap);\n"
|
" va_end(ap);\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f(int n, ...)\n"
|
check("void f(int n, ...)\n"
|
||||||
|
@ -179,7 +179,7 @@ private:
|
||||||
" {\n"
|
" {\n"
|
||||||
" return va_arg(ap, const char*);\n"
|
" return va_arg(ap, const char*);\n"
|
||||||
" });\n"
|
" });\n"
|
||||||
"}\n");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:10]: (error) va_list 'ap' was opened but not closed by va_end().\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:10]: (error) va_list 'ap' was opened but not closed by va_end().\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -613,7 +613,7 @@ private:
|
||||||
|
|
||||||
code = "void f(int i) {\n"
|
code = "void f(int i) {\n"
|
||||||
" X x;\n"
|
" X x;\n"
|
||||||
" y = g(std::move(x), \n"
|
" y = g(std::move(x),\n"
|
||||||
" x.size());\n"
|
" x.size());\n"
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::MovedVariable));
|
ASSERT_EQUALS(false, testValueOfX(code, 4U, ValueFlow::Value::MoveKind::MovedVariable));
|
||||||
|
@ -1556,7 +1556,7 @@ private:
|
||||||
"\n"
|
"\n"
|
||||||
"out:\n"
|
"out:\n"
|
||||||
" if (abc) {}\n"
|
" if (abc) {}\n"
|
||||||
"}\n");
|
"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueFlowBeforeConditionForward() {
|
void valueFlowBeforeConditionForward() {
|
||||||
|
@ -2472,7 +2472,7 @@ private:
|
||||||
// protected usage with &&
|
// protected usage with &&
|
||||||
code = "void f(const Token* x) {\n"
|
code = "void f(const Token* x) {\n"
|
||||||
" if (x) {}\n"
|
" if (x) {}\n"
|
||||||
" for (; x && \n"
|
" for (; x &&\n"
|
||||||
" x->str() != y; x = x->next()) {}\n"
|
" x->str() != y; x = x->next()) {}\n"
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));
|
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));
|
||||||
|
@ -2480,7 +2480,7 @@ private:
|
||||||
|
|
||||||
code = "void f(const Token* x) {\n"
|
code = "void f(const Token* x) {\n"
|
||||||
" if (x) {}\n"
|
" if (x) {}\n"
|
||||||
" if (x && \n"
|
" if (x &&\n"
|
||||||
" x->str() != y) {}\n"
|
" x->str() != y) {}\n"
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));
|
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));
|
||||||
|
@ -2833,9 +2833,9 @@ private:
|
||||||
|
|
||||||
code = "void f(int i) {\n"
|
code = "void f(int i) {\n"
|
||||||
" int x = 0;\n"
|
" int x = 0;\n"
|
||||||
" if (i == 0) \n"
|
" if (i == 0)\n"
|
||||||
" x = 1;\n"
|
" x = 1;\n"
|
||||||
" else if (!x && i == 1) \n"
|
" else if (!x && i == 1)\n"
|
||||||
" int b = x;\n"
|
" int b = x;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
ASSERT_EQUALS(true, testValueOfXKnown(code, 5U, 0));
|
ASSERT_EQUALS(true, testValueOfXKnown(code, 5U, 0));
|
||||||
|
@ -4303,7 +4303,7 @@ private:
|
||||||
|
|
||||||
code = "void f(int i, int j, bool a) {\n"
|
code = "void f(int i, int j, bool a) {\n"
|
||||||
" if (i != j) {}\n"
|
" if (i != j) {}\n"
|
||||||
" if (i == j) return; \n"
|
" if (i == j) return;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
ASSERT_EQUALS(false, valueOfTok(code, "!=").intvalue == 1);
|
ASSERT_EQUALS(false, valueOfTok(code, "!=").intvalue == 1);
|
||||||
|
|
||||||
|
@ -4335,7 +4335,7 @@ private:
|
||||||
code = "void f(int i, int j, bool a) {\n"
|
code = "void f(int i, int j, bool a) {\n"
|
||||||
" bool x = (i != j);\n"
|
" bool x = (i != j);\n"
|
||||||
" bool b = x;\n"
|
" bool b = x;\n"
|
||||||
" if (i != j) return; \n"
|
" if (i != j) return;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
ASSERT_EQUALS(false, testValueOfXKnown(code, 3U, 0));
|
ASSERT_EQUALS(false, testValueOfXKnown(code, 3U, 0));
|
||||||
|
|
||||||
|
|
|
@ -476,7 +476,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" std::string str(\"test\");\n"
|
" std::string str(\"test\");\n"
|
||||||
" str.clear();\n"
|
" str.clear();\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
const char expected[] = "1: void func ( )\n"
|
const char expected[] = "1: void func ( )\n"
|
||||||
"2: {\n"
|
"2: {\n"
|
||||||
|
@ -514,8 +514,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void varid11() {
|
void varid11() {
|
||||||
const std::string actual = tokenize(
|
const std::string actual = tokenize("class Foo;");
|
||||||
"class Foo;\n");
|
|
||||||
|
|
||||||
const char expected[] = "1: class Foo ;\n";
|
const char expected[] = "1: class Foo ;\n";
|
||||||
|
|
||||||
|
@ -527,7 +526,7 @@ private:
|
||||||
"static void a()\n"
|
"static void a()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" class Foo *foo;\n"
|
" class Foo *foo;\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
const char expected[] = "1: static void a ( )\n"
|
const char expected[] = "1: static void a ( )\n"
|
||||||
"2: {\n"
|
"2: {\n"
|
||||||
|
@ -1278,8 +1277,7 @@ private:
|
||||||
"std::list<boost::wave::token_id> tokens;\n"
|
"std::list<boost::wave::token_id> tokens;\n"
|
||||||
"static std::vector<CvsProcess*> ex1;\n"
|
"static std::vector<CvsProcess*> ex1;\n"
|
||||||
"extern std::vector<CvsProcess*> ex2;\n"
|
"extern std::vector<CvsProcess*> ex2;\n"
|
||||||
"std::map<int, 1> m;\n"
|
"std::map<int, 1> m;");
|
||||||
);
|
|
||||||
|
|
||||||
const char expected[] = "1: list < int > ints@1 ;\n"
|
const char expected[] = "1: list < int > ints@1 ;\n"
|
||||||
"2: list < int > :: iterator it@2 ;\n"
|
"2: list < int > :: iterator it@2 ;\n"
|
||||||
|
@ -1313,7 +1311,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" int *a;\n"
|
" int *a;\n"
|
||||||
" delete a;\n"
|
" delete a;\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
const char expected[] = "1: void f ( )\n"
|
const char expected[] = "1: void f ( )\n"
|
||||||
"2: {\n"
|
"2: {\n"
|
||||||
|
@ -1364,7 +1362,7 @@ private:
|
||||||
"void f3(const std::string &s)\n"
|
"void f3(const std::string &s)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" s.size();\n"
|
" s.size();\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
const char expected[] = "1: void f1 ( int & p@1 )\n"
|
const char expected[] = "1: void f1 ( int & p@1 )\n"
|
||||||
"2: {\n"
|
"2: {\n"
|
||||||
|
@ -1408,7 +1406,7 @@ private:
|
||||||
" std::vector<int> b;\n"
|
" std::vector<int> b;\n"
|
||||||
" std::vector<int> &a = b;\n"
|
" std::vector<int> &a = b;\n"
|
||||||
" std::vector<int> *c = &b;\n"
|
" std::vector<int> *c = &b;\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
const char expected[] = "1: void f ( )\n"
|
const char expected[] = "1: void f ( )\n"
|
||||||
"2: {\n"
|
"2: {\n"
|
||||||
|
@ -1428,7 +1426,7 @@ private:
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" std::string name1;\n"
|
" std::string name1;\n"
|
||||||
" std::string name2;\n"
|
" std::string name2;\n"
|
||||||
"};\n");
|
"};");
|
||||||
|
|
||||||
const char expected[] = "1: class Foo\n"
|
const char expected[] = "1: class Foo\n"
|
||||||
"2: {\n"
|
"2: {\n"
|
||||||
|
@ -1454,7 +1452,7 @@ private:
|
||||||
" POINT pOutput = { 0 , 0 };\n"
|
" POINT pOutput = { 0 , 0 };\n"
|
||||||
" int x = pOutput.x;\n"
|
" int x = pOutput.x;\n"
|
||||||
" int y = pOutput.y;\n"
|
" int y = pOutput.y;\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
const char expected[] = "1: class foo\n"
|
const char expected[] = "1: class foo\n"
|
||||||
"2: {\n"
|
"2: {\n"
|
||||||
|
@ -1489,7 +1487,7 @@ private:
|
||||||
"void Bar::f()\n"
|
"void Bar::f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" foo.x = x;\n"
|
" foo.x = x;\n"
|
||||||
"}\n");
|
"}");
|
||||||
const char expected[] = "1: struct Foo {\n"
|
const char expected[] = "1: struct Foo {\n"
|
||||||
"2: int x@1 ;\n"
|
"2: int x@1 ;\n"
|
||||||
"3: } ;\n"
|
"3: } ;\n"
|
||||||
|
@ -2199,7 +2197,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" void operator=(const Foo &);\n"
|
" void operator=(const Foo &);\n"
|
||||||
"};\n");
|
"};");
|
||||||
|
|
||||||
const char expected[] = "1: class Foo\n"
|
const char expected[] = "1: class Foo\n"
|
||||||
"2: {\n"
|
"2: {\n"
|
||||||
|
@ -2213,7 +2211,7 @@ private:
|
||||||
const std::string actual = tokenize(
|
const std::string actual = tokenize(
|
||||||
"struct Foo {\n"
|
"struct Foo {\n"
|
||||||
" void * operator new [](int);\n"
|
" void * operator new [](int);\n"
|
||||||
"};\n");
|
"};");
|
||||||
const char expected[] = "1: struct Foo {\n"
|
const char expected[] = "1: struct Foo {\n"
|
||||||
"2: void * operatornew[] ( int ) ;\n"
|
"2: void * operatornew[] ( int ) ;\n"
|
||||||
"3: } ;\n";
|
"3: } ;\n";
|
||||||
|
@ -2225,7 +2223,7 @@ private:
|
||||||
void varid_throw() { // ticket #1723
|
void varid_throw() { // ticket #1723
|
||||||
const std::string actual = tokenize(
|
const std::string actual = tokenize(
|
||||||
"UserDefinedException* pe = new UserDefinedException();\n"
|
"UserDefinedException* pe = new UserDefinedException();\n"
|
||||||
"throw pe;\n");
|
"throw pe;");
|
||||||
|
|
||||||
const char expected[] = "1: UserDefinedException * pe@1 ; pe@1 = new UserDefinedException ( ) ;\n"
|
const char expected[] = "1: UserDefinedException * pe@1 ; pe@1 = new UserDefinedException ( ) ;\n"
|
||||||
"2: throw pe@1 ;\n";
|
"2: throw pe@1 ;\n";
|
||||||
|
@ -2383,7 +2381,7 @@ private:
|
||||||
" class QErrorLogger {\n"
|
" class QErrorLogger {\n"
|
||||||
" void reportErr(ErrorLogger::ErrorMessage &msg) {\n"
|
" void reportErr(ErrorLogger::ErrorMessage &msg) {\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }; \n"
|
" };\n"
|
||||||
"}"));
|
"}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2716,7 +2714,7 @@ private:
|
||||||
"Fred::foo1()\n"
|
"Fred::foo1()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" i = 0;\n"
|
" i = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
const char expected[] = "1: class Fred\n"
|
const char expected[] = "1: class Fred\n"
|
||||||
"2: {\n"
|
"2: {\n"
|
||||||
|
@ -2752,7 +2750,7 @@ private:
|
||||||
"void Fred::f()\n"
|
"void Fred::f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" i = 0;\n"
|
" i = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
const char expected[] = "1: class Fred\n"
|
const char expected[] = "1: class Fred\n"
|
||||||
"2: { void f ( ) ; } ;\n"
|
"2: { void f ( ) ; } ;\n"
|
||||||
|
@ -2784,7 +2782,7 @@ private:
|
||||||
"void A::f()\n"
|
"void A::f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" i = 0;\n"
|
" i = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
const char expected[] = "1: class Fred\n"
|
const char expected[] = "1: class Fred\n"
|
||||||
"2: { int i@1 ; void f ( ) ; } ;\n"
|
"2: { int i@1 ; void f ( ) ; } ;\n"
|
||||||
|
@ -2812,7 +2810,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" if (i) { }\n"
|
" if (i) { }\n"
|
||||||
" i = 0;\n"
|
" i = 0;\n"
|
||||||
"}\n");
|
"}");
|
||||||
|
|
||||||
const char expected[] = "1: class Fred\n"
|
const char expected[] = "1: class Fred\n"
|
||||||
"2: { int i@1 ; void f ( ) ; } ;\n"
|
"2: { int i@1 ; void f ( ) ; } ;\n"
|
||||||
|
@ -2834,7 +2832,7 @@ private:
|
||||||
" A *a;\n"
|
" A *a;\n"
|
||||||
" B() : a(new A)\n"
|
" B() : a(new A)\n"
|
||||||
" { }\n"
|
" { }\n"
|
||||||
"};\n");
|
"};");
|
||||||
|
|
||||||
const char expected[] = "1: class A { } ;\n"
|
const char expected[] = "1: class A { } ;\n"
|
||||||
"2: class B\n"
|
"2: class B\n"
|
||||||
|
|
Loading…
Reference in New Issue