Unit test cleanup: Removed some empty lines and whitespaces before \n.

This commit is contained in:
PKEuS 2012-12-06 10:19:22 -08:00
parent ae447a192a
commit 4737966caf
10 changed files with 63 additions and 68 deletions

View File

@ -1401,7 +1401,7 @@ private:
void array_index_43() { // #3838 void array_index_43() { // #3838
check("int f( ) \n" check("int f( )\n"
"{\n" "{\n"
" struct {\n" " struct {\n"
" int arr[ 3 ];\n" " int arr[ 3 ];\n"
@ -1415,7 +1415,7 @@ private:
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:10]: (error) Array 'var[0].arr[3]' index 3 out of bounds.\n","", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:10]: (error) Array 'var[0].arr[3]' index 3 out of bounds.\n","", errout.str());
check("int f( ) \n" check("int f( )\n"
"{\n" "{\n"
" struct {\n" " struct {\n"
" int arr[ 3 ];\n" " int arr[ 3 ];\n"
@ -2592,7 +2592,7 @@ private:
check("void main() {\n" check("void main() {\n"
" int array[] = {1,2};\n" " int array[] = {1,2};\n"
" int x = 0;\n" " int x = 0;\n"
" for( int i = 0; i<6; ) { \n" " for( int i = 0; i<6; ) {\n"
" x += array[i];\n" " x += array[i];\n"
" i++; }\n" " i++; }\n"
"}\n"); "}\n");
@ -2601,7 +2601,7 @@ private:
check("void main() {\n" check("void main() {\n"
" int array[] = {1,2};\n" " int array[] = {1,2};\n"
" int x = 0;\n" " int x = 0;\n"
" for( int i = 0; i<6; ) { \n" " for( int i = 0; i<6; ) {\n"
" i++; }\n" " i++; }\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -2611,7 +2611,7 @@ private:
check("void main() {\n" check("void main() {\n"
" int array[] = {1,2};\n" " int array[] = {1,2};\n"
" int x = 0;\n" " int x = 0;\n"
" for( int i = 0; i<6; ) { \n" " for( int i = 0; i<6; ) {\n"
" x += array[i++];\n" " x += array[i++];\n"
" }\n" " }\n"
"}\n"); "}\n");

View File

@ -1936,7 +1936,7 @@ private:
checkNoMemset("class Fred\n" checkNoMemset("class Fred\n"
"{\n" "{\n"
" std::string * b; \n" " std::string * b;\n"
"};\n" "};\n"
"void f()\n" "void f()\n"
"{\n" "{\n"
@ -1947,7 +1947,7 @@ private:
checkNoMemset("class Fred\n" checkNoMemset("class Fred\n"
"{\n" "{\n"
" std::string b; \n" " std::string b;\n"
"};\n" "};\n"
"void f()\n" "void f()\n"
"{\n" "{\n"
@ -1958,7 +1958,7 @@ private:
checkNoMemset("class Fred\n" checkNoMemset("class Fred\n"
"{\n" "{\n"
" mutable std::string b; \n" " mutable std::string b;\n"
"};\n" "};\n"
"void f()\n" "void f()\n"
"{\n" "{\n"
@ -2041,7 +2041,7 @@ private:
checkNoMemset("namespace n1 {\n" checkNoMemset("namespace n1 {\n"
" class Fred\n" " class Fred\n"
" {\n" " {\n"
" std::string b; \n" " std::string b;\n"
" };\n" " };\n"
"}\n" "}\n"
"void f()\n" "void f()\n"
@ -2055,7 +2055,7 @@ private:
checkNoMemset("namespace n1 {\n" checkNoMemset("namespace n1 {\n"
" class Fred\n" " class Fred\n"
" {\n" " {\n"
" std::string b; \n" " std::string b;\n"
" };\n" " };\n"
"}\n" "}\n"
"void f()\n" "void f()\n"
@ -2069,7 +2069,7 @@ private:
checkNoMemset("namespace n1 {\n" checkNoMemset("namespace n1 {\n"
" class Fred\n" " class Fred\n"
" {\n" " {\n"
" std::string b; \n" " std::string b;\n"
" };\n" " };\n"
"}\n" "}\n"
"void f()\n" "void f()\n"
@ -2122,7 +2122,7 @@ private:
"{\n" "{\n"
" void g( struct sockaddr_in6& a);\n" " void g( struct sockaddr_in6& a);\n"
"private:\n" "private:\n"
" std::string b; \n" " std::string b;\n"
"};\n" "};\n"
"void f()\n" "void f()\n"
"{\n" "{\n"
@ -4181,7 +4181,7 @@ private:
"class A\n" "class A\n"
"{\n" "{\n"
" public:\n" " public:\n"
" \n" "\n"
" AA::BB::CC::DD a;\n" " AA::BB::CC::DD a;\n"
" void foo(AA::BB::CC::DD b)\n" " void foo(AA::BB::CC::DD b)\n"
" {\n" " {\n"

View File

@ -1524,7 +1524,7 @@ private:
"private:\n" "private:\n"
" int a[23];\n" " int a[23];\n"
"public:\n" "public:\n"
" Fred(); \n" " Fred();\n"
"};\n" "};\n"
"Fred::Fred() {\n" "Fred::Fred() {\n"
" a[x::y] = 0;\n" " a[x::y] = 0;\n"

View File

@ -2201,13 +2201,13 @@ private:
// #2705 // #2705
void func24() { void func24() {
check("void f(void) \n" check("void f(void)\n"
"{\n" "{\n"
" std::string *x = new std::string;\n" " std::string *x = new std::string;\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: x\n","", errout.str()); TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: x\n","", errout.str());
check("void f(void) \n" check("void f(void)\n"
"{\n" "{\n"
" std::string *x = new std::string;\n" " std::string *x = new std::string;\n"
" delete x;\n" " delete x;\n"
@ -2217,7 +2217,7 @@ private:
void func25() { // ticket #2904 void func25() { // ticket #2904
check("class Fred { };\n" check("class Fred { };\n"
"void f(void) \n" "void f(void)\n"
"{\n" "{\n"
" Fred *f = new Fred();\n" " Fred *f = new Fred();\n"
" delete f;\n" " delete f;\n"
@ -2225,14 +2225,14 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("class Fred { };\n" check("class Fred { };\n"
"void f(void) \n" "void f(void)\n"
"{\n" "{\n"
" Fred *f = new Fred();\n" " Fred *f = new Fred();\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: f\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: f\n", errout.str());
check("class Fred { void foo(){ } };\n" check("class Fred { void foo(){ } };\n"
"void f(void) \n" "void f(void)\n"
"{\n" "{\n"
" Fred *f = new Fred();\n" " Fred *f = new Fred();\n"
" delete f;\n" " delete f;\n"
@ -2240,7 +2240,7 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("class Fred { void foo(){ } };\n" check("class Fred { void foo(){ } };\n"
"void f(void) \n" "void f(void)\n"
"{\n" "{\n"
" Fred *f = new Fred();\n" " Fred *f = new Fred();\n"
"}\n"); "}\n");
@ -3479,11 +3479,11 @@ private:
check("int myfunc()\n" check("int myfunc()\n"
"{\n" "{\n"
" int handle;\n" " int handle;\n"
" \n" "\n"
" handle = open(\"myfile\");\n" " handle = open(\"myfile\");\n"
" if (handle < 0) return 1;\n" " if (handle < 0) return 1;\n"
" \n" "\n"
" while (some_condition()) \n" " while (some_condition())\n"
" if (some_other_condition())\n" " if (some_other_condition())\n"
" {\n" " {\n"
" close(handle);\n" " close(handle);\n"
@ -3497,11 +3497,11 @@ private:
check("int myfunc()\n" check("int myfunc()\n"
"{\n" "{\n"
" int handle;\n" " int handle;\n"
" \n" "\n"
" handle = open(\"myfile\", O_RDONLY);\n" " handle = open(\"myfile\", O_RDONLY);\n"
" if (handle < 0) return 1;\n" " if (handle < 0) return 1;\n"
" \n" "\n"
" while (some_condition()) \n" " while (some_condition())\n"
" if (some_other_condition())\n" " if (some_other_condition())\n"
" {\n" " {\n"
" return 3;\n" " return 3;\n"
@ -4115,7 +4115,7 @@ private:
"{\n" "{\n"
"public:\n" "public:\n"
" void foo()\n" " void foo()\n"
" { \n" " {\n"
" char *str = new char[100];\n" " char *str = new char[100];\n"
" delete [] str;\n" " delete [] str;\n"
" hello();\n" " hello();\n"

View File

@ -699,7 +699,7 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// Ticket #2463 // Ticket #2463
check("struct A \n" check("struct A\n"
"{\n" "{\n"
" B* W;\n" " B* W;\n"
"\n" "\n"
@ -1122,7 +1122,7 @@ private:
check("void foo()\n" check("void foo()\n"
"{\n" "{\n"
" struct my_type* p;\n" " struct my_type* p;\n"
" p = 0; \n" " p = 0;\n"
" p->x = 0;\n" " p->x = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
@ -1146,7 +1146,7 @@ private:
check("int foo()\n" check("int foo()\n"
"{\n" "{\n"
" my_type* p;\n" " my_type* p;\n"
" p = 0; \n" " p = 0;\n"
" return p->x;\n" " return p->x;\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
@ -1154,7 +1154,7 @@ private:
check("int foo()\n" check("int foo()\n"
"{\n" "{\n"
" struct my_type* p;\n" " struct my_type* p;\n"
" p = 0; \n" " p = 0;\n"
" return p->x;\n" " return p->x;\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());

View File

@ -274,12 +274,12 @@ private:
"}", "test.cpp", true, true); "}", "test.cpp", true, true);
ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Opposite conditions in nested 'if' blocks lead to a dead code block.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Opposite conditions in nested 'if' blocks lead to a dead code block.\n", errout.str());
check("void foo(int i) \n" check("void foo(int i)\n"
"{\n" "{\n"
" if(i > 5) {\n" " if(i > 5) {\n"
" i = bar();\n" " i = bar();\n"
" if(i < 5) {\n" " if(i < 5) {\n"
" cout << a; \n" " cout << a;\n"
" }\n" " }\n"
" }\n" " }\n"
"}", "test.cpp", true, true); "}", "test.cpp", true, true);
@ -329,7 +329,7 @@ private:
" int n = 100;\n" " int n = 100;\n"
" for(int i = 0; i < n; i ++)\n" " for(int i = 0; i < n; i ++)\n"
" {\n" " {\n"
" sum += i; \n" " sum += i;\n"
" }\n" " }\n"
" cout<<b/sum;\n" " cout<<b/sum;\n"
"}\n"); "}\n");
@ -4875,27 +4875,27 @@ private:
// Errors detected in Quake 3: Arena by PVS-Studio: Fragement 2 // Errors detected in Quake 3: Arena by PVS-Studio: Fragement 2
check("void f()\n" check("void f()\n"
"{\n" "{\n"
" if (front < 0) \n" " if (front < 0)\n"
" frac = (front)/(front-back);\n" " frac = (front)/(front-back);\n"
" else \n" " else\n"
" frac = (front)/(front-back);\n" " frac = (front)/(front-back);\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str());
check("void f()\n" check("void f()\n"
"{\n" "{\n"
" if (front < 0) \n" " if (front < 0)\n"
" { frac = (front)/(front-back);}\n" " { frac = (front)/(front-back);}\n"
" else \n" " else\n"
" frac = (front)/(front-back);\n" " frac = (front)/(front-back);\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str());
check("void f()\n" check("void f()\n"
"{\n" "{\n"
" if (front < 0) \n" " if (front < 0)\n"
" { frac = (front)/(front-back);}\n" " { frac = (front)/(front-back);}\n"
" else \n" " else\n"
" frac = (front)/((front-back));\n" " frac = (front)/((front-back));\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for 'if' and 'else'.\n", errout.str());

View File

@ -1706,7 +1706,6 @@ private:
"{\n" "{\n"
"public:\n" "public:\n"
" typedef ABC<T> m;\n" " typedef ABC<T> m;\n"
"\n"
"};\n"; "};\n";
const std::string expected("template < class T > class ABC { public: } ;"); const std::string expected("template < class T > class ABC { public: } ;");
@ -5257,10 +5256,10 @@ private:
} }
void simplifyTypedef65() { // ticket #2314 void simplifyTypedef65() { // ticket #2314
const char code[] = "typedef BAR<int> Foo; \n" const char code[] = "typedef BAR<int> Foo;\n"
"int main() { \n" "int main() {\n"
" Foo b(0); \n" " Foo b(0);\n"
" return b > Foo(10); \n" " return b > Foo(10);\n"
"}"; "}";
const std::string actual(tok(code)); const std::string actual(tok(code));
ASSERT_EQUALS("int main ( ) { BAR < int > b ( 0 ) ; return b > BAR < int > ( 10 ) ; }", actual); ASSERT_EQUALS("int main ( ) { BAR < int > b ( 0 ) ; return b > BAR < int > ( 10 ) ; }", actual);
@ -5296,7 +5295,7 @@ private:
void simplifyTypedef69() { // ticket #2348 void simplifyTypedef69() { // ticket #2348
const char code[] = "typedef int (*CompilerHook)();\n" const char code[] = "typedef int (*CompilerHook)();\n"
"typedef struct VirtualMachine \n" "typedef struct VirtualMachine\n"
"{\n" "{\n"
" CompilerHook *(*compilerHookVector)(void);\n" " CompilerHook *(*compilerHookVector)(void);\n"
"}VirtualMachine;\n"; "}VirtualMachine;\n";
@ -5417,7 +5416,7 @@ private:
} }
void simplifyTypedef75() { // ticket #2426 void simplifyTypedef75() { // ticket #2426
const char code[] = "typedef _Packed struct S { long l; }; \n"; const char code[] = "typedef _Packed struct S { long l; };\n";
const std::string expected = ""; const std::string expected = "";
ASSERT_EQUALS(expected, tok(code)); ASSERT_EQUALS(expected, tok(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -7002,7 +7001,7 @@ private:
void enum10() { void enum10() {
// ticket 1445 // ticket 1445
const char code[] = "enum {\n" const char code[] = "enum {\n"
"SHELL_SIZE = sizeof(union { int i; char *cp; double d; }) - 1, \n" "SHELL_SIZE = sizeof(union { int i; char *cp; double d; }) - 1,\n"
"} e = SHELL_SIZE;"; "} e = SHELL_SIZE;";
const char expected[] = "int e ; e = sizeof ( union { int i ; char * cp ; double d ; } ) - 1 ;"; const char expected[] = "int e ; e = sizeof ( union { int i ; char * cp ; double d ; } ) - 1 ;";
ASSERT_EQUALS(expected, checkSimplifyEnum(code)); ASSERT_EQUALS(expected, checkSimplifyEnum(code));
@ -7186,7 +7185,7 @@ private:
void enum28() { void enum28() {
const char code[] = "enum { x=0 };\n" const char code[] = "enum { x=0 };\n"
"void f() { char x[4]; memset(x, 0, 4); \n" "void f() { char x[4]; memset(x, 0, 4);\n"
"{ x } };\n" "{ x } };\n"
"void g() { x; }"; "void g() { x; }";
ASSERT_EQUALS("void f ( ) { char x [ 4 ] ; memset ( x , 0 , 4 ) ; { x } } ; void g ( ) { 0 ; }", checkSimplifyEnum(code)); ASSERT_EQUALS("void f ( ) { char x [ 4 ] ; memset ( x , 0 , 4 ) ; { x } } ; void g ( ) { 0 ; }", checkSimplifyEnum(code));

View File

@ -1187,7 +1187,7 @@ private:
errout.str(""); errout.str("");
const std::string src = "void f()\n" const std::string src = "void f()\n"
"{\n" "{\n"
" for ( \n" " for (\n"
"}\n"; "}\n";
Settings settings; Settings settings;
@ -1910,7 +1910,7 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("void f() \n" check("void f()\n"
"{\n" "{\n"
" auto_ptr<T> p2;\n" " auto_ptr<T> p2;\n"
" p2 = new T;\n" " p2 = new T;\n"
@ -1945,39 +1945,39 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// ticket #748 // ticket #748
check("void f() \n" check("void f()\n"
"{\n" "{\n"
" T* var = new T[10];\n" " T* var = new T[10];\n"
" auto_ptr<T> p2( var );\n" " auto_ptr<T> p2( var );\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n" check("void f()\n"
"{\n" "{\n"
" foo::bar::baz* var = new foo::bar::baz[10];\n" " foo::bar::baz* var = new foo::bar::baz[10];\n"
" auto_ptr<foo::bar::baz> p2( var );\n" " auto_ptr<foo::bar::baz> p2( var );\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n" check("void f()\n"
"{\n" "{\n"
" auto_ptr<T> p2( new T[] );\n" " auto_ptr<T> p2( new T[] );\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n" check("void f()\n"
"{\n" "{\n"
" auto_ptr<T> p2( new T[5] );\n" " auto_ptr<T> p2( new T[5] );\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n" check("void f()\n"
"{\n" "{\n"
" auto_ptr<foo::bar> p(new foo::bar[10]);\n" " auto_ptr<foo::bar> p(new foo::bar[10]);\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n" check("void f()\n"
"{\n" "{\n"
" auto_ptr<T> p2;\n" " auto_ptr<T> p2;\n"
" p2.reset( new T[] );\n" " p2.reset( new T[] );\n"
@ -1985,34 +1985,34 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n" check("void f()\n"
"{\n" "{\n"
" auto_ptr<T> p2( new T[][] );\n" " auto_ptr<T> p2( new T[][] );\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n" check("void f()\n"
"{\n" "{\n"
" auto_ptr<T> p2;\n" " auto_ptr<T> p2;\n"
" p2 = new T[10];\n" " p2 = new T[10];\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n" check("void f()\n"
"{\n" "{\n"
" auto_ptr<T::B> p2;\n" " auto_ptr<T::B> p2;\n"
" p2 = new T::B[10];\n" " p2 = new T::B[10];\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n" check("void f()\n"
"{\n" "{\n"
" auto_ptr<T> p2;\n" " auto_ptr<T> p2;\n"
" p2.reset( new T[10] );\n" " p2.reset( new T[10] );\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
check("void f() \n" check("void f()\n"
"{\n" "{\n"
" auto_ptr<T::B> p2;\n" " auto_ptr<T::B> p2;\n"
" p2.reset( new T::B[10] );\n" " p2.reset( new T::B[10] );\n"
@ -2034,7 +2034,6 @@ private:
" string s1, s2;\n" " string s1, s2;\n"
" s1.swap(s2);\n" " s1.swap(s2);\n"
" s2.swap(s2);\n" " s2.swap(s2);\n"
" \n"
"};\n"); "};\n");
ASSERT_EQUALS("[test.cpp:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)'\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (performance) It is inefficient to swap a object with itself by calling 's2.swap(s2)'\n", errout.str());
@ -2045,7 +2044,6 @@ private:
" s2.compare(s2);\n" " s2.compare(s2);\n"
" s1.compare(s2.c_str());\n" " s1.compare(s2.c_str());\n"
" s1.compare(0, s1.size(), s1);\n" " s1.compare(0, s1.size(), s1);\n"
" \n"
"};\n"); "};\n");
ASSERT_EQUALS("[test.cpp:5]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0.\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (warning) It is inefficient to call 's2.compare(s2)' as it always returns 0.\n", errout.str());
@ -2058,7 +2056,6 @@ private:
" s1 = s2.substr(0, x);\n" " s1 = s2.substr(0, x);\n"
" s1 = s2.substr(0,std::string::npos);\n" " s1 = s2.substr(0,std::string::npos);\n"
" s1 = s2.substr(x+5-n, 0);\n" " s1 = s2.substr(x+5-n, 0);\n"
" \n"
"};\n"); "};\n");
ASSERT_EQUALS("[test.cpp:5]: (performance) Ineffective call of function \'substr\' because it returns a copy of " ASSERT_EQUALS("[test.cpp:5]: (performance) Ineffective call of function \'substr\' because it returns a copy of "
"the object. Use operator= instead.\n" "the object. Use operator= instead.\n"

View File

@ -1153,7 +1153,7 @@ private:
"{\n" "{\n"
" if (a)\n" " if (a)\n"
" bar1 ();\n" " bar1 ();\n"
" \n" "\n"
" else\n" " else\n"
" bar2 ();\n" " bar2 ();\n"
"}\n"; "}\n";

View File

@ -1192,8 +1192,7 @@ private:
"{\n" "{\n"
" int y[2];\n" " int y[2];\n"
" int s;\n" " int s;\n"
" GetField( y + 0, \n" " GetField( y + 0, y + 1 );\n"
" y + 1 );\n"
" s = y[0]*y[1];\n" " s = y[0]*y[1];\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());