Fixed #7821 (segmentation fault, invalid last token)
This commit is contained in:
parent
769b6a0b72
commit
5b377ea2e4
|
@ -8027,6 +8027,14 @@ const Token * Tokenizer::findGarbageCode() const
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Code must end with } ; ) NAME
|
||||
if (!Token::Match(list.back(), "%name%|;|}|)"))
|
||||
return list.back();
|
||||
if (list.back()->str() == ")" && !Token::Match(list.back()->link()->previous(), "%name% ("))
|
||||
return list.back();
|
||||
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -158,7 +158,6 @@ private:
|
|||
TEST_CASE(buffer_overrun_16);
|
||||
TEST_CASE(buffer_overrun_18); // ticket #2576 - for, calculation with loop variable
|
||||
TEST_CASE(buffer_overrun_19); // #2597 - class member with unknown type
|
||||
TEST_CASE(buffer_overrun_20); // #2986 (segmentation fault)
|
||||
TEST_CASE(buffer_overrun_21);
|
||||
TEST_CASE(buffer_overrun_24); // index variable is changed in for-loop
|
||||
TEST_CASE(buffer_overrun_26); // #4432 (segmentation fault)
|
||||
|
@ -2413,11 +2412,6 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void buffer_overrun_20() { // #2986(segmentation fault)
|
||||
check("x[y]\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void buffer_overrun_21() {
|
||||
check("void foo()\n"
|
||||
"{ { {\n"
|
||||
|
|
|
@ -2905,41 +2905,38 @@ private:
|
|||
|
||||
|
||||
void uninitVarHeader1() {
|
||||
check("#file \"fred.h\"\n"
|
||||
check("#line 1 \"fred.h\"\n"
|
||||
"class Fred\n"
|
||||
"{\n"
|
||||
"private:\n"
|
||||
" unsigned int i;\n"
|
||||
"public:\n"
|
||||
" Fred();\n"
|
||||
"};\n"
|
||||
"#endfile");
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitVarHeader2() {
|
||||
check("#file \"fred.h\"\n"
|
||||
check("#line 1 \"fred.h\"\n"
|
||||
"class Fred\n"
|
||||
"{\n"
|
||||
"private:\n"
|
||||
" unsigned int i;\n"
|
||||
"public:\n"
|
||||
" Fred() { }\n"
|
||||
"};\n"
|
||||
"#endfile");
|
||||
"};\n");
|
||||
ASSERT_EQUALS("[fred.h:6]: (warning) Member variable 'Fred::i' is not initialized in the constructor.\n", errout.str());
|
||||
}
|
||||
|
||||
void uninitVarHeader3() {
|
||||
check("#file \"fred.h\"\n"
|
||||
check("#line 1 \"fred.h\"\n"
|
||||
"class Fred\n"
|
||||
"{\n"
|
||||
"private:\n"
|
||||
" mutable int i;\n"
|
||||
"public:\n"
|
||||
" Fred() { }\n"
|
||||
"};\n"
|
||||
"#endfile");
|
||||
"};\n");
|
||||
ASSERT_EQUALS("[fred.h:6]: (warning) Member variable 'Fred::i' is not initialized in the constructor.\n", errout.str());
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,6 @@ private:
|
|||
TEST_CASE(garbageCode8); // #5511
|
||||
TEST_CASE(garbageCode9); // #5604
|
||||
TEST_CASE(garbageCode10); // #6127
|
||||
TEST_CASE(garbageCode11);
|
||||
TEST_CASE(garbageCode12);
|
||||
TEST_CASE(garbageCode13); // #2607
|
||||
TEST_CASE(garbageCode14); // #5595
|
||||
|
@ -77,17 +76,14 @@ private:
|
|||
TEST_CASE(garbageCode26);
|
||||
TEST_CASE(garbageCode27);
|
||||
TEST_CASE(garbageCode28);
|
||||
TEST_CASE(garbageCode29);
|
||||
TEST_CASE(garbageCode30); // #5867
|
||||
TEST_CASE(garbageCode31); // #6539
|
||||
TEST_CASE(garbageCode32); // #6135
|
||||
TEST_CASE(garbageCode33); // #6613
|
||||
TEST_CASE(garbageCode34); // #6626
|
||||
TEST_CASE(garbageCode35); // #2599, #2604
|
||||
TEST_CASE(garbageCode36); // #6334
|
||||
TEST_CASE(garbageCode37); // #5166
|
||||
TEST_CASE(garbageCode38); // #6666
|
||||
TEST_CASE(garbageCode39); // #6686
|
||||
TEST_CASE(garbageCode40); // #6620
|
||||
TEST_CASE(garbageCode41); // #6685
|
||||
TEST_CASE(garbageCode42); // #5760
|
||||
|
@ -100,7 +96,6 @@ private:
|
|||
TEST_CASE(garbageCode49); // #6715
|
||||
TEST_CASE(garbageCode50); // #6718
|
||||
TEST_CASE(garbageCode51); // #6719
|
||||
TEST_CASE(garbageCode52); // #6720
|
||||
TEST_CASE(garbageCode53); // #6721
|
||||
TEST_CASE(garbageCode54); // #6722
|
||||
TEST_CASE(garbageCode55); // #6724
|
||||
|
@ -110,12 +105,10 @@ private:
|
|||
TEST_CASE(garbageCode59); // #6735
|
||||
TEST_CASE(garbageCode60); // #6736
|
||||
TEST_CASE(garbageCode61);
|
||||
TEST_CASE(garbageCode62);
|
||||
TEST_CASE(garbageCode63);
|
||||
TEST_CASE(garbageCode64);
|
||||
TEST_CASE(garbageCode65);
|
||||
TEST_CASE(garbageCode66);
|
||||
TEST_CASE(garbageCode67);
|
||||
TEST_CASE(garbageCode68);
|
||||
TEST_CASE(garbageCode69);
|
||||
TEST_CASE(garbageCode70);
|
||||
|
@ -123,7 +116,6 @@ private:
|
|||
TEST_CASE(garbageCode72);
|
||||
TEST_CASE(garbageCode73);
|
||||
TEST_CASE(garbageCode74);
|
||||
TEST_CASE(garbageCode75);
|
||||
TEST_CASE(garbageCode76);
|
||||
TEST_CASE(garbageCode77);
|
||||
TEST_CASE(garbageCode78);
|
||||
|
@ -137,7 +129,6 @@ private:
|
|||
TEST_CASE(garbageCode86);
|
||||
TEST_CASE(garbageCode87);
|
||||
TEST_CASE(garbageCode88);
|
||||
TEST_CASE(garbageCode89);
|
||||
TEST_CASE(garbageCode90);
|
||||
TEST_CASE(garbageCode91);
|
||||
TEST_CASE(garbageCode92);
|
||||
|
@ -172,7 +163,6 @@ private:
|
|||
TEST_CASE(garbageCode121); // #2585
|
||||
TEST_CASE(garbageCode122); // #6303
|
||||
TEST_CASE(garbageCode123);
|
||||
TEST_CASE(garbageCode124); // 6948
|
||||
TEST_CASE(garbageCode125); // 6782, 6834
|
||||
TEST_CASE(garbageCode126); // #6997
|
||||
TEST_CASE(garbageCode127); // #6667
|
||||
|
@ -182,7 +172,6 @@ private:
|
|||
TEST_CASE(garbageCode131); // #7023
|
||||
TEST_CASE(garbageCode132); // #7022
|
||||
TEST_CASE(garbageCode133);
|
||||
TEST_CASE(garbageCode134);
|
||||
TEST_CASE(garbageCode135); // #4994
|
||||
TEST_CASE(garbageCode136); // #7033
|
||||
TEST_CASE(garbageCode137); // #7034
|
||||
|
@ -193,7 +182,6 @@ private:
|
|||
TEST_CASE(garbageCode142); // #7050
|
||||
TEST_CASE(garbageCode143); // #6922
|
||||
TEST_CASE(garbageCode144); // #6865
|
||||
TEST_CASE(garbageCode145); // #7074
|
||||
TEST_CASE(garbageCode146); // #7081
|
||||
TEST_CASE(garbageCode147); // #7082
|
||||
TEST_CASE(garbageCode148); // #7090
|
||||
|
@ -214,7 +202,6 @@ private:
|
|||
TEST_CASE(garbageCode163); // #7228
|
||||
TEST_CASE(garbageCode164); // #7234
|
||||
TEST_CASE(garbageCode165); // #7235
|
||||
TEST_CASE(garbageCode166); // #7236
|
||||
TEST_CASE(garbageCode167); // #7237
|
||||
TEST_CASE(garbageCode168); // #7246
|
||||
TEST_CASE(garbageCode169); // #6731
|
||||
|
@ -226,18 +213,17 @@ private:
|
|||
TEST_CASE(garbageCode175);
|
||||
TEST_CASE(garbageCode176); // #7527
|
||||
TEST_CASE(garbageCode177); // #7321
|
||||
TEST_CASE(garbageCode178); // #3441
|
||||
TEST_CASE(garbageCode179); // #3533
|
||||
TEST_CASE(garbageCode180);
|
||||
TEST_CASE(garbageCode181);
|
||||
TEST_CASE(garbageCode182); // #4195
|
||||
TEST_CASE(garbageCode183); // #7505
|
||||
TEST_CASE(garbageCode184); // #7699
|
||||
TEST_CASE(garbageCode185); // #7769
|
||||
TEST_CASE(garbageValueFlow);
|
||||
TEST_CASE(garbageSymbolDatabase);
|
||||
TEST_CASE(garbageAST);
|
||||
TEST_CASE(templateSimplifierCrashes);
|
||||
TEST_CASE(garbageLastToken); // Make sure syntax errors are detected and reported
|
||||
}
|
||||
|
||||
std::string checkCode(const char code[], bool cpp = true) {
|
||||
|
@ -436,10 +422,6 @@ private:
|
|||
checkCode("for( rl=reslist; rl!=NULL; rl=rl->next )");
|
||||
}
|
||||
|
||||
void garbageCode11() { // do not crash
|
||||
checkCode("( ) &");
|
||||
}
|
||||
|
||||
void garbageCode12() { // do not crash
|
||||
checkCode("{ g; S (void) { struct } { } int &g; }");
|
||||
}
|
||||
|
@ -553,11 +535,6 @@ private:
|
|||
"};\n");
|
||||
}
|
||||
|
||||
void garbageCode29() {
|
||||
// ticket #2601 segmentation fault
|
||||
checkCode("|| #if #define <=");
|
||||
}
|
||||
|
||||
void garbageCode30() {
|
||||
// simply survive - a syntax error would be even better (#5867)
|
||||
checkCode("void f(int x) {\n"
|
||||
|
@ -569,16 +546,8 @@ private:
|
|||
ASSERT_THROW(checkCode("typedef struct{}x[([],)]typedef e y;(y,x 0){}"), InternalError);
|
||||
}
|
||||
|
||||
void garbageCode32() { // #6135
|
||||
checkCode(" ( * const ( size_t ) ; foo )");
|
||||
}
|
||||
|
||||
void garbageCode33() { // #6613
|
||||
checkCode("main(()B{});");
|
||||
|
||||
checkCode("f::y:y : <x::");
|
||||
|
||||
checkCode("\xe2u.");
|
||||
}
|
||||
|
||||
// Bug #6626 crash: Token::astOperand2() const ( do while )
|
||||
|
@ -616,10 +585,6 @@ private:
|
|||
checkCode("{ f2 { } } void f3 () { delete[] } { }");
|
||||
}
|
||||
|
||||
void garbageCode39() { // #6686
|
||||
checkCode("({ (); strcat(strcat(() ()) ()) })");
|
||||
}
|
||||
|
||||
void garbageCode40() { // #6620
|
||||
checkCode("{ ( ) () { virtual } ; { } E } A { : { } ( ) } * const ( ) const { }");
|
||||
// test doesn't seem to work on any platform: ASSERT_THROW(checkCode("{ ( ) () { virtual } ; { } E } A { : { } ( ) } * const ( ) const { }", "test.c"), InternalError);
|
||||
|
@ -669,10 +634,6 @@ private:
|
|||
checkCode(" (const \"C\" ...); struct base { int f2; base (int arg1, int arg2); }; global_base(0x55, 0xff); { ((global_base.f1 0x55) (global_base.f2 0xff)) { } } base::base(int arg1, int arg2) { f2 = }");
|
||||
}
|
||||
|
||||
void garbageCode52() { // #6720
|
||||
checkCode("a \"b\" not_eq \"c\"");
|
||||
}
|
||||
|
||||
void garbageCode53() { // #6721
|
||||
checkCode("{ { } }; void foo (struct int i) { x->b[i] = = }");
|
||||
}
|
||||
|
@ -710,10 +671,6 @@ private:
|
|||
ASSERT_THROW(checkCode("{ (const U&) }; { }; { }; struct U : virtual public"), InternalError);
|
||||
}
|
||||
|
||||
void garbageCode62() { // #6738
|
||||
checkCode("(int arg2) { } { } typedef void (func_type) (int, int); typedef func_type&");
|
||||
}
|
||||
|
||||
void garbageCode63() { // #6739
|
||||
ASSERT_THROW(checkCode("{ } { } typedef int u_array[]; typedef u_array &u_array_ref; (u_array_ref arg) { } u_array_ref u_array_ref_gbl_obj0"), InternalError);
|
||||
}
|
||||
|
@ -730,10 +687,6 @@ private:
|
|||
ASSERT_THROW(checkCode("{ { } }; { { } }; { }; class bar : public virtual"), InternalError);
|
||||
}
|
||||
|
||||
void garbageCode67() { // #6744
|
||||
checkCode("&g[0]; { (g[0] 0) } =", false);
|
||||
}
|
||||
|
||||
void garbageCode68() { // #6745
|
||||
checkCode("(int a[3]); typedef void (*fp) (void); fp");
|
||||
}
|
||||
|
@ -762,10 +715,6 @@ private:
|
|||
checkCode("_lenraw(const char* digits) { } typedef decltype(sizeof(0)) { } operator");
|
||||
}
|
||||
|
||||
void garbageCode75() { // #6753
|
||||
checkCode("{ { void foo() { struct }; { }; } }; struct S { } f =", false);
|
||||
}
|
||||
|
||||
void garbageCode76() { // #6754
|
||||
ASSERT_THROW(checkCode(" ( ) ( ) { ( ) [ ] } TEST ( ) { ( _broadcast_f32x4 ) ( ) ( ) ( ) ( ) if ( ) ( ) ; } E mask = ( ) [ ] ( ) res1.x ="), InternalError);
|
||||
}
|
||||
|
@ -818,10 +767,6 @@ private:
|
|||
ASSERT_THROW(checkCode("( ) { ( 0 ) { ( ) } } g ( ) { i( ( false ?) ( ) : 1 ) ; } ;"), InternalError); // do not crash
|
||||
}
|
||||
|
||||
void garbageCode89() { // #6772
|
||||
checkCode("{ { ( ) } P ( ) ^ { } { } { } ( ) } 0"); // do not crash
|
||||
}
|
||||
|
||||
void garbageCode90() { // #6790
|
||||
ASSERT_THROW(checkCode("{ } { } typedef int u_array [[ ] ; typedef u_array & u_array_ref] ( ) { } u_array_ref_gbl_obj0"), InternalError); // do not crash
|
||||
}
|
||||
|
@ -989,10 +934,6 @@ private:
|
|||
"}"), InternalError);
|
||||
}
|
||||
|
||||
void garbageCode124() {
|
||||
checkCode("+---+");
|
||||
}
|
||||
|
||||
void garbageCode125() {
|
||||
ASSERT_THROW(checkCode("{ T struct B : T valueA_AA ; } T : [ T > ( ) { B } template < T > struct A < > : ] { ( ) { return valueA_AC struct { : } } b A < int > AC ( ) a_aa.M ; ( ) ( ) }"),
|
||||
InternalError);
|
||||
|
@ -1084,7 +1025,6 @@ private:
|
|||
|
||||
void garbageCode134() {
|
||||
// Ticket #5605, #5759, #5762, #5774, #5823, #6059
|
||||
checkCode("template<>\n");
|
||||
checkCode("foo() template<typename T1 = T2 = typename = unused, T5 = = unused> struct tuple Args> tuple<Args...> { } main() { foo<int,int,int,int,int,int>(); }");
|
||||
checkCode("( ) template < T1 = typename = unused> struct Args { } main ( ) { foo < int > ( ) ; }");
|
||||
checkCode("() template < T = typename = x > struct a {} { f <int> () }");
|
||||
|
@ -1178,10 +1118,6 @@ private:
|
|||
//ASSERT_THROW(checkCode("template < typename > struct A { } ; template < typename > struct A < INVALID > : A < int[ > { }] ;"), InternalError);
|
||||
}
|
||||
|
||||
void garbageCode145() { // #7074
|
||||
checkCode("++4++ + + E++++++++++ + ch " "tp.oed5[.]");
|
||||
}
|
||||
|
||||
void garbageCode146() { // #7081
|
||||
ASSERT_THROW(checkCode("void foo() {\n"
|
||||
" ? std::cout << pow((, 1) << std::endl;\n"
|
||||
|
@ -1316,8 +1252,6 @@ private:
|
|||
}
|
||||
|
||||
void garbageAST() {
|
||||
checkCode("--"); // don't crash
|
||||
|
||||
ASSERT_THROW(checkCode("N 1024 float a[N], b[N + 3], c[N]; void N; (void) i;\n"
|
||||
"int #define for (i = avx_test i < c[i]; i++)\n"
|
||||
"b[i + 3] = a[i] * {}"), InternalError); // Don't hang (#5787)
|
||||
|
@ -1402,9 +1336,6 @@ private:
|
|||
checkCode("template<typename T> struct A;\n"
|
||||
"struct B { template<typename T> struct C };\n"
|
||||
"{};"));
|
||||
|
||||
// #4169
|
||||
checkCode("volatile true , test < test < #ifdef __ppc__ true ,");
|
||||
}
|
||||
void garbageCode161() {
|
||||
//7200
|
||||
|
@ -1431,11 +1362,6 @@ private:
|
|||
checkCode("for(;..)", false);
|
||||
}
|
||||
|
||||
void garbageCode166() {
|
||||
//7236
|
||||
checkCode("d a(){f s=0()8[]s?():0}*()?:0", false);
|
||||
}
|
||||
|
||||
void garbageCode167() {
|
||||
//7237
|
||||
checkCode("class D00i000{:D00i000::}i", false);
|
||||
|
@ -1493,10 +1419,6 @@ private:
|
|||
checkCode("{(){(())}}r&const");
|
||||
}
|
||||
|
||||
void garbageCode178() { // #3441
|
||||
checkCode("%: return ; ()");
|
||||
}
|
||||
|
||||
void garbageCode179() { // #3533
|
||||
checkCode("<class T>\n"
|
||||
"{\n"
|
||||
|
@ -1530,11 +1452,39 @@ private:
|
|||
"}");
|
||||
}
|
||||
|
||||
void garbageCode185() { // #7769
|
||||
// that check failed to reproduce the segfault but got added anyway...
|
||||
checkCode("!2 : #h2 ?:", false);
|
||||
}
|
||||
void garbageLastToken() {
|
||||
ASSERT_THROW(checkCode("int *"), InternalError); // #7821
|
||||
ASSERT_THROW(checkCode("x[y]"), InternalError); // #2986
|
||||
ASSERT_THROW(checkCode("( ) &"), InternalError);
|
||||
ASSERT_THROW(checkCode("|| #if #define <="), InternalError); // #2601
|
||||
ASSERT_THROW(checkCode("f::y:y : <x::"), InternalError); // #6613
|
||||
ASSERT_THROW(checkCode("\xe2u."), InternalError); // #6613
|
||||
ASSERT_THROW(checkCode("a \"b\" not_eq \"c\""), InternalError); // #6720
|
||||
ASSERT_THROW(checkCode("(int arg2) { } { } typedef void (func_type) (int, int); typedef func_type&"), InternalError); // #6738
|
||||
ASSERT_THROW(checkCode("&g[0]; { (g[0] 0) } =", false), InternalError); // #6744
|
||||
ASSERT_THROW(checkCode("{ { void foo() { struct }; { }; } }; struct S { } f =", false), InternalError); // #6753
|
||||
ASSERT_THROW(checkCode("{ { ( ) } P ( ) ^ { } { } { } ( ) } 0"), InternalError); // #6772
|
||||
ASSERT_THROW(checkCode("+---+"), InternalError); // #6948
|
||||
ASSERT_THROW(checkCode("template<>\n"), InternalError);
|
||||
ASSERT_THROW(checkCode("++4++ + + E++++++++++ + ch " "tp.oed5[.]"), InternalError); // #7074
|
||||
ASSERT_THROW(checkCode("d a(){f s=0()8[]s?():0}*()?:0", false), InternalError); // #7236
|
||||
ASSERT_THROW(checkCode("!2 : #h2 ?:", false), InternalError); // #7769
|
||||
ASSERT_THROW(checkCode("--"), InternalError);
|
||||
ASSERT_THROW(checkCode("volatile true , test < test < #ifdef __ppc__ true ,"), InternalError); // #4169
|
||||
ASSERT_THROW(checkCode("a,b--\n"), InternalError); // #2847
|
||||
ASSERT_THROW(checkCode("x a[0] ="), InternalError); // #2682
|
||||
ASSERT_THROW(checkCode("auto_ptr<x>\n"), InternalError); // #2967
|
||||
ASSERT_THROW(checkCode("char a[1]\n"), InternalError); // #2865
|
||||
ASSERT_THROW(checkCode("<><<"), InternalError); // #2612
|
||||
ASSERT_THROW(checkCode("z<y<x>"), InternalError); // #2831
|
||||
ASSERT_THROW(checkCode("><,f<i,"), InternalError); // #2835
|
||||
ASSERT_THROW(checkCode("0; (a) < (a)"), InternalError); // #2875
|
||||
ASSERT_THROW(checkCode(" ( * const ( size_t ) ; foo )"), InternalError); // #6135
|
||||
ASSERT_THROW(checkCode("({ (); strcat(strcat(() ()) ()) })"), InternalError); // #6686
|
||||
ASSERT_THROW(checkCode("%: return ; ()"), InternalError); // #3441
|
||||
|
||||
// ASSERT_THROW( , InternalError)
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestGarbage)
|
||||
|
|
|
@ -54,17 +54,11 @@ private:
|
|||
TEST_CASE(testiterator);
|
||||
TEST_CASE(test2168);
|
||||
TEST_CASE(pointer); // #2321 - postincrement of pointer is OK
|
||||
TEST_CASE(testHangWithInvalidCode); // #2847 - cppcheck hangs with 100% cpu load
|
||||
TEST_CASE(testtemplate); // #4686
|
||||
TEST_CASE(testmember);
|
||||
TEST_CASE(testcomma);
|
||||
}
|
||||
|
||||
void testHangWithInvalidCode() {
|
||||
check("a,b--\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void testsimple() {
|
||||
check("int main()\n"
|
||||
"{\n"
|
||||
|
|
|
@ -206,7 +206,6 @@ private:
|
|||
// void foo(void) -> void foo()
|
||||
TEST_CASE(removeVoidFromFunction);
|
||||
|
||||
TEST_CASE(simplifyVarDecl1); // ticket # 2682 segmentation fault
|
||||
TEST_CASE(return_strncat); // ticket # 2860 Returning value of strncat() reported as memory leak
|
||||
|
||||
// #3069 : for loop with 1 iteration
|
||||
|
@ -700,7 +699,7 @@ private:
|
|||
|
||||
// keep parentheses..
|
||||
ASSERT_EQUALS("b = a ;", tok("b = (char)a;"));
|
||||
ASSERT_EQUALS("cast < char * > ( p )", tok("cast<char *>(p)"));
|
||||
ASSERT_EQUALS("cast < char * > ( p ) ;", tok("cast<char *>(p);"));
|
||||
ASSERT_EQUALS("return ( a + b ) * c ;", tok("return (a+b)*c;"));
|
||||
ASSERT_EQUALS("void f ( ) { int p ; if ( 2 * p == 0 ) { } }", tok("void f(){int p; if (2*p == 0) {}}"));
|
||||
ASSERT_EQUALS("void f ( ) { DIR * f ; f = opendir ( dirname ) ; if ( closedir ( f ) ) { } }", tok("void f(){DIR * f = opendir(dirname);if (closedir(f)){}}"));
|
||||
|
@ -793,8 +792,8 @@ private:
|
|||
}
|
||||
|
||||
void elseif1() {
|
||||
const char code[] = "else if(ab) { cd } else { ef }gh";
|
||||
ASSERT_EQUALS("\n\n##file 0\n1: else { if ( ab ) { cd } else { ef } } gh\n", tokenizeDebugListing(code));
|
||||
const char code[] = "else if(ab) { cd } else { ef }gh;";
|
||||
ASSERT_EQUALS("\n\n##file 0\n1: else { if ( ab ) { cd } else { ef } } gh ;\n", tokenizeDebugListing(code));
|
||||
|
||||
// syntax error: assert there is no segmentation fault
|
||||
ASSERT_EQUALS("\n\n##file 0\n1: else if ( x ) { }\n", tokenizeDebugListing("else if (x) { }"));
|
||||
|
@ -831,13 +830,13 @@ private:
|
|||
|
||||
// Ticket #6860 - lambdas
|
||||
{
|
||||
const char src[] = "( []{if (ab) {cd}else if(ef) { gh } else { ij }kl}() )";
|
||||
const char expected[] = "\n\n##file 0\n1: ( [ ] { if ( ab ) { cd } else { if ( ef ) { gh } else { ij } } kl } ( ) )\n";
|
||||
const char src[] = "( []{if (ab) {cd}else if(ef) { gh } else { ij }kl}() );";
|
||||
const char expected[] = "\n\n##file 0\n1: ( [ ] { if ( ab ) { cd } else { if ( ef ) { gh } else { ij } } kl } ( ) ) ;\n";
|
||||
ASSERT_EQUALS(expected, tokenizeDebugListing(src));
|
||||
}
|
||||
{
|
||||
const char src[] = "[ []{if (ab) {cd}else if(ef) { gh } else { ij }kl}() ]";
|
||||
const char expected[] = "\n\n##file 0\n1: [ [ ] { if ( ab ) { cd } else { if ( ef ) { gh } else { ij } } kl } ( ) ]\n";
|
||||
const char src[] = "[ []{if (ab) {cd}else if(ef) { gh } else { ij }kl}() ];";
|
||||
const char expected[] = "\n\n##file 0\n1: [ [ ] { if ( ab ) { cd } else { if ( ef ) { gh } else { ij } } kl } ( ) ] ;\n";
|
||||
ASSERT_EQUALS(expected, tokenizeDebugListing(src));
|
||||
}
|
||||
{
|
||||
|
@ -1005,10 +1004,10 @@ private:
|
|||
// ticket #716 - sizeof string
|
||||
{
|
||||
std::ostringstream expected;
|
||||
expected << "; " << (sizeof "123");
|
||||
expected << "; " << (sizeof "123") << " ;";
|
||||
|
||||
ASSERT_EQUALS(expected.str(), tok("; sizeof \"123\""));
|
||||
ASSERT_EQUALS(expected.str(), tok("; sizeof(\"123\")"));
|
||||
ASSERT_EQUALS(expected.str(), tok("; sizeof \"123\";"));
|
||||
ASSERT_EQUALS(expected.str(), tok("; sizeof(\"123\");"));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -1971,13 +1970,13 @@ private:
|
|||
|
||||
void simplifyConditionOperator() {
|
||||
{
|
||||
const char code[] = "(0?(false?1:2):3)";
|
||||
ASSERT_EQUALS("( 3 )", tok(code));
|
||||
const char code[] = "(0?(false?1:2):3);";
|
||||
ASSERT_EQUALS("( 3 ) ;", tok(code));
|
||||
}
|
||||
|
||||
{
|
||||
const char code[] = "(1?(false?1:2):3)";
|
||||
ASSERT_EQUALS("( 2 )", tok(code));
|
||||
const char code[] = "(1?(false?1:2):3);";
|
||||
ASSERT_EQUALS("( 2 ) ;", tok(code));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -1986,8 +1985,8 @@ private:
|
|||
}
|
||||
|
||||
{
|
||||
const char code[] = "(1?0:foo())";
|
||||
ASSERT_EQUALS("( 0 )", tok(code));
|
||||
const char code[] = "(1?0:foo());";
|
||||
ASSERT_EQUALS("( 0 ) ;", tok(code));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -2006,13 +2005,13 @@ private:
|
|||
}
|
||||
|
||||
{
|
||||
const char code[] = "( true ? a ( ) : b ( ) )";
|
||||
ASSERT_EQUALS("( a ( ) )", tok(code));
|
||||
const char code[] = "( true ? a ( ) : b ( ) );";
|
||||
ASSERT_EQUALS("( a ( ) ) ;", tok(code));
|
||||
}
|
||||
|
||||
{
|
||||
const char code[] = "( true ? abc . a : abc . b )";
|
||||
ASSERT_EQUALS("( abc . a )", tok(code));
|
||||
const char code[] = "( true ? abc . a : abc . b );";
|
||||
ASSERT_EQUALS("( abc . a ) ;", tok(code));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -2060,28 +2059,28 @@ private:
|
|||
|
||||
void calculations() {
|
||||
{
|
||||
const char code[] = "a[i+8+2]";
|
||||
ASSERT_EQUALS("a [ i + 10 ]", tok(code));
|
||||
const char code[] = "a[i+8+2];";
|
||||
ASSERT_EQUALS("a [ i + 10 ] ;", tok(code));
|
||||
}
|
||||
{
|
||||
const char code[] = "a[8+2+i]";
|
||||
ASSERT_EQUALS("a [ 10 + i ]", tok(code));
|
||||
const char code[] = "a[8+2+i];";
|
||||
ASSERT_EQUALS("a [ 10 + i ] ;", tok(code));
|
||||
}
|
||||
{
|
||||
const char code[] = "a[i + 2 * (2 * 4)]";
|
||||
ASSERT_EQUALS("a [ i + 16 ]", tok(code));
|
||||
const char code[] = "a[i + 2 * (2 * 4)];";
|
||||
ASSERT_EQUALS("a [ i + 16 ] ;", tok(code));
|
||||
}
|
||||
{
|
||||
const char code[] = "a[i + 100 - 90]";
|
||||
ASSERT_EQUALS("a [ i + 10 ]", tok(code));
|
||||
const char code[] = "a[i + 100 - 90];";
|
||||
ASSERT_EQUALS("a [ i + 10 ] ;", tok(code));
|
||||
}
|
||||
{
|
||||
const char code[] = "a[1+1+1+1+1+1+1+1+1+1-2+5-3]";
|
||||
ASSERT_EQUALS("a [ 10 ]", tok(code));
|
||||
const char code[] = "a[1+1+1+1+1+1+1+1+1+1-2+5-3];";
|
||||
ASSERT_EQUALS("a [ 10 ] ;", tok(code));
|
||||
}
|
||||
{
|
||||
const char code[] = "a[10+10-10-10]";
|
||||
ASSERT_EQUALS("a [ 0 ]", tok(code));
|
||||
const char code[] = "a[10+10-10-10];";
|
||||
ASSERT_EQUALS("a [ 0 ] ;", tok(code));
|
||||
}
|
||||
|
||||
ASSERT_EQUALS("a [ 4 ] ;", tok("a[1+3|4];"));
|
||||
|
@ -2114,30 +2113,30 @@ private:
|
|||
ASSERT_EQUALS("if ( a + 2 != 6 ) { ; }", tok("if (a+1+1!=1+2+3);"));
|
||||
ASSERT_EQUALS("if ( 4 < a ) { ; }", tok("if (14-2*5<a*4/(2*2));"));
|
||||
|
||||
ASSERT_EQUALS("( y / 2 - 2 )", tok("(y / 2 - 2)"));
|
||||
ASSERT_EQUALS("( y % 2 - 2 )", tok("(y % 2 - 2)"));
|
||||
ASSERT_EQUALS("( y / 2 - 2 ) ;", tok("(y / 2 - 2);"));
|
||||
ASSERT_EQUALS("( y % 2 - 2 ) ;", tok("(y % 2 - 2);"));
|
||||
|
||||
ASSERT_EQUALS("( 4 )", tok("(1 * 2 / 1 * 2)")); // #3722
|
||||
ASSERT_EQUALS("( 4 ) ;", tok("(1 * 2 / 1 * 2);")); // #3722
|
||||
|
||||
ASSERT_EQUALS("x ( 60129542144 )", tok("x(14<<4+17<<300%17)")); // #4931
|
||||
ASSERT_EQUALS("x ( 1 )", tok("x(8|5&6+0 && 7)")); // #6104
|
||||
ASSERT_EQUALS("x ( 1 )", tok("x(2 && 4<<4<<5 && 4)")); // #4933
|
||||
ASSERT_EQUALS("x ( 1 )", tok("x(9&&8%5%4/3)")); // #4931
|
||||
ASSERT_EQUALS("x ( 1 )", tok("x(2 && 2|5<<2%4)")); // #4931
|
||||
ASSERT_EQUALS("x ( -2 << 6 | 1 )", tok("x(1-3<<6|5/3)")); // #4931
|
||||
ASSERT_EQUALS("x ( 2 )", tok("x(2|0*0&2>>1+0%2*1)")); // #4931
|
||||
ASSERT_EQUALS("x ( 0 & 4 != 1 )", tok("x(4%1<<1&4!=1)")); // #4931 (can be simplified further but it's not a problem)
|
||||
ASSERT_EQUALS("x ( true )", tok("x(0&&4>0==2||4)")); // #4931
|
||||
ASSERT_EQUALS("x ( 60129542144 ) ;", tok("x(14<<4+17<<300%17);")); // #4931
|
||||
ASSERT_EQUALS("x ( 1 ) ;", tok("x(8|5&6+0 && 7);")); // #6104
|
||||
ASSERT_EQUALS("x ( 1 ) ;", tok("x(2 && 4<<4<<5 && 4);")); // #4933
|
||||
ASSERT_EQUALS("x ( 1 ) ;", tok("x(9&&8%5%4/3);")); // #4931
|
||||
ASSERT_EQUALS("x ( 1 ) ;", tok("x(2 && 2|5<<2%4);")); // #4931
|
||||
ASSERT_EQUALS("x ( -2 << 6 | 1 ) ;", tok("x(1-3<<6|5/3);")); // #4931
|
||||
ASSERT_EQUALS("x ( 2 ) ;", tok("x(2|0*0&2>>1+0%2*1);")); // #4931
|
||||
ASSERT_EQUALS("x ( 0 & 4 != 1 ) ;", tok("x(4%1<<1&4!=1);")); // #4931 (can be simplified further but it's not a problem)
|
||||
ASSERT_EQUALS("x ( true ) ;", tok("x(0&&4>0==2||4);")); // #4931
|
||||
|
||||
// don't remove these spaces..
|
||||
ASSERT_EQUALS("new ( auto ) ( 4 ) ;", tok("new (auto)(4);"));
|
||||
}
|
||||
|
||||
void comparisons() {
|
||||
ASSERT_EQUALS("( 1 )", tok("( 1 < 2 )"));
|
||||
ASSERT_EQUALS("( x && true )", tok("( x && 1 < 2 )"));
|
||||
ASSERT_EQUALS("( 5 )", tok("( 1 < 2 && 3 < 4 ? 5 : 6 )"));
|
||||
ASSERT_EQUALS("( 6 )", tok("( 1 > 2 && 3 > 4 ? 5 : 6 )"));
|
||||
ASSERT_EQUALS("( 1 ) ;", tok("( 1 < 2 );"));
|
||||
ASSERT_EQUALS("( x && true ) ;", tok("( x && 1 < 2 );"));
|
||||
ASSERT_EQUALS("( 5 ) ;", tok("( 1 < 2 && 3 < 4 ? 5 : 6 );"));
|
||||
ASSERT_EQUALS("( 6 ) ;", tok("( 1 > 2 && 3 > 4 ? 5 : 6 );"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -3332,12 +3331,6 @@ private:
|
|||
ASSERT_EQUALS("void foo ( ) ;", tok("void foo(void);"));
|
||||
}
|
||||
|
||||
void simplifyVarDecl1() { // ticket # 2682 segmentation fault
|
||||
const char code[] = "x a[0] =";
|
||||
tok(code, false);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void return_strncat() {
|
||||
{
|
||||
const char code[] = "char *f()\n"
|
||||
|
|
|
@ -2509,10 +2509,6 @@ private:
|
|||
check("A::A(std::auto_ptr<X> e){}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// ticket #2967 (segmentation fault)
|
||||
check("auto_ptr<x>\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// ticket #4390
|
||||
check("auto_ptr<ConnectionStringReadStorage> CreateRegistryStringStorage() {\n"
|
||||
" return auto_ptr<ConnectionStringReadStorage>(new RegistryConnectionStringStorage());\n"
|
||||
|
|
|
@ -217,7 +217,6 @@ private:
|
|||
TEST_CASE(symboldatabase15); // ticket #2591
|
||||
TEST_CASE(symboldatabase16); // ticket #2637
|
||||
TEST_CASE(symboldatabase17); // ticket #2657
|
||||
TEST_CASE(symboldatabase18); // ticket #2865
|
||||
TEST_CASE(symboldatabase19); // ticket #2991 (segmentation fault)
|
||||
TEST_CASE(symboldatabase20); // ticket #3013 (segmentation fault)
|
||||
TEST_CASE(symboldatabase21);
|
||||
|
@ -2184,13 +2183,6 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void symboldatabase18() {
|
||||
// ticket #2865 - segmentation fault
|
||||
check("char a[1]\n");
|
||||
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void symboldatabase19() {
|
||||
// ticket #2991 - segmentation fault
|
||||
check("::y(){x}");
|
||||
|
@ -3902,54 +3894,54 @@ private:
|
|||
s.long_long_bit = 64;
|
||||
|
||||
// numbers
|
||||
ASSERT_EQUALS("signed int", typeOf("1", "1", "test.c", &s));
|
||||
ASSERT_EQUALS("signed int", typeOf("32767", "32767", "test.c", &s));
|
||||
ASSERT_EQUALS("signed long", typeOf("32768", "32768", "test.c", &s));
|
||||
ASSERT_EQUALS("signed long long", typeOf("2147483648", "2147483648", "test.c", &s));
|
||||
ASSERT_EQUALS("unsigned int", typeOf("1U", "1U"));
|
||||
ASSERT_EQUALS("signed long", typeOf("1L", "1L"));
|
||||
ASSERT_EQUALS("unsigned long", typeOf("1UL", "1UL"));
|
||||
ASSERT_EQUALS("signed long long", typeOf("1LL", "1LL"));
|
||||
ASSERT_EQUALS("unsigned long long", typeOf("1ULL", "1ULL"));
|
||||
ASSERT_EQUALS("unsigned long long", typeOf("1LLU", "1LLU"));
|
||||
ASSERT_EQUALS("signed long long", typeOf("1i64", "1i64"));
|
||||
ASSERT_EQUALS("unsigned long long", typeOf("1ui64", "1ui64"));
|
||||
ASSERT_EQUALS("unsigned int", typeOf("1u", "1u"));
|
||||
ASSERT_EQUALS("signed long", typeOf("1l", "1l"));
|
||||
ASSERT_EQUALS("unsigned long", typeOf("1ul", "1ul"));
|
||||
ASSERT_EQUALS("signed long long", typeOf("1ll", "1ll"));
|
||||
ASSERT_EQUALS("unsigned long long", typeOf("1ull", "1ull"));
|
||||
ASSERT_EQUALS("unsigned long long", typeOf("1llu", "1llu"));
|
||||
ASSERT_EQUALS("float", typeOf("1.0F", "1.0F"));
|
||||
ASSERT_EQUALS("float", typeOf("1.0f", "1.0f"));
|
||||
ASSERT_EQUALS("double", typeOf("1.0", "1.0"));
|
||||
ASSERT_EQUALS("double", typeOf("1E3", "1E3"));
|
||||
ASSERT_EQUALS("long double", typeOf("1.23L", "1.23L"));
|
||||
ASSERT_EQUALS("signed int", typeOf("1;", "1", "test.c", &s));
|
||||
ASSERT_EQUALS("signed int", typeOf("32767;", "32767", "test.c", &s));
|
||||
ASSERT_EQUALS("signed long", typeOf("32768;", "32768", "test.c", &s));
|
||||
ASSERT_EQUALS("signed long long", typeOf("2147483648;", "2147483648", "test.c", &s));
|
||||
ASSERT_EQUALS("unsigned int", typeOf("1U;", "1U"));
|
||||
ASSERT_EQUALS("signed long", typeOf("1L;", "1L"));
|
||||
ASSERT_EQUALS("unsigned long", typeOf("1UL;", "1UL"));
|
||||
ASSERT_EQUALS("signed long long", typeOf("1LL;", "1LL"));
|
||||
ASSERT_EQUALS("unsigned long long", typeOf("1ULL;", "1ULL"));
|
||||
ASSERT_EQUALS("unsigned long long", typeOf("1LLU;", "1LLU"));
|
||||
ASSERT_EQUALS("signed long long", typeOf("1i64;", "1i64"));
|
||||
ASSERT_EQUALS("unsigned long long", typeOf("1ui64;", "1ui64"));
|
||||
ASSERT_EQUALS("unsigned int", typeOf("1u;", "1u"));
|
||||
ASSERT_EQUALS("signed long", typeOf("1l;", "1l"));
|
||||
ASSERT_EQUALS("unsigned long", typeOf("1ul;", "1ul"));
|
||||
ASSERT_EQUALS("signed long long", typeOf("1ll;", "1ll"));
|
||||
ASSERT_EQUALS("unsigned long long", typeOf("1ull;", "1ull"));
|
||||
ASSERT_EQUALS("unsigned long long", typeOf("1llu;", "1llu"));
|
||||
ASSERT_EQUALS("float", typeOf("1.0F;", "1.0F"));
|
||||
ASSERT_EQUALS("float", typeOf("1.0f;", "1.0f"));
|
||||
ASSERT_EQUALS("double", typeOf("1.0;", "1.0"));
|
||||
ASSERT_EQUALS("double", typeOf("1E3;", "1E3"));
|
||||
ASSERT_EQUALS("long double", typeOf("1.23L;", "1.23L"));
|
||||
|
||||
// Constant calculations
|
||||
ASSERT_EQUALS("signed int", typeOf("1 + 2", "+"));
|
||||
ASSERT_EQUALS("signed long", typeOf("1L + 2", "+"));
|
||||
ASSERT_EQUALS("signed long long", typeOf("1LL + 2", "+"));
|
||||
ASSERT_EQUALS("float", typeOf("1.2f + 3", "+"));
|
||||
ASSERT_EQUALS("float", typeOf("1 + 2.3f", "+"));
|
||||
ASSERT_EQUALS("signed int", typeOf("1 + 2;", "+"));
|
||||
ASSERT_EQUALS("signed long", typeOf("1L + 2;", "+"));
|
||||
ASSERT_EQUALS("signed long long", typeOf("1LL + 2;", "+"));
|
||||
ASSERT_EQUALS("float", typeOf("1.2f + 3;", "+"));
|
||||
ASSERT_EQUALS("float", typeOf("1 + 2.3f;", "+"));
|
||||
|
||||
// promotions
|
||||
ASSERT_EQUALS("signed int", typeOf("(char)1 + (char)2", "+"));
|
||||
ASSERT_EQUALS("signed int", typeOf("(short)1 + (short)2", "+"));
|
||||
ASSERT_EQUALS("signed int", typeOf("(signed int)1 + (signed char)2", "+"));
|
||||
ASSERT_EQUALS("signed int", typeOf("(signed int)1 + (unsigned char)2", "+"));
|
||||
ASSERT_EQUALS("unsigned int", typeOf("(unsigned int)1 + (signed char)2", "+"));
|
||||
ASSERT_EQUALS("unsigned int", typeOf("(unsigned int)1 + (unsigned char)2", "+"));
|
||||
ASSERT_EQUALS("unsigned int", typeOf("(unsigned int)1 + (signed int)2", "+"));
|
||||
ASSERT_EQUALS("unsigned int", typeOf("(unsigned int)1 + (unsigned int)2", "+"));
|
||||
ASSERT_EQUALS("signed long", typeOf("(signed long)1 + (unsigned int)2", "+"));
|
||||
ASSERT_EQUALS("unsigned long", typeOf("(unsigned long)1 + (signed int)2", "+"));
|
||||
ASSERT_EQUALS("signed int", typeOf("(char)1 + (char)2;", "+"));
|
||||
ASSERT_EQUALS("signed int", typeOf("(short)1 + (short)2;", "+"));
|
||||
ASSERT_EQUALS("signed int", typeOf("(signed int)1 + (signed char)2;", "+"));
|
||||
ASSERT_EQUALS("signed int", typeOf("(signed int)1 + (unsigned char)2;", "+"));
|
||||
ASSERT_EQUALS("unsigned int", typeOf("(unsigned int)1 + (signed char)2;", "+"));
|
||||
ASSERT_EQUALS("unsigned int", typeOf("(unsigned int)1 + (unsigned char)2;", "+"));
|
||||
ASSERT_EQUALS("unsigned int", typeOf("(unsigned int)1 + (signed int)2;", "+"));
|
||||
ASSERT_EQUALS("unsigned int", typeOf("(unsigned int)1 + (unsigned int)2;", "+"));
|
||||
ASSERT_EQUALS("signed long", typeOf("(signed long)1 + (unsigned int)2;", "+"));
|
||||
ASSERT_EQUALS("unsigned long", typeOf("(unsigned long)1 + (signed int)2;", "+"));
|
||||
|
||||
// char *
|
||||
ASSERT_EQUALS("const char *", typeOf("\"hello\" + 1", "+"));
|
||||
ASSERT_EQUALS("const char", typeOf("\"hello\"[1]", "["));
|
||||
ASSERT_EQUALS("const char", typeOf("*\"hello\"", "*"));
|
||||
ASSERT_EQUALS("const short *", typeOf("L\"hello\" + 1", "+"));
|
||||
ASSERT_EQUALS("const char *", typeOf("\"hello\" + 1;", "+"));
|
||||
ASSERT_EQUALS("const char", typeOf("\"hello\"[1];", "["));
|
||||
ASSERT_EQUALS("const char", typeOf("*\"hello\";", "*"));
|
||||
ASSERT_EQUALS("const short *", typeOf("L\"hello\" + 1;", "+"));
|
||||
|
||||
// Variable calculations
|
||||
ASSERT_EQUALS("void *", typeOf("void *p; a = p + 1;", "+"));
|
||||
|
@ -3983,11 +3975,11 @@ private:
|
|||
ASSERT_EQUALS("double", typeOf("double x; a = -x;", "-"));
|
||||
|
||||
// Ternary operator
|
||||
ASSERT_EQUALS("signed int", typeOf("int x; a = (b ? x : x)", "?"));
|
||||
ASSERT_EQUALS("", typeOf("int x; a = (b ? x : y)", "?"));
|
||||
ASSERT_EQUALS("double", typeOf("int x; double y; a = (b ? x : y)", "?"));
|
||||
ASSERT_EQUALS("const char *", typeOf("int x; double y; a = (b ? \"a\" : \"b\")", "?"));
|
||||
ASSERT_EQUALS("", typeOf("int x; double y; a = (b ? \"a\" : std::string(\"b\"))", "?"));
|
||||
ASSERT_EQUALS("signed int", typeOf("int x; a = (b ? x : x);", "?"));
|
||||
ASSERT_EQUALS("", typeOf("int x; a = (b ? x : y);", "?"));
|
||||
ASSERT_EQUALS("double", typeOf("int x; double y; a = (b ? x : y);", "?"));
|
||||
ASSERT_EQUALS("const char *", typeOf("int x; double y; a = (b ? \"a\" : \"b\");", "?"));
|
||||
ASSERT_EQUALS("", typeOf("int x; double y; a = (b ? \"a\" : std::string(\"b\"));", "?"));
|
||||
|
||||
// Boolean operators
|
||||
ASSERT_EQUALS("bool", typeOf("a > b;", ">"));
|
||||
|
@ -4023,7 +4015,7 @@ private:
|
|||
ASSERT_EQUALS("", typeOf("a = (unsigned x)0;", "("));
|
||||
|
||||
// sizeof..
|
||||
ASSERT_EQUALS("char", typeOf("sizeof(char)", "char"));
|
||||
ASSERT_EQUALS("char", typeOf("sizeof(char);", "char"));
|
||||
|
||||
// const..
|
||||
ASSERT_EQUALS("const char *", typeOf("a = \"123\";", "\"123\""));
|
||||
|
|
|
@ -118,7 +118,7 @@ private:
|
|||
bool Match(const std::string &code, const std::string &pattern, unsigned int varid=0) {
|
||||
static const Settings settings;
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(code);
|
||||
std::istringstream istr(code + ";");
|
||||
try {
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
} catch (...) {}
|
||||
|
@ -512,24 +512,24 @@ private:
|
|||
}
|
||||
|
||||
void matchOr() const {
|
||||
givenACodeSampleToTokenize bitwiseOr("|", true);
|
||||
givenACodeSampleToTokenize bitwiseOr("|;", true);
|
||||
ASSERT_EQUALS(true, Token::Match(bitwiseOr.tokens(), "%or%"));
|
||||
ASSERT_EQUALS(true, Token::Match(bitwiseOr.tokens(), "%op%"));
|
||||
ASSERT_EQUALS(false, Token::Match(bitwiseOr.tokens(), "%oror%"));
|
||||
|
||||
givenACodeSampleToTokenize bitwiseOrAssignment("|=");
|
||||
givenACodeSampleToTokenize bitwiseOrAssignment("|=;");
|
||||
ASSERT_EQUALS(false, Token::Match(bitwiseOrAssignment.tokens(), "%or%"));
|
||||
ASSERT_EQUALS(true, Token::Match(bitwiseOrAssignment.tokens(), "%op%"));
|
||||
ASSERT_EQUALS(false, Token::Match(bitwiseOrAssignment.tokens(), "%oror%"));
|
||||
|
||||
givenACodeSampleToTokenize logicalOr("||", true);
|
||||
givenACodeSampleToTokenize logicalOr("||;", true);
|
||||
ASSERT_EQUALS(false, Token::Match(logicalOr.tokens(), "%or%"));
|
||||
ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "%op%"));
|
||||
ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "%oror%"));
|
||||
ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "&&|%oror%"));
|
||||
ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "%oror%|&&"));
|
||||
|
||||
givenACodeSampleToTokenize logicalAnd("&&", true);
|
||||
givenACodeSampleToTokenize logicalAnd("&&;", true);
|
||||
ASSERT_EQUALS(true, Token::simpleMatch(logicalAnd.tokens(), "&&"));
|
||||
ASSERT_EQUALS(true, Token::Match(logicalAnd.tokens(), "&&|%oror%"));
|
||||
ASSERT_EQUALS(true, Token::Match(logicalAnd.tokens(), "%oror%|&&"));
|
||||
|
|
|
@ -52,7 +52,6 @@ private:
|
|||
TEST_CASE(tokenize13); // bailout if the code contains "@" - that is not handled well.
|
||||
TEST_CASE(tokenize14); // tokenize "0X10" => 16
|
||||
TEST_CASE(tokenize15); // tokenize ".123"
|
||||
TEST_CASE(tokenize16); // #2612 - segfault for "<><<"
|
||||
TEST_CASE(tokenize17); // #2759
|
||||
TEST_CASE(tokenize18); // tokenize "(X&&Y)" into "( X && Y )" instead of "( X & & Y )"
|
||||
TEST_CASE(tokenize19); // #3006 (segmentation fault)
|
||||
|
@ -340,7 +339,6 @@ private:
|
|||
TEST_CASE(bitfields8);
|
||||
TEST_CASE(bitfields9); // ticket #2706
|
||||
TEST_CASE(bitfields10);
|
||||
TEST_CASE(bitfields11); // ticket #2845 (segmentation fault)
|
||||
TEST_CASE(bitfields12); // ticket #3485 (segmentation fault)
|
||||
TEST_CASE(bitfields13); // ticket #3502 (segmentation fault)
|
||||
TEST_CASE(bitfields14); // ticket #4561 (segfault for 'class a { signals: };')
|
||||
|
@ -675,13 +673,8 @@ private:
|
|||
|
||||
// Ticket #2429: 0.125
|
||||
void tokenize15() {
|
||||
ASSERT_EQUALS("0.125", tokenizeAndStringify(".125"));
|
||||
ASSERT_EQUALS("005.125", tokenizeAndStringify("005.125")); // Don't confuse with octal values
|
||||
}
|
||||
|
||||
// #2612 - segfault for "<><<"
|
||||
void tokenize16() {
|
||||
tokenizeAndStringify("<><<");
|
||||
ASSERT_EQUALS("0.125 ;", tokenizeAndStringify(".125;"));
|
||||
ASSERT_EQUALS("005.125 ;", tokenizeAndStringify("005.125;")); // Don't confuse with octal values
|
||||
}
|
||||
|
||||
void tokenize17() { // #2759
|
||||
|
@ -689,7 +682,7 @@ private:
|
|||
}
|
||||
|
||||
void tokenize18() { // tokenize "(X&&Y)" into "( X && Y )" instead of "( X & & Y )"
|
||||
ASSERT_EQUALS("( X && Y )", tokenizeAndStringify("(X&&Y)"));
|
||||
ASSERT_EQUALS("( X && Y ) ;", tokenizeAndStringify("(X&&Y);"));
|
||||
}
|
||||
|
||||
void tokenize19() {
|
||||
|
@ -722,7 +715,7 @@ private:
|
|||
}
|
||||
|
||||
void tokenize21() { // tokenize 0x0E-7
|
||||
ASSERT_EQUALS("14 - 7", tokenizeAndStringify("0x0E-7"));
|
||||
ASSERT_EQUALS("14 - 7 ;", tokenizeAndStringify("0x0E-7;"));
|
||||
}
|
||||
|
||||
void tokenize22() { // tokenize special marker $ from preprocessor
|
||||
|
@ -834,17 +827,17 @@ private:
|
|||
}
|
||||
|
||||
void combineOperators() {
|
||||
ASSERT_EQUALS("; private:", tokenizeAndStringify(";private:", false));
|
||||
ASSERT_EQUALS("; protected:", tokenizeAndStringify(";protected:", false));
|
||||
ASSERT_EQUALS("; public:", tokenizeAndStringify(";public:", false));
|
||||
ASSERT_EQUALS("; __published:", tokenizeAndStringify(";__published:", false));
|
||||
ASSERT_EQUALS("a . public :", tokenizeAndStringify("a.public:", false));
|
||||
ASSERT_EQUALS("; private: ;", tokenizeAndStringify(";private:;", false));
|
||||
ASSERT_EQUALS("; protected: ;", tokenizeAndStringify(";protected:;", false));
|
||||
ASSERT_EQUALS("; public: ;", tokenizeAndStringify(";public:;", false));
|
||||
ASSERT_EQUALS("; __published: ;", tokenizeAndStringify(";__published:;", false));
|
||||
ASSERT_EQUALS("a . public : ;", tokenizeAndStringify("a.public:;", false));
|
||||
}
|
||||
|
||||
void concatenateNegativeNumber() {
|
||||
ASSERT_EQUALS("i = -12", tokenizeAndStringify("i = -12"));
|
||||
ASSERT_EQUALS("1 - 2", tokenizeAndStringify("1-2"));
|
||||
ASSERT_EQUALS("foo ( -1 ) - 2", tokenizeAndStringify("foo(-1)-2"));
|
||||
ASSERT_EQUALS("i = -12 ;", tokenizeAndStringify("i = -12;"));
|
||||
ASSERT_EQUALS("1 - 2 ;", tokenizeAndStringify("1-2;"));
|
||||
ASSERT_EQUALS("foo ( -1 ) - 2 ;", tokenizeAndStringify("foo(-1)-2;"));
|
||||
ASSERT_EQUALS("int f ( ) { return -2 ; }", tokenizeAndStringify("int f(){return -2;}"));
|
||||
ASSERT_EQUALS("int x [ 2 ] = { -2 , 1 }", tokenizeAndStringify("int x[2] = {-2,1}"));
|
||||
|
||||
|
@ -938,7 +931,7 @@ private:
|
|||
|
||||
void simplifyCasts14() { // const
|
||||
// #5081
|
||||
ASSERT_EQUALS("( ! ( & s ) . a )", tokenizeAndStringify("(! ( (struct S const *) &s)->a)", true));
|
||||
ASSERT_EQUALS("( ! ( & s ) . a ) ;", tokenizeAndStringify("(! ( (struct S const *) &s)->a);", true));
|
||||
// #5244
|
||||
ASSERT_EQUALS("bar ( & ptr ) ;", tokenizeAndStringify("bar((const X**)&ptr);",true));
|
||||
}
|
||||
|
@ -2947,7 +2940,7 @@ private:
|
|||
|
||||
void file3() {
|
||||
const char code[] = "#file \"c:\\a.h\"\n"
|
||||
"123\n"
|
||||
"123 ;\n"
|
||||
"#endfile\n";
|
||||
|
||||
errout.str("");
|
||||
|
@ -3132,8 +3125,8 @@ private:
|
|||
// "!(abc.a)" => "!abc.a"
|
||||
void removeParentheses6() {
|
||||
{
|
||||
const char code[] = "(!(abc.a))";
|
||||
ASSERT_EQUALS("( ! abc . a )", tokenizeAndStringify(code));
|
||||
const char code[] = "(!(abc.a));";
|
||||
ASSERT_EQUALS("( ! abc . a ) ;", tokenizeAndStringify(code));
|
||||
}
|
||||
//handle more complex member selections
|
||||
{
|
||||
|
@ -3211,7 +3204,7 @@ private:
|
|||
}
|
||||
|
||||
void removeParentheses19() {
|
||||
ASSERT_EQUALS("( ( ( typeof ( X ) ) * ) 0 )", tokenizeAndStringify("(((typeof(X))*)0)", false));
|
||||
ASSERT_EQUALS("( ( ( typeof ( X ) ) * ) 0 ) ;", tokenizeAndStringify("(((typeof(X))*)0);", false));
|
||||
}
|
||||
|
||||
void removeParentheses20() {
|
||||
|
@ -4468,7 +4461,7 @@ private:
|
|||
}
|
||||
|
||||
{
|
||||
const char code[] = "Data<T&&>";
|
||||
const char code[] = "Data<T&&>;";
|
||||
errout.str("");
|
||||
Tokenizer tokenizer(&settings0, this);
|
||||
std::istringstream istr(code);
|
||||
|
@ -5342,13 +5335,6 @@ private:
|
|||
ASSERT_EQUALS("{ } MACRO default : { } ;", tokenizeAndStringify(code,false));
|
||||
}
|
||||
|
||||
void bitfields11() { // ticket #2845 (segmentation fault)
|
||||
const char code[] = "#if b&&a\n"
|
||||
"#ifdef y z:\n";
|
||||
tokenizeAndStringify(code,false);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void bitfields12() { // ticket #3485 (segmentation fault)
|
||||
const char code[] = "{a:1;};\n";
|
||||
ASSERT_EQUALS("{ } ;", tokenizeAndStringify(code,false));
|
||||
|
@ -5690,10 +5676,10 @@ private:
|
|||
tokenizeAndStringify("int foo ( ) { int i; int j; i = 0 && j; return i; }", true)); // ticket #3576 - False positives in boolean expressions
|
||||
|
||||
// ticket #3723 - Simplify condition (0 && a < 123)
|
||||
ASSERT_EQUALS("( 0 )",
|
||||
tokenizeAndStringify("( 0 && a < 123 )", true));
|
||||
ASSERT_EQUALS("( 0 )",
|
||||
tokenizeAndStringify("( 0 && a[123] )", true));
|
||||
ASSERT_EQUALS("( 0 ) ;",
|
||||
tokenizeAndStringify("( 0 && a < 123 );", true));
|
||||
ASSERT_EQUALS("( 0 ) ;",
|
||||
tokenizeAndStringify("( 0 && a[123] );", true));
|
||||
|
||||
// ticket #3964 - simplify numeric calculations in tokenization
|
||||
ASSERT_EQUALS("char a [ 10 ] ;", tokenizeAndStringify("char a[9+1];"));
|
||||
|
|
|
@ -281,12 +281,12 @@ private:
|
|||
ASSERT_EQUALS(0, valueOfTok("3 <= (a ? b : 2);", "<=").intvalue);
|
||||
|
||||
// Don't calculate if there is UB
|
||||
ASSERT(tokenValues("-1<<10","<<").empty());
|
||||
ASSERT(tokenValues("10<<-1","<<").empty());
|
||||
ASSERT(tokenValues("10<<64","<<").empty());
|
||||
ASSERT(tokenValues("-1>>10",">>").empty());
|
||||
ASSERT(tokenValues("10>>-1",">>").empty());
|
||||
ASSERT(tokenValues("10>>64",">>").empty());
|
||||
ASSERT(tokenValues("-1<<10;","<<").empty());
|
||||
ASSERT(tokenValues("10<<-1;","<<").empty());
|
||||
ASSERT(tokenValues("10<<64;","<<").empty());
|
||||
ASSERT(tokenValues("-1>>10;",">>").empty());
|
||||
ASSERT(tokenValues("10>>-1;",">>").empty());
|
||||
ASSERT(tokenValues("10>>64;",">>").empty());
|
||||
|
||||
// calculation using 1,2 variables/values
|
||||
code = "void f(int x) {\n"
|
||||
|
@ -2035,7 +2035,7 @@ private:
|
|||
|
||||
// function
|
||||
code = "int f(int x) { return x + 1; }\n" // <- possible value
|
||||
"void a() { f(12); }\b";
|
||||
"void a() { f(12); }";
|
||||
value = valueOfTok(code, "+");
|
||||
ASSERT_EQUALS(13, value.intvalue);
|
||||
ASSERT(value.isPossible());
|
||||
|
|
|
@ -58,9 +58,6 @@ private:
|
|||
TEST_CASE(varid28); // ticket #2630
|
||||
TEST_CASE(varid29); // ticket #1974
|
||||
TEST_CASE(varid30); // ticket #2614
|
||||
TEST_CASE(varid31); // ticket #2831 (segmentation fault)
|
||||
TEST_CASE(varid32); // ticket #2835 (segmentation fault)
|
||||
TEST_CASE(varid33); // ticket #2875 (segmentation fault)
|
||||
TEST_CASE(varid34); // ticket #2825
|
||||
TEST_CASE(varid35); // function declaration inside function body
|
||||
TEST_CASE(varid36); // ticket #2980 (segmentation fault)
|
||||
|
@ -699,24 +696,6 @@ private:
|
|||
ASSERT_EQUALS(expected3, tokenize(code3));
|
||||
}
|
||||
|
||||
void varid31() { // ticket #2831 (segmentation fault)
|
||||
const char code[] ="z<y<x>";
|
||||
tokenize(code);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void varid32() { // ticket #2835 (segmentation fault)
|
||||
const char code[] ="><,f<i,";
|
||||
tokenize(code);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void varid33() { // ticket #2875 (segmentation fault)
|
||||
const char code[] ="0; (a) < (a)";
|
||||
tokenize(code, true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void varid34() { // ticket #2825
|
||||
const char code[] ="class Fred : public B1, public B2\n"
|
||||
"{\n"
|
||||
|
@ -2064,9 +2043,9 @@ private:
|
|||
}
|
||||
|
||||
void varid_typename() {
|
||||
ASSERT_EQUALS("1: template < int d , class A , class B >\n", tokenize("template<int d, class A, class B>"));
|
||||
ASSERT_EQUALS("1: template < int d , class A , class B > ;\n", tokenize("template<int d, class A, class B>;"));
|
||||
|
||||
ASSERT_EQUALS("1: template < int d , typename A , typename B >\n", tokenize("template<int d, typename A, typename B>"));
|
||||
ASSERT_EQUALS("1: template < int d , typename A , typename B > ;\n", tokenize("template<int d, typename A, typename B>;"));
|
||||
|
||||
ASSERT_EQUALS("1: typename A a@1 ;\n", tokenize("typename A a;"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue