Removed preprocessor directives from tests that aren't preprocessed before being tokenized.
This commit is contained in:
parent
5262ba16d9
commit
43c060b630
|
@ -958,12 +958,11 @@ private:
|
|||
}
|
||||
|
||||
void array_index_22() {
|
||||
check("#include <cstring>\n"
|
||||
"int main() {\n"
|
||||
check("int main() {\n"
|
||||
" size_t indices[2];\n"
|
||||
" int b = indices[2];\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'indices[2]' accessed at index 2, which is out of bounds\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Array 'indices[2]' accessed at index 2, which is out of bounds\n", errout.str());
|
||||
}
|
||||
|
||||
void array_index_23() {
|
||||
|
|
|
@ -4786,25 +4786,23 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'Fred::a' can be const.\n", errout.str());
|
||||
|
||||
// ticket #1593
|
||||
checkConst("#include <vector>\n"
|
||||
"class A\n"
|
||||
checkConst("class A\n"
|
||||
"{\n"
|
||||
" std::vector<int> m_v;\n"
|
||||
"public:\n"
|
||||
" A(){}\n"
|
||||
" unsigned int GetVecSize() {return m_v.size();}\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("[test.cpp:7]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:6]: (style, inconclusive) Technically the member function 'A::GetVecSize' can be const.\n", errout.str());
|
||||
|
||||
checkConst("#include <vector>\n"
|
||||
"class A\n"
|
||||
checkConst("class A\n"
|
||||
"{\n"
|
||||
" std::vector<int> m_v;\n"
|
||||
"public:\n"
|
||||
" A(){}\n"
|
||||
" bool GetVecEmpty() {return m_v.empty();}\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("[test.cpp:7]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:6]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const.\n", errout.str());
|
||||
}
|
||||
|
||||
void constVirtualFunc() {
|
||||
|
|
|
@ -1887,8 +1887,7 @@ private:
|
|||
}
|
||||
|
||||
void uninitVarStream() {
|
||||
check("#include <fstream>\n"
|
||||
"class Foo\n"
|
||||
check("class Foo\n"
|
||||
"{\n"
|
||||
"private:\n"
|
||||
" int foo;\n"
|
||||
|
|
|
@ -2345,8 +2345,7 @@ private:
|
|||
}
|
||||
|
||||
void trac1132() {
|
||||
check("#include <iostream>\n"
|
||||
"class Lock\n"
|
||||
check("class Lock\n"
|
||||
"{\n"
|
||||
"public:\n"
|
||||
" Lock(int i)\n"
|
||||
|
@ -2365,7 +2364,7 @@ private:
|
|||
" return 0;\n"
|
||||
"}\n"
|
||||
);
|
||||
ASSERT_EQUALS("[test.cpp:16]: (error) Instance of \"Lock\" object destroyed immediately.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:15]: (error) Instance of \"Lock\" object destroyed immediately.\n", errout.str());
|
||||
}
|
||||
|
||||
void trac3693() {
|
||||
|
@ -2449,10 +2448,7 @@ private:
|
|||
}
|
||||
|
||||
void testMisusedScopeObjectDoesNotPickFunctor() {
|
||||
check("\n"
|
||||
"#include <algorithm>\n"
|
||||
"\n"
|
||||
"class IncrementFunctor\n"
|
||||
check("class IncrementFunctor\n"
|
||||
"{\n"
|
||||
"public:\n"
|
||||
" void operator()(int &i)\n"
|
||||
|
@ -2545,9 +2541,7 @@ private:
|
|||
}
|
||||
|
||||
void trac2084() {
|
||||
check("#include <signal.h>\n"
|
||||
"\n"
|
||||
"void f()\n"
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" struct sigaction sa;\n"
|
||||
"\n"
|
||||
|
|
|
@ -70,9 +70,7 @@ private:
|
|||
}
|
||||
|
||||
void testsimple() {
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"int main(int argc, char *argv[])\n"
|
||||
check("int main()\n"
|
||||
"{\n"
|
||||
" unsigned int k(0);\n"
|
||||
" std::cout << k << std::endl;\n"
|
||||
|
@ -88,10 +86,8 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"class K {};"
|
||||
"int main(int argc, char *argv[])\n"
|
||||
check("class K {};"
|
||||
"int main()\n"
|
||||
"{\n"
|
||||
" K k(0);\n"
|
||||
" std::cout << k << std::endl;\n"
|
||||
|
@ -99,30 +95,26 @@ private:
|
|||
" std::cout << k << std::endl;\n"
|
||||
" return 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:7]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:5]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
|
||||
check("\n"
|
||||
"struct K {};"
|
||||
check("struct K {};"
|
||||
"void foo()\n"
|
||||
"{\n"
|
||||
" K k(0);\n"
|
||||
" k++;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
|
||||
check("\n"
|
||||
"union K {};"
|
||||
check("union K {};"
|
||||
"void foo()\n"
|
||||
"{\n"
|
||||
" K k(0);\n"
|
||||
" k++;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"class K {};"
|
||||
"int main(int argc, char *argv[])\n"
|
||||
check("class K {};"
|
||||
"int main()\n"
|
||||
"{\n"
|
||||
" K k(1);\n"
|
||||
" std::cout << k << std::endl;\n"
|
||||
|
@ -132,12 +124,10 @@ private:
|
|||
" std::cout << k << std::endl;\n"
|
||||
" return 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:8]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"class K {};"
|
||||
"int main(int argc, char *argv[])\n"
|
||||
check("class K {};"
|
||||
"int main()\n"
|
||||
"{\n"
|
||||
" K k(1);\n"
|
||||
" std::cout << k << std::endl;\n"
|
||||
|
@ -148,13 +138,11 @@ private:
|
|||
" std::cout << k << std::endl;\n"
|
||||
" return 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:10]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:8]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
|
||||
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"class K {};"
|
||||
"int main(int argc, char *argv[])\n"
|
||||
check("class K {};"
|
||||
"int main()\n"
|
||||
"{\n"
|
||||
" K k(0);\n"
|
||||
" std::cout << k << std::endl;\n"
|
||||
|
@ -162,12 +150,10 @@ private:
|
|||
" std::cout << k << std::endl;\n"
|
||||
" return 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:7]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:5]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"class K {};"
|
||||
"int main(int argc, char *argv[])\n"
|
||||
check("class K {};"
|
||||
"int main()\n"
|
||||
"{\n"
|
||||
" K k(0);\n"
|
||||
" std::cout << k << std::endl;\n"
|
||||
|
@ -177,10 +163,8 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"class K {};"
|
||||
"int main(int argc, char *argv[])\n"
|
||||
check("class K {};"
|
||||
"int main()\n"
|
||||
"{\n"
|
||||
" K k(0);\n"
|
||||
" std::cout << k << std::endl;\n"
|
||||
|
@ -193,9 +177,7 @@ private:
|
|||
}
|
||||
|
||||
void testfor() {
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"int main(int argc, char *argv[])\n"
|
||||
check("int main()\n"
|
||||
"{\n"
|
||||
" for ( unsigned int i=0; i <= 10; i++) {\n"
|
||||
" std::cout << i << std::endl;\n"
|
||||
|
@ -204,22 +186,18 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"class K {};\n"
|
||||
"int main(int argc, char *argv[])\n"
|
||||
check("class K {};\n"
|
||||
"int main()\n"
|
||||
"{\n"
|
||||
" for ( K i(0); i <= 10; i++) {\n"
|
||||
" std::cout << i << std::endl;\n"
|
||||
" }\n"
|
||||
" return 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"class K {};\n"
|
||||
"int main(int argc, char *argv[])\n"
|
||||
check("class K {};\n"
|
||||
"int main()\n"
|
||||
"{\n"
|
||||
" for ( K i(0); i <= 10; ++i) {\n"
|
||||
" std::cout << i << std::endl;\n"
|
||||
|
@ -228,21 +206,17 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"class K {};\n"
|
||||
"int main(int argc, char *argv[])\n"
|
||||
check("class K {};\n"
|
||||
"int main()\n"
|
||||
"{\n"
|
||||
" for ( K i(10); i > 1; i--) {\n"
|
||||
" std::cout << i << std::endl;\n"
|
||||
" }\n"
|
||||
" return 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"class K {};\n"
|
||||
check("class K {};\n"
|
||||
"int main(int argc, char *argv[])\n"
|
||||
"{\n"
|
||||
" for ( K i=10; i > 1; --i) {\n"
|
||||
|
@ -256,9 +230,7 @@ private:
|
|||
}
|
||||
|
||||
void teststream() {
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"int main(int argc, char *argv[])\n"
|
||||
check("int main()\n"
|
||||
"{\n"
|
||||
" int k(0);\n"
|
||||
" std::cout << k << std::endl;\n"
|
||||
|
@ -268,22 +240,18 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"class K {};\n"
|
||||
"int main(int argc, char *argv[])\n"
|
||||
check("class K {};\n"
|
||||
"int main()\n"
|
||||
"{\n"
|
||||
" K k(0);\n"
|
||||
" std::cout << k << std::endl;\n"
|
||||
" std::cout << k-- << std::endl;\n"
|
||||
" return 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:8]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"class K {};\n"
|
||||
"int main(int argc, char *argv[])\n"
|
||||
check("class K {};\n"
|
||||
"int main()\n"
|
||||
"{\n"
|
||||
" K k(0);\n"
|
||||
" std::cout << k << std::endl;\n"
|
||||
|
@ -295,10 +263,8 @@ private:
|
|||
}
|
||||
|
||||
void testvolatile() {
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"class K {};\n"
|
||||
"int main(int argc, char *argv[])\n"
|
||||
check("class K {};\n"
|
||||
"int main()\n"
|
||||
"{\n"
|
||||
" volatile K k(0);\n"
|
||||
" std::cout << k << std::endl;\n"
|
||||
|
@ -307,13 +273,11 @@ private:
|
|||
" return 0;\n"
|
||||
"}\n");
|
||||
TODO_ASSERT_EQUALS("",
|
||||
"[test.cpp:8]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
"[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
}
|
||||
|
||||
void testiterator() {
|
||||
check("\n"
|
||||
"#include <vector>\n"
|
||||
"class Base {};\n"
|
||||
check("class Base {};\n"
|
||||
"int main() {\n"
|
||||
" std::vector<Base*> v;\n"
|
||||
" v.push_back(new Base());\n"
|
||||
|
@ -324,12 +288,9 @@ private:
|
|||
" v.clear();\n"
|
||||
" return 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:8]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"#include <vector>\n"
|
||||
"int main() {\n"
|
||||
check("int main() {\n"
|
||||
" std::vector<int> v;\n"
|
||||
" std::vector<int>::iterator it;\n"
|
||||
" for( int i=0; i < 10; ++i ) v.push_back(i);\n"
|
||||
|
@ -341,12 +302,9 @@ private:
|
|||
" }\n"
|
||||
" return 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:12]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:9]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"#include <vector>\n"
|
||||
"int main() {\n"
|
||||
check("int main() {\n"
|
||||
" std::vector<int> v;\n"
|
||||
" std::vector<int>::const_iterator it;\n"
|
||||
" for( int i=0; i < 10; ++i ) v.push_back(i);\n"
|
||||
|
@ -357,12 +315,9 @@ private:
|
|||
" }\n"
|
||||
" return 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:11]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:8]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
|
||||
check("\n"
|
||||
"#include <iostream>\n"
|
||||
"#include <vector>\n"
|
||||
"int main() {\n"
|
||||
check("int main() {\n"
|
||||
" std::vector<int> v;\n"
|
||||
" std::vector<int>::iterator it;\n"
|
||||
" for( int i=0; i < 10; ++i ) v.push_back(i);\n"
|
||||
|
@ -374,7 +329,7 @@ private:
|
|||
" }\n"
|
||||
" return 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:12]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:9]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1857,8 +1857,7 @@ private:
|
|||
"the object. Use operator= instead.\n"
|
||||
"[test.cpp:9]: (performance) Useless call of function \'substr\' because it returns an empty string.\n", errout.str());
|
||||
|
||||
check("#include <string>\n"
|
||||
"int main()\n"
|
||||
check("int main()\n"
|
||||
"{\n"
|
||||
" std::string str = \"a1b1\";\n"
|
||||
" return str.find(str[1], 2);\n"
|
||||
|
|
|
@ -547,8 +547,7 @@ private:
|
|||
}
|
||||
|
||||
void testDoesNotIdentifyMethodAsFirstFunctionArgument() {
|
||||
check("#include <iostream>"
|
||||
"void callback(void (*func)(int), int arg)"
|
||||
check("void callback(void (*func)(int), int arg)"
|
||||
"{"
|
||||
" (*func)(arg);"
|
||||
"}"
|
||||
|
@ -575,8 +574,7 @@ private:
|
|||
}
|
||||
|
||||
void testDoesNotIdentifyMethodAsMiddleFunctionArgument() {
|
||||
check("#include <iostream>"
|
||||
"void callback(char, void (*func)(int), int arg)"
|
||||
check("void callback(char, void (*func)(int), int arg)"
|
||||
"{"
|
||||
" (*func)(arg);"
|
||||
"}"
|
||||
|
@ -603,8 +601,7 @@ private:
|
|||
}
|
||||
|
||||
void testDoesNotIdentifyMethodAsLastFunctionArgument() {
|
||||
check("#include <iostream>"
|
||||
"void callback(int arg, void (*func)(int))"
|
||||
check("void callback(int arg, void (*func)(int))"
|
||||
"{"
|
||||
" (*func)(arg);"
|
||||
"}"
|
||||
|
|
Loading…
Reference in New Issue