From e43037db86b3aef2553b0bd72c8614413d792e6f Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 10 Apr 2024 09:20:34 +0200 Subject: [PATCH 1/2] testrunner: added `ASSERT_THROW_INTERNAL` --- test/fixture.h | 1 + test/testautovariables.cpp | 2 +- test/testcondition.cpp | 12 +- test/testerrorlogger.cpp | 2 +- test/testgarbage.cpp | 786 +++++++++++++++++----------------- test/testleakautovar.cpp | 16 +- test/testsimplifytemplate.cpp | 34 +- test/testsimplifytokens.cpp | 4 +- test/testsimplifytypedef.cpp | 20 +- test/teststl.cpp | 8 +- test/testsymboldatabase.cpp | 10 +- test/testtoken.cpp | 2 +- test/testtokenize.cpp | 134 +++--- test/testuninitvar.cpp | 18 +- test/testvarid.cpp | 6 +- 15 files changed, 528 insertions(+), 527 deletions(-) diff --git a/test/fixture.h b/test/fixture.h index 63e35f79733..ab1e1ecdfdf 100644 --- a/test/fixture.h +++ b/test/fixture.h @@ -299,6 +299,7 @@ class TestFixture : public ErrorLogger { #define ASSERT_THROW( CMD, EXCEPTION ) do { try { CMD; assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&) {} catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) #define ASSERT_THROW_EQUALS( CMD, EXCEPTION, EXPECTED ) do { try { CMD; assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&e) { assertEquals(__FILE__, __LINE__, EXPECTED, e.errorMessage); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) #define ASSERT_THROW_EQUALS_2( CMD, EXCEPTION, EXPECTED ) do { try { CMD; assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&e) { assertEquals(__FILE__, __LINE__, EXPECTED, e.what()); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) +#define ASSERT_THROW_INTERNAL( CMD, TYPE ) do { try { CMD; assertThrowFail(__FILE__, __LINE__); } catch (const InternalError& e) { assertEqualsEnum(__FILE__, __LINE__, InternalError::TYPE, e.type); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) #define ASSERT_NO_THROW( CMD ) do { try { CMD; } catch (...) { assertNoThrowFail(__FILE__, __LINE__); } } while (false) #define TODO_ASSERT_THROW( CMD, EXCEPTION ) do { try { CMD; } catch (const EXCEPTION&) {} catch (...) { assertThrow(__FILE__, __LINE__); } } while (false) #define TODO_ASSERT( CONDITION ) do { const bool condition=(CONDITION); todoAssertEquals(__FILE__, __LINE__, true, false, condition); } while (false) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index ef8cd776a2b..500f0c9fbc2 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -443,7 +443,7 @@ class TestAutoVariables : public TestFixture { } void testautovar12() { // Ticket #5024, #5050 - Crash on invalid input - ASSERT_THROW(check("void f(int* a) { a = }"), InternalError); + ASSERT_THROW_INTERNAL(check("void f(int* a) { a = }"), SYNTAX); check("struct custom_type { custom_type(int) {} };\n" "void func(int) {}\n" "int var;\n" diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 5c794bbd39c..115fbe4b84c 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -2787,12 +2787,12 @@ class TestCondition : public TestFixture { "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Identical condition 'x>100', second condition is always false\n", errout_str()); - ASSERT_THROW(check("void f(int x) {\n" // #8217 - crash for incomplete code - " if (x > 100) { return; }\n" - " X(do);\n" - " if (x > 100) {}\n" - "}"), - InternalError); + ASSERT_THROW_INTERNAL(check("void f(int x) {\n" // #8217 - crash for incomplete code + " if (x > 100) { return; }\n" + " X(do);\n" + " if (x > 100) {}\n" + "}"), + SYNTAX); check("void f(const int *i) {\n" " if (!i) return;\n" diff --git a/test/testerrorlogger.cpp b/test/testerrorlogger.cpp index ea3e2234275..f7d5c11f794 100644 --- a/test/testerrorlogger.cpp +++ b/test/testerrorlogger.cpp @@ -402,7 +402,7 @@ class TestErrorLogger : public TestFixture { "17 Programming error" "0 "; ErrorMessage msg; - ASSERT_THROW(msg.deserialize(str), InternalError); + ASSERT_THROW_INTERNAL(msg.deserialize(str), INTERNAL); } } diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 8a08aff2f7c..3b52c7493e1 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -330,18 +330,18 @@ class TestGarbage : public TestFixture { void wrong_syntax1() { { const char code[] ="TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))"; - ASSERT_THROW(checkCode(code), InternalError); + ASSERT_THROW_INTERNAL(checkCode(code), UNKNOWN_MACRO); ASSERT_EQUALS("", errout_str()); } { const char code[] ="struct A { template struct { }; };"; - ASSERT_THROW(checkCode(code), InternalError); + ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX); } { const char code[] ="enum ABC { A,B, typedef enum { C } };"; - ASSERT_THROW(checkCode(code), InternalError); + ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX); } } @@ -354,7 +354,7 @@ class TestGarbage : public TestFixture { "void G( template class (j) ) {}"; // don't segfault.. - ASSERT_THROW(checkCode(code), InternalError); + ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX); ignore_errout(); // we are not interested in the output } @@ -383,18 +383,18 @@ class TestGarbage : public TestFixture { void wrong_syntax4() { // #3618 const char code[] = "typedef void (x) (int); return x&"; - ASSERT_THROW(checkCode(code), InternalError); + ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX); } void wrong_syntax_if_macro() { // #2518 #4171 - ASSERT_THROW(checkCode("void f() { if MACRO(); }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f() { if MACRO(); }"), SYNTAX); // #4668 - note there is no semicolon after MACRO() - ASSERT_THROW(checkCode("void f() { if (x) MACRO() {} }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f() { if (x) MACRO() {} }"), SYNTAX); // #4810 - note there is no semicolon after MACRO() - ASSERT_THROW(checkCode("void f() { if (x) MACRO() else ; }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f() { if (x) MACRO() else ; }"), SYNTAX); } void wrong_syntax_class_x_y() { @@ -416,31 +416,31 @@ class TestGarbage : public TestFixture { } void wrong_syntax_anonymous_struct() { - ASSERT_THROW(checkCode("struct { int x; } = {0};"), InternalError); - ASSERT_THROW(checkCode("struct { int x; } * = {0};"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("struct { int x; } = {0};"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("struct { int x; } * = {0};"), SYNTAX); } void syntax_case_default() { - ASSERT_THROW(checkCode("void f() {switch (n) { case: z(); break;}}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f() {switch (n) { case: z(); break;}}"), SYNTAX); - ASSERT_THROW(checkCode("void f() {switch (n) { case;: z(); break;}}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f() {switch (n) { case;: z(); break;}}"), SYNTAX); - ASSERT_THROW(checkCode("void f() {switch (n) { case {}: z(); break;}}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f() {switch (n) { case {}: z(); break;}}"), SYNTAX); - ASSERT_THROW(checkCode("void f() {switch (n) { case 0?{1}:{2} : z(); break;}}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f() {switch (n) { case 0?{1}:{2} : z(); break;}}"), SYNTAX); - ASSERT_THROW(checkCode("void f() {switch (n) { case 0?1;:{2} : z(); break;}}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f() {switch (n) { case 0?1;:{2} : z(); break;}}"), SYNTAX); - ASSERT_THROW(checkCode("void f() {switch (n) { case 0?(1?{3:4}):2 : z(); break;}}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f() {switch (n) { case 0?(1?{3:4}):2 : z(); break;}}"), AST); //ticket #4234 - ASSERT_THROW(checkCode("( ) { switch break ; { switch ( x ) { case } y break ; : } }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("( ) { switch break ; { switch ( x ) { case } y break ; : } }"), SYNTAX); //ticket #4267 - ASSERT_THROW(checkCode("f ( ) { switch break; { switch ( x ) { case } case break; -6: ( ) ; } }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("f ( ) { switch break; { switch ( x ) { case } case break; -6: ( ) ; } }"), SYNTAX); // Missing semicolon - ASSERT_THROW(checkCode("void foo () { switch(0) case 0 : default : }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void foo () { switch(0) case 0 : default : }"), SYNTAX); } void garbageCode1() { @@ -456,21 +456,21 @@ class TestGarbage : public TestFixture { } void garbageCode4() { // #4887 - ASSERT_THROW(checkCode("void f ( ) { = a ; if ( 1 ) if = ( 0 ) ; }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f ( ) { = a ; if ( 1 ) if = ( 0 ) ; }"), SYNTAX); } void garbageCode5() { // #5168 - ASSERT_THROW(checkCode("( asm : ; void : );"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("( asm : ; void : );"), SYNTAX); } void garbageCode6() { // #5214 - ASSERT_THROW(checkCode("int b = ( 0 ? ? ) 1 : 0 ;"), InternalError); - ASSERT_THROW(checkCode("int a = int b = ( 0 ? ? ) 1 : 0 ;"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("int b = ( 0 ? ? ) 1 : 0 ;"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("int a = int b = ( 0 ? ? ) 1 : 0 ;"), SYNTAX); } void garbageCode7() { - ASSERT_THROW(checkCode("1 (int j) { return return (c) * sizeof } y[1];"), InternalError); - ASSERT_THROW(checkCode("foo(Args&&...) fn void = { } auto templatenext )"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("for( rl=reslist; rl!=NULL; rl=rl->next )"), SYNTAX); } void garbageCode12() { // do not crash @@ -503,7 +503,7 @@ class TestGarbage : public TestFixture { } void garbageCode15() { // Ticket #5203 - ASSERT_THROW(checkCode("int f ( int* r ) { { int s[2] ; f ( s ) ; if ( ) } }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("int f ( int* r ) { { int s[2] ; f ( s ) ; if ( ) } }"), SYNTAX); } void garbageCode16() { @@ -511,13 +511,13 @@ class TestGarbage : public TestFixture { } void garbageCode17() { - ASSERT_THROW(checkCode("void h(int l) {\n" - " while\n" // Don't crash (#3870) - "}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void h(int l) {\n" + " while\n" // Don't crash (#3870) + "}"), SYNTAX); } void garbageCode18() { - ASSERT_THROW(checkCode("switch(){case}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("switch(){case}"), SYNTAX); } void garbageCode20() { @@ -527,21 +527,21 @@ class TestGarbage : public TestFixture { void garbageCode21() { // Ticket #3486 - Don't crash garbage code - ASSERT_THROW(checkCode("void f()\n" - "{\n" - " (\n" - " x;\n" - " int a, a2, a2*x; if () ;\n" - " )\n" - "}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f()\n" + "{\n" + " (\n" + " x;\n" + " int a, a2, a2*x; if () ;\n" + " )\n" + "}"), SYNTAX); } void garbageCode22() { // Ticket #3480 - Don't crash garbage code - ASSERT_THROW(checkCode("int f()\n" - "{\n" - " return if\n" - "}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("int f()\n" + "{\n" + " return if\n" + "}"), SYNTAX); } void garbageCode23() { @@ -556,40 +556,40 @@ class TestGarbage : public TestFixture { void garbageCode24() { // don't crash (example from #6361) - ASSERT_THROW(checkCode("float buffer[64];\n" - "main (void)\n" - "{\n" - " char *cptr;\n" - " cptr = (char *)buffer;\n" - " cptr += (-(long int) buffer & (16 * sizeof (float) - 1));\n" - "}\n"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("float buffer[64];\n" + "main (void)\n" + "{\n" + " char *cptr;\n" + " cptr = (char *)buffer;\n" + " cptr += (-(long int) buffer & (16 * sizeof (float) - 1));\n" + "}\n"), SYNTAX); ignore_errout(); // we do not care about the output } void garbageCode25() { // Ticket #2386 - Segmentation fault upon strange syntax - ASSERT_THROW(checkCode("void f() {\n" - " switch ( x ) {\n" - " case struct Tree : break;\n" - " }\n" - "}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f() {\n" + " switch ( x ) {\n" + " case struct Tree : break;\n" + " }\n" + "}"), SYNTAX); } void garbageCode26() { // See tickets #2518 #2555 #4171 - ASSERT_THROW(checkCode("void f() {\n" - " switch MAKEWORD(1)\n" - " {\n" - " case 0:\n" - " return;\n" - " }\n" - "}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f() {\n" + " switch MAKEWORD(1)\n" + " {\n" + " case 0:\n" + " return;\n" + " }\n" + "}"), SYNTAX); } void garbageCode27() { - ASSERT_THROW(checkCode("int f() {\n" - " return if\n" - "}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("int f() {\n" + " return if\n" + "}"), SYNTAX); } void garbageCode28() { @@ -610,7 +610,7 @@ class TestGarbage : public TestFixture { } void garbageCode31() { - ASSERT_THROW(checkCode("typedef struct{}x[([],)]typedef e y;(y,x 0){}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("typedef struct{}x[([],)]typedef e y;(y,x 0){}"), SYNTAX); } void garbageCode33() { // #6613 @@ -623,21 +623,21 @@ class TestGarbage : public TestFixture { " do\n" " while (0);\n" "}"; - ASSERT_THROW(checkCode(code), InternalError); + ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX); } void garbageCode35() { // ticket #2604 segmentation fault - ASSERT_THROW(checkCode("sizeof <= A"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("sizeof <= A"), AST); } void garbageCode36() { // #6334 - ASSERT_THROW(checkCode("{ } < class template < > , { = } ; class... >\n" - "struct Y { }\n" - "class Types { }\n" - "( X < int > \"uses template\" ) ( < ( ) \"uses ;" - "( int int ::primary \"uses template\" ) int double \"uses )" - "::primary , \"uses template\" ;\n"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ } < class template < > , { = } ; class... >\n" + "struct Y { }\n" + "class Types { }\n" + "( X < int > \"uses template\" ) ( < ( ) \"uses ;" + "( int int ::primary \"uses template\" ) int double \"uses )" + "::primary , \"uses template\" ;\n"), SYNTAX); } void garbageCode37() { @@ -667,11 +667,11 @@ class TestGarbage : public TestFixture { } void garbageCode44() { // #6704 - ASSERT_THROW(checkCode("{ { }; }; { class A : }; public typedef b;"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ { }; }; { class A : }; public typedef b;"), SYNTAX); } void garbageCode45() { // #6608 - ASSERT_THROW(checkCode("struct true template < > { = } > struct Types \"s\" ; static_assert < int > ;"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("struct true template < > { = } > struct Types \"s\" ; static_assert < int > ;"), SYNTAX); } void garbageCode46() { // #6705 @@ -689,56 +689,56 @@ class TestGarbage : public TestFixture { } void garbageCode49() { // #6715 - ASSERT_THROW(checkCode(" ( ( ) ) { } ( { ( __builtin_va_arg_pack ( ) ) ; } ) { ( int { ( ) ( ( ) ) } ( ) { } ( ) ) += ( ) }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode(" ( ( ) ) { } ( { ( __builtin_va_arg_pack ( ) ) ; } ) { ( int { ( ) ( ( ) ) } ( ) { } ( ) ) += ( ) }"), AST); } void garbageCode51() { // #6719 - ASSERT_THROW(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 = }"), InternalError); + ASSERT_THROW_INTERNAL(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 = }"), SYNTAX); } void garbageCode53() { // #6721 - ASSERT_THROW(checkCode("{ { } }; void foo (struct int i) { x->b[i] = = }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ { } }; void foo (struct int i) { x->b[i] = = }"), SYNTAX); } void garbageCode54() { // #6722 - ASSERT_THROW(checkCode("{ typedef long ((pf) p) (); }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ typedef long ((pf) p) (); }"), SYNTAX); } void garbageCode55() { // #6724 - ASSERT_THROW(checkCode("() __attribute__((constructor)); { } { }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("() __attribute__((constructor)); { } { }"), SYNTAX); } void garbageCode56() { // #6713 - ASSERT_THROW(checkCode("void foo() { int a = 0; int b = ???; }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void foo() { int a = 0; int b = ???; }"), AST); } void garbageCode57() { // #6731 - ASSERT_THROW(checkCode("{ } if () try { } catch (...) B::~B { }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ } if () try { } catch (...) B::~B { }"), SYNTAX); } void garbageCode58() { // #6732, #6762 - ASSERT_THROW(checkCode("{ }> {= ~A()^{} }P { }"), InternalError); - ASSERT_THROW(checkCode("{= ~A()^{} }P { } { }> is"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ }> {= ~A()^{} }P { }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("{= ~A()^{} }P { } { }> is"), SYNTAX); } void garbageCode59() { // #6735 - ASSERT_THROW(checkCode("{ { } }; char font8x8[256][8]"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ { } }; char font8x8[256][8]"), SYNTAX); } void garbageCode60() { // #6736 - ASSERT_THROW(checkCode("{ } { } typedef int int_array[]; int_array &right ="), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ } { } typedef int int_array[]; int_array &right ="), SYNTAX); } void garbageCode61() { // #6737 - ASSERT_THROW(checkCode("{ (const U&) }; { }; { }; struct U : virtual public"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ (const U&) }; { }; { }; struct U : virtual public"), SYNTAX); } 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); + ASSERT_THROW_INTERNAL(checkCode("{ } { } typedef int u_array[]; typedef u_array &u_array_ref; (u_array_ref arg) { } u_array_ref u_array_ref_gbl_obj0"), INTERNAL); } void garbageCode64() { // #6740 - ASSERT_THROW(checkCode("{ } foo(void (*bar)(void))"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ } foo(void (*bar)(void))"), SYNTAX); } void garbageCode65() { // #6741 @@ -747,7 +747,7 @@ class TestGarbage : public TestFixture { } void garbageCode66() { // #6742 - ASSERT_THROW(checkCode("{ { } }; { { } }; { }; class bar : public virtual"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ { } }; { { } }; { }; class bar : public virtual"), SYNTAX); } void garbageCode68() { // #6745 @@ -755,65 +755,65 @@ class TestGarbage : public TestFixture { } void garbageCode69() { // #6746 - ASSERT_THROW(checkCode("{ (make_mess, aux); } typedef void F(void); aux(void (*x)()) { } (void (*y)()) { } F*"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ (make_mess, aux); } typedef void F(void); aux(void (*x)()) { } (void (*y)()) { } F*"), SYNTAX); } void garbageCode70() { // #6747 - ASSERT_THROW(checkCode("{ } __attribute__((constructor)) void"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ } __attribute__((constructor)) void"), SYNTAX); } void garbageCode71() { // #6748 - ASSERT_THROW(checkCode("( ) { } typedef void noattr_t ( ) ; noattr_t __attribute__ ( )"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("( ) { } typedef void noattr_t ( ) ; noattr_t __attribute__ ( )"), SYNTAX); } void garbageCode72() { // #6749 - ASSERT_THROW(checkCode("{ } { } typedef void voidfn(void); = } } unsigned *d = (b b--) --*d"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void foo (int **p) { { { };>= } } unsigned *d = (b b--) --*d"), SYNTAX); } void garbageCode78() { // #6756 - ASSERT_THROW(checkCode("( ) { [ ] } ( ) { } const_array_of_int ( ) { } typedef int A [ ] [ ] ; A a = { { } { } }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("( ) { [ ] } ( ) { } const_array_of_int ( ) { } typedef int A [ ] [ ] ; A a = { { } { } }"), SYNTAX); ignore_errout(); // we do not care about the output } void garbageCode79() { // #6757 - ASSERT_THROW(checkCode("{ } { } typedef void ( func_type ) ( ) ; func_type & ( )"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ } { } typedef void ( func_type ) ( ) ; func_type & ( )"), SYNTAX); } void garbageCode80() { // #6759 - ASSERT_THROW(checkCode("( ) { ; ( ) ; ( * ) [ ] ; [ ] = ( ( ) ( ) h ) ! ( ( ) ) } { ; } { } head heads [ ] = ; = & heads [ 2 ]"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("( ) { ; ( ) ; ( * ) [ ] ; [ ] = ( ( ) ( ) h ) ! ( ( ) ) } { ; } { } head heads [ ] = ; = & heads [ 2 ]"), SYNTAX); } void garbageCode81() { // #6760 - ASSERT_THROW(checkCode("{ } [ ] { ( ) } { } typedef void ( *fptr1 ) ( ) const"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ } [ ] { ( ) } { } typedef void ( *fptr1 ) ( ) const"), SYNTAX); } void garbageCode82() { // #6761 - ASSERT_THROW(checkCode("p(\"Hello \" 14) _yn(const size_t) typedef bool pfunk (*pfunk)(const size_t)"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("p(\"Hello \" 14) _yn(const size_t) typedef bool pfunk (*pfunk)(const size_t)"), SYNTAX); } void garbageCode83() { // #6771 - ASSERT_THROW(checkCode("namespace A { class } class A { friend C ; } { } ;"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("namespace A { class } class A { friend C ; } { } ;"), SYNTAX); } void garbageCode84() { // #6780 - ASSERT_THROW(checkCode("int main ( [ ] ) { " " [ ] ; int i = 0 ; do { } ; } ( [ ] ) { }"), InternalError); // do not crash + ASSERT_THROW_INTERNAL(checkCode("int main ( [ ] ) { " " [ ] ; int i = 0 ; do { } ; } ( [ ] ) { }"), SYNTAX); // do not crash } void garbageCode85() { // #6784 @@ -821,68 +821,68 @@ class TestGarbage : public TestFixture { } void garbageCode86() { // #6785 - ASSERT_THROW(checkCode("{ } typedef char ( *( X ) ( void) , char ) ;"), InternalError); // do not crash + ASSERT_THROW_INTERNAL(checkCode("{ } typedef char ( *( X ) ( void) , char ) ;"), SYNTAX); // do not crash } void garbageCode87() { // #6788 - ASSERT_THROW(checkCode("((X (128))) (int a) { v[ = {} (x 42) a] += }"), InternalError); // do not crash + ASSERT_THROW_INTERNAL(checkCode("((X (128))) (int a) { v[ = {} (x 42) a] += }"), SYNTAX); // do not crash } void garbageCode88() { // #6786 - ASSERT_THROW(checkCode("( ) { ( 0 ) { ( ) } } g ( ) { i( ( false ?) ( ) : 1 ) ; } ;"), InternalError); // do not crash + ASSERT_THROW_INTERNAL(checkCode("( ) { ( 0 ) { ( ) } } g ( ) { i( ( false ?) ( ) : 1 ) ; } ;"), SYNTAX); // 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 + ASSERT_THROW_INTERNAL(checkCode("{ } { } typedef int u_array [[ ] ; typedef u_array & u_array_ref] ( ) { } u_array_ref_gbl_obj0"), SYNTAX); // do not crash } void garbageCode91() { // #6791 - ASSERT_THROW(checkCode("typedef __attribute__((vector_size (16))) { return[ (v2df){ } ;] }"), InternalError); // throw syntax error + ASSERT_THROW_INTERNAL(checkCode("typedef __attribute__((vector_size (16))) { return[ (v2df){ } ;] }"), SYNTAX); // throw syntax error } void garbageCode92() { // #6792 - ASSERT_THROW(checkCode("template < typename _Tp ( ( ) ; _Tp ) , decltype > { } { ( ) ( ) }"), InternalError); // do not crash + ASSERT_THROW_INTERNAL(checkCode("template < typename _Tp ( ( ) ; _Tp ) , decltype > { } { ( ) ( ) }"), SYNTAX); // do not crash } void garbageCode94() { // #6803 //checkCode("typedef long __m256i __attribute__ ( ( ( ) ) )[ ; ( ) { } typedef __m256i __attribute__ ( ( ( ) ) ) < ] ( ) { ; }"); - ASSERT_THROW(checkCode("typedef long __m256i __attribute__ ( ( ( ) ) )[ ; ( ) { } typedef __m256i __attribute__ ( ( ( ) ) ) < ] ( ) { ; }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("typedef long __m256i __attribute__ ( ( ( ) ) )[ ; ( ) { } typedef __m256i __attribute__ ( ( ( ) ) ) < ] ( ) { ; }"), SYNTAX); } void garbageCode95() { // #6804 - ASSERT_THROW(checkCode("{ } x x ; { } h h [ ] ( ) ( ) { struct x ( x ) ; int __attribute__ ( ) f ( ) { h - > first = & x ; struct x * n = h - > first ; ( ) n > } }"), InternalError); // do not crash + ASSERT_THROW_INTERNAL(checkCode("{ } x x ; { } h h [ ] ( ) ( ) { struct x ( x ) ; int __attribute__ ( ) f ( ) { h - > first = & x ; struct x * n = h - > first ; ( ) n > } }"), AST); // do not crash } void garbageCode96() { // #6807 - ASSERT_THROW(checkCode("typedef J J[ ; typedef ( ) ( ) { ; } typedef J J ;] ( ) ( J cx ) { n } ;"), InternalError); // throw syntax error + ASSERT_THROW_INTERNAL(checkCode("typedef J J[ ; typedef ( ) ( ) { ; } typedef J J ;] ( ) ( J cx ) { n } ;"), SYNTAX); // throw syntax error } void garbageCode97() { // #6808 - ASSERT_THROW(checkCode("namespace A {> } class A{ { }} class A : T< ;"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("namespace A {> } class A{ { }} class A : T< ;"), SYNTAX); } void garbageCode98() { // #6838 - ASSERT_THROW(checkCode("for (cocon To::ta@Taaaaaforconst oken aaaaaaaaaaaa5Dl()\n" - "const unsigned in;\n" - "fon *tok = f);.s(Token i = d-)L;"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("for (cocon To::ta@Taaaaaforconst oken aaaaaaaaaaaa5Dl()\n" + "const unsigned in;\n" + "fon *tok = f);.s(Token i = d-)L;"), SYNTAX); } void garbageCode99() { // #6726 - ASSERT_THROW(checkCode("{ xs :: i(:) ! ! x/5 ! !\n" - "i, :: a :: b integer, } foo2(x) :: j(:)\n" - "b type(*), d(:), a x :: end d(..), foo end\n" - "foo4 b d(..), a a x type(*), b foo2 b"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ xs :: i(:) ! ! x/5 ! !\n" + "i, :: a :: b integer, } foo2(x) :: j(:)\n" + "b type(*), d(:), a x :: end d(..), foo end\n" + "foo4 b d(..), a a x type(*), b foo2 b"), INTERNAL); } void garbageCode100() { // #6840 - ASSERT_THROW(checkCode("( ) { ( i< ) } int foo ( ) { int i ; ( for ( i => 1 ) ; ) }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("( ) { ( i< ) } int foo ( ) { int i ; ( for ( i => 1 ) ; ) }"), SYNTAX); } void garbageCode101() { // #6835 // Reported case - ASSERT_THROW(checkCode("template < class , =( , int) X = 1 > struct A { } ( ) { = } [ { } ] ( ) { A < void > 0 }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("template < class , =( , int) X = 1 > struct A { } ( ) { = } [ { } ] ( ) { A < void > 0 }"), SYNTAX); // Reduced case - ASSERT_THROW(checkCode("template < class =( , ) X = 1> struct A {}; A a;"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("template < class =( , ) X = 1> struct A {}; A a;"), SYNTAX); } void garbageCode102() { // #6846 @@ -891,19 +891,19 @@ class TestGarbage : public TestFixture { } void garbageCode103() { // #6824 - ASSERT_THROW(checkCode("a f(r) int * r; { { int s[2]; [f(s); if () ] } }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("a f(r) int * r; { { int s[2]; [f(s); if () ] } }"), SYNTAX); } void garbageCode104() { // #6847 - ASSERT_THROW(checkCode("template < Types > struct S {> ( S < ) S >} { ( ) { } } ( ) { return S < void > ( ) } { ( )> >} { ( ) { } } ( ) { ( ) }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("template < Types > struct S {> ( S < ) S >} { ( ) { } } ( ) { return S < void > ( ) } { ( )> >} { ( ) { } } ( ) { ( ) }"), SYNTAX); } void garbageCode105() { // #6859 - ASSERT_THROW(checkCode("void foo (int i) { int a , for (a 1; a( < 4; a++) if (a) (b b++) (b);) n++; }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void foo (int i) { int a , for (a 1; a( < 4; a++) if (a) (b b++) (b);) n++; }"), SYNTAX); } void garbageCode106() { // #6880 - ASSERT_THROW(checkCode("[ ] typedef typedef b_array b_array_ref [ ; ] ( ) b_array_ref b_array_ref_gbl_obj0 { ; { b_array_ref b_array_ref_gbl_obj0 } }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("[ ] typedef typedef b_array b_array_ref [ ; ] ( ) b_array_ref b_array_ref_gbl_obj0 { ; { b_array_ref b_array_ref_gbl_obj0 } }"), SYNTAX); } void garbageCode107() { // #6881 @@ -911,7 +911,7 @@ class TestGarbage : public TestFixture { } void garbageCode108() { // #6895 "segmentation fault (invalid code) in CheckCondition::isOppositeCond" - ASSERT_THROW(checkCode("A( ) { } bool f( ) { ( ) F; ( ) { ( == ) if ( !=< || ( !A( ) && r[2] ) ) ( !A( ) ) ( ) } }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("A( ) { } bool f( ) { ( ) F; ( ) { ( == ) if ( !=< || ( !A( ) && r[2] ) ) ( !A( ) ) ( ) } }"), SYNTAX); } void garbageCode109() { // #6900 "segmentation fault (invalid code) in CheckStl::runSimplifiedChecks" @@ -920,7 +920,7 @@ class TestGarbage : public TestFixture { } void garbageCode110() { // #6902 "segmentation fault (invalid code) in CheckStl::string_c_str" - ASSERT_THROW(checkCode("( *const<> ( size_t ) ; foo ) { } * ( *const ( size_t ) ( ) ;> foo )< { }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("( *const<> ( size_t ) ; foo ) { } * ( *const ( size_t ) ( ) ;> foo )< { }"), SYNTAX); } void garbageCode111() { // #6907 @@ -939,11 +939,11 @@ class TestGarbage : public TestFixture { } void garbageCode115() { // #5506 - ASSERT_THROW(checkCode("A template < int { int = -1 ; } template < int N > struct B { int [ A < N > :: zero ] ; } ; B < 0 > b ;"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("A template < int { int = -1 ; } template < int N > struct B { int [ A < N > :: zero ] ; } ; B < 0 > b ;"), UNKNOWN_MACRO); } void garbageCode116() { // #5356 - ASSERT_THROW(checkCode("struct template struct B { }; B < 0 > b;"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("struct template struct B { }; B < 0 > b;"), SYNTAX); } void garbageCode117() { // #6121 @@ -952,13 +952,13 @@ class TestGarbage : public TestFixture { } void garbageCode118() { // #5600 - missing include causes invalid enum - ASSERT_THROW(checkCode("enum {\n" - " NUM_OPCODES =\n" - // #include "definition" - "};\n" - "struct bytecode {};\n" - "jv jq_next() { opcode = ((opcode) +NUM_OPCODES);\n" - "}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("enum {\n" + " NUM_OPCODES =\n" + // #include "definition" + "};\n" + "struct bytecode {};\n" + "jv jq_next() { opcode = ((opcode) +NUM_OPCODES);\n" + "}"), SYNTAX); } void garbageCode119() { // #5598 @@ -974,9 +974,9 @@ class TestGarbage : public TestFixture { } void garbageCode121() { // #2585 - ASSERT_THROW(checkCode("abcdef?" "?<" - "123456?" "?>" - "+?" "?="), InternalError); + ASSERT_THROW_INTERNAL(checkCode("abcdef?" "?<" + "123456?" "?>" + "+?" "?="), SYNTAX); } void garbageCode122() { // #6303 @@ -997,14 +997,14 @@ class TestGarbage : public TestFixture { } 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); - ASSERT_THROW(checkCode("template < Types > struct S :{ ( S < ) S >} { ( ) { } } ( ) { return S < void > ( ) }"), - InternalError); + ASSERT_THROW_INTERNAL(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 ; ( ) ( ) }"), UNKNOWN_MACRO); + ASSERT_THROW_INTERNAL(checkCode("template < Types > struct S :{ ( S < ) S >} { ( ) { } } ( ) { return S < void > ( ) }"), + SYNTAX); } void garbageCode126() { - ASSERT_THROW(checkCode("{ } float __ieee754_sinhf ( float x ) { float t , , do { gf_u ( jx ) { } ( 0 ) return ; ( ) { } t } ( 0x42b17180 ) { } }"), - InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ } float __ieee754_sinhf ( float x ) { float t , , do { gf_u ( jx ) { } ( 0 ) return ; ( ) { } t } ( 0x42b17180 ) { } }"), + SYNTAX); } void garbageCode127() { // #6667 @@ -1026,8 +1026,8 @@ class TestGarbage : public TestFixture { } void garbageCode129() { - ASSERT_THROW(checkCode("operator - ( { } typedef typename x ; ( ) ) { ( { { ( ( ) ) } ( { } ) } ) }"), - InternalError); + ASSERT_THROW_INTERNAL(checkCode("operator - ( { } typedef typename x ; ( ) ) { ( { { ( ( ) ) } ( { } ) } ) }"), + SYNTAX); } void garbageCode130() { @@ -1036,33 +1036,33 @@ class TestGarbage : public TestFixture { } void garbageCode131() { - ASSERT_THROW(checkCode("( void ) { ( ) } ( ) / { ( ) }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("( void ) { ( ) } ( ) / { ( ) }"), SYNTAX); // actually the invalid code should trigger an syntax error... } void garbageCode132() { // #7022 - ASSERT_THROW(checkCode("() () { } { () () ({}) i() } void i(void(*ptr) ()) { ptr(!) () }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("() () { } { () () ({}) i() } void i(void(*ptr) ()) { ptr(!) () }"), SYNTAX); } void garbageCode133() { - ASSERT_THROW(checkCode("void f() {{}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f() {{}"), SYNTAX); - ASSERT_THROW(checkCode("void f()) {}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f()) {}"), SYNTAX); - ASSERT_THROW(checkCode("void f()\n" - "{\n" - " foo(;\n" - "}\n"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f()\n" + "{\n" + " foo(;\n" + "}\n"), SYNTAX); - ASSERT_THROW(checkCode("void f()\n" - "{\n" - " for(;;){ foo();\n" - "}\n"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f()\n" + "{\n" + " for(;;){ foo();\n" + "}\n"), SYNTAX); - ASSERT_THROW(checkCode("void f()\n" - "{\n" - " a[10;\n" - "}\n"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f()\n" + "{\n" + " a[10;\n" + "}\n"), SYNTAX); { const char code[] = "{\n" @@ -1098,10 +1098,10 @@ class TestGarbage : public TestFixture { void garbageCode134() { // Ticket #5605, #5759, #5762, #5774, #5823, #6059 - ASSERT_THROW(checkCode("foo() template struct tuple Args> tuple { } main() { foo(); }"), InternalError); - ASSERT_THROW(checkCode("( ) template < T1 = typename = unused> struct Args { } main ( ) { foo < int > ( ) ; }"), InternalError); - ASSERT_THROW(checkCode("() template < T = typename = x > struct a {} { f () }"), InternalError); - ASSERT_THROW(checkCode("template < T = typename = > struct a { f }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("foo() template struct tuple Args> tuple { } main() { foo(); }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("( ) template < T1 = typename = unused> struct Args { } main ( ) { foo < int > ( ) ; }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("() template < T = typename = x > struct a {} { f () }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("template < T = typename = > struct a { f }"), SYNTAX); checkCode("struct S { int i, j; }; " "template struct X {}; " "X<&S::i, int> x = X<&S::i, int>(); " @@ -1137,12 +1137,12 @@ class TestGarbage : public TestFixture { } void garbageCode136() { // #7033 - ASSERT_THROW(checkCode("{ } () { void f() { node_t * n; for (; -n) {} } } { }"), - InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ } () { void f() { node_t * n; for (; -n) {} } } { }"), + SYNTAX); } void garbageCode137() { // #7034 - ASSERT_THROW(checkCode("\" \" typedef signed char f; \" \"; void a() { f * s = () &[]; (; ) (; ) }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("\" \" typedef signed char f; \" \"; void a() { f * s = () &[]; (; ) (; ) }"), SYNTAX); } void garbageCode138() { // #6660 @@ -1159,15 +1159,15 @@ class TestGarbage : public TestFixture { } void garbageCode139() { // #6659 heap user after free: kernel: sm750_accel.c - ASSERT_THROW(checkCode("void hw_copyarea() {\n" - " de_ctrl = (nDirection == RIGHT_TO_LEFT) ?\n" - " ( (0 & ~(((1 << (1 - (0 ? DE_CONTROL_DIRECTION))) - 1) << (0 ? DE_CONTROL_DIRECTION))) )\n" - " : 42;\n" - "}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void hw_copyarea() {\n" + " de_ctrl = (nDirection == RIGHT_TO_LEFT) ?\n" + " ( (0 & ~(((1 << (1 - (0 ? DE_CONTROL_DIRECTION))) - 1) << (0 ? DE_CONTROL_DIRECTION))) )\n" + " : 42;\n" + "}"), SYNTAX); } void garbageCode140() { // #7035 - ASSERT_THROW(checkCode("int foo(int align) { int off(= 0 % align; return off) ? \\ align - off : 0; \\ }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("int foo(int align) { int off(= 0 % align; return off) ? \\ align - off : 0; \\ }"), SYNTAX); } void garbageCode141() { // #7043 @@ -1175,56 +1175,56 @@ class TestGarbage : public TestFixture { } void garbageCode142() { // #7050 - ASSERT_THROW(checkCode("{ } ( ) { void mapGraphs ( ) { node_t * n ; for (!oid n ) { } } } { }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ } ( ) { void mapGraphs ( ) { node_t * n ; for (!oid n ) { } } } { }"), SYNTAX); } void garbageCode143() { // #6922 - ASSERT_THROW(checkCode("void neoProgramShadowRegs() {\n" - " int i;\n" - " Bool noProgramShadowRegs;\n" - " if (noProgramShadowRegs) {\n" - " } else {\n" - " switch (nPtr->NeoPanelWidth) {\n" - " case 1280:\n" - " VGAwCR(0x64,0x?? );\n" - " }\n" - " }\n" - "}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void neoProgramShadowRegs() {\n" + " int i;\n" + " Bool noProgramShadowRegs;\n" + " if (noProgramShadowRegs) {\n" + " } else {\n" + " switch (nPtr->NeoPanelWidth) {\n" + " case 1280:\n" + " VGAwCR(0x64,0x?? );\n" + " }\n" + " }\n" + "}"), AST); } void garbageCode144() { // #6865 - ASSERT_THROW(checkCode("template < typename > struct A { } ; template < typename > struct A < INVALID > : A < int[ > { }] ;"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("template < typename > struct A { } ; template < typename > struct A < INVALID > : A < int[ > { }] ;"), SYNTAX); } void garbageCode146() { // #7081 - ASSERT_THROW(checkCode("void foo() {\n" - " ? std::cout << pow((, 1) << std::endl;\n" - " double () ^ {\n" - " int *p() ^ {\n" + " int *p don't crash @@ -1267,15 +1267,15 @@ class TestGarbage : public TestFixture { } void garbageCode156() { // #7120 - ASSERT_THROW(checkCode("struct {}a; d f() { c ? : } {}a.p"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("struct {}a; d f() { c ? : } {}a.p"), AST); } void garbageCode157() { // #7131 - ASSERT_THROW(checkCode("namespace std {\n" - " template < typename >\n" - " void swap();\n" - "}" - "template std::swap\n"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("namespace std {\n" + " template < typename >\n" + " void swap();\n" + "}" + "template std::swap\n"), SYNTAX); } void garbageCode158() { // #3238 @@ -1283,20 +1283,20 @@ class TestGarbage : public TestFixture { } void garbageCode159() { // #7119 - ASSERT_THROW(checkCode("({}typedef typename x;typename x!){({{}()})}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("({}typedef typename x;typename x!){({{}()})}"), SYNTAX); } void garbageCode160() { // #7190 - ASSERT_THROW(checkCode("f(a,b,c,d)float [ a[],d;int ] b[],c;{} "), InternalError); // don't hang + ASSERT_THROW_INTERNAL(checkCode("f(a,b,c,d)float [ a[],d;int ] b[],c;{} "), SYNTAX); // don't hang } void garbageCodeFuzzerClientMode1() { - ASSERT_THROW(checkCode("void f() { x= name2 & name3 name2 = | 0.1 , | 0.1 , | 0.1 name4 <= >( ); }"), InternalError); - ASSERT_THROW(checkCode("void f() { x = , * [ | + 0xff | > 0xff]; }"), InternalError); - ASSERT_THROW(checkCode("void f() { x = , | 0xff , 0.1 < ; }"), InternalError); - ASSERT_THROW(checkCode("void f() { x = [ 1 || ] ; }"), InternalError); - ASSERT_THROW(checkCode("void f1() { x = name6 1 || ? name3 [ ( 1 || +) ] ; }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f() { x= name2 & name3 name2 = | 0.1 , | 0.1 , | 0.1 name4 <= >( ); }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() { x = , * [ | + 0xff | > 0xff]; }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() { x = , | 0xff , 0.1 < ; }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f() { x = [ 1 || ] ; }"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("void f1() { x = name6 1 || ? name3 [ ( 1 || +) ] ; }"), SYNTAX); } void garbageValueFlow() { @@ -1305,22 +1305,22 @@ class TestGarbage : public TestFixture { "{\n" " (foo(s, , 2, , , 5, , 7)) abort()\n" "}\n"; - ASSERT_THROW(checkCode(code), InternalError); + ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX); // 6122 survive garbage code code = "; { int i ; for ( i = 0 ; = 123 ; ) - ; }"; - ASSERT_THROW(checkCode(code), InternalError); + ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX); code = "void f1() { for (int n = 0 n < 10 n++); }"; - ASSERT_THROW(checkCode(code), InternalError); + ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX); } void garbageSymbolDatabase() { checkCode("void f( { u = 1 ; } ) { }"); - ASSERT_THROW(checkCode("{ }; void namespace A::f; { g() { int } }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ }; void namespace A::f; { g() { int } }"), SYNTAX); - ASSERT_THROW(checkCode("class Foo {}; class Bar : public Foo"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("class Foo {}; class Bar : public Foo"), SYNTAX); checkCode("YY_DECL { switch (yy_act) {\n" " case 65: YY_BREAK\n" @@ -1331,17 +1331,17 @@ class TestGarbage : public TestFixture { } void garbageAST() { - 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) + ASSERT_THROW_INTERNAL(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] * {}"), SYNTAX); // Don't hang (#5787) checkCode("START_SECTION([EXTRA](bool isValid(const String &filename)))"); // Don't crash (#5991) // #8352 - ASSERT_THROW(checkCode("else return % name5 name2 - =name1 return enum | { - name3 1 enum != >= 1 >= ++ { { || " - "{ return return { | { - name3 1 enum != >= 1 >= ++ { name6 | ; ++}}}}}}}"), InternalError); - ASSERT_THROW(checkCode("else return % name5 name2 - =name1 return enum | { - name3 1 enum != >= 1 >= ++ { { || " - "{ return return { | { - name3 1 enum != >= 1 >= ++ { { || ; ++}}}}}}}}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("else return % name5 name2 - =name1 return enum | { - name3 1 enum != >= 1 >= ++ { { || " + "{ return return { | { - name3 1 enum != >= 1 >= ++ { name6 | ; ++}}}}}}}"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("else return % name5 name2 - =name1 return enum | { - name3 1 enum != >= 1 >= ++ { { || " + "{ return return { | { - name3 1 enum != >= 1 >= ++ { { || ; ++}}}}}}}}"), SYNTAX); } void templateSimplifierCrashes() { @@ -1420,32 +1420,32 @@ class TestGarbage : public TestFixture { } void garbageCode161() { //7200 - ASSERT_THROW(checkCode("{ }{ if () try { } catch (...)} B : : ~B { }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ }{ if () try { } catch (...)} B : : ~B { }"), SYNTAX); } void garbageCode162() { //7208 - ASSERT_THROW(checkCode("return << >> x return << >> x ", false), InternalError); + ASSERT_THROW_INTERNAL(checkCode("return << >> x return << >> x ", false), SYNTAX); } void garbageCode163() { //7228 - ASSERT_THROW(checkCode("typedef s f[](){typedef d h(;f)}", false), InternalError); + ASSERT_THROW_INTERNAL(checkCode("typedef s f[](){typedef d h(;f)}", false), SYNTAX); } void garbageCode164() { //7234 - ASSERT_THROW(checkCode("class d{k p;}(){d::d():B<()}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("class d{k p;}(){d::d():B<()}"), SYNTAX); } void garbageCode165() { //7235 - ASSERT_THROW(checkCode("for(;..)", false),InternalError); + ASSERT_THROW_INTERNAL(checkCode("for(;..)", false),SYNTAX); } void garbageCode167() { //7237 - ASSERT_THROW(checkCode("class D00i000{:D00i000::}i"),InternalError); + ASSERT_THROW_INTERNAL(checkCode("class D00i000{:D00i000::}i"),SYNTAX); } void garbageCode168() { @@ -1455,41 +1455,41 @@ class TestGarbage : public TestFixture { void garbageCode169() { // 6713 - ASSERT_THROW(checkCode("( ) { ( ) ; { return } switch ( ) i\n" - "set case break ; default: ( ) }", false), InternalError); + ASSERT_THROW_INTERNAL(checkCode("( ) { ( ) ; { return } switch ( ) i\n" + "set case break ; default: ( ) }", false), SYNTAX); } void garbageCode170() { // 7255 - ASSERT_THROW(checkCode("d i(){{f*s=typeid(()0,)}}", false), InternalError); + ASSERT_THROW_INTERNAL(checkCode("d i(){{f*s=typeid(()0,)}}", false), SYNTAX); } void garbageCode171() { // 7270 - ASSERT_THROW(checkCode("(){case()?():}:", false), InternalError); + ASSERT_THROW_INTERNAL(checkCode("(){case()?():}:", false), SYNTAX); } void garbageCode172() { // #7357 - ASSERT_THROW(checkCode("p>,"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("p>,"), SYNTAX); } void garbageCode173() { // #6781 heap corruption ; TemplateSimplifier::simplifyTemplateInstantiations - ASSERT_THROW(checkCode(" template < Types > struct S : >( S < ...Types... > S <) > { ( ) { } } ( ) { return S < void > ( ) }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode(" template < Types > struct S : >( S < ...Types... > S <) > { ( ) { } } ( ) { return S < void > ( ) }"), SYNTAX); } void garbageCode174() { // #7356 - ASSERT_THROW(checkCode("{r e() { w*constD = (())D = cast< }}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{r e() { w*constD = (())D = cast< }}"), SYNTAX); } void garbageCode175() { // #7027 - ASSERT_THROW(checkCode("int f() {\n" - " int i , j;\n" - " for ( i = t3 , i < t1 ; i++ )\n" - " for ( j = 0 ; j < = j++ )\n" - " return t1 ,\n" - "}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("int f() {\n" + " int i , j;\n" + " for ( i = t3 , i < t1 ; i++ )\n" + " for ( j = 0 ; j < = j++ )\n" + " return t1 ,\n" + "}"), SYNTAX); } void garbageCode176() { // #7527 @@ -1498,23 +1498,23 @@ class TestGarbage : public TestFixture { } void garbageCode181() { - ASSERT_THROW(checkCode("int test() { int +; }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("int test() { int +; }"), SYNTAX); } // #4195 - segfault for "enum { int f ( ) { return = } r = f ( ) ; }" void garbageCode182() { - ASSERT_THROW(checkCode("enum { int f ( ) { return = } r = f ( ) ; }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("enum { int f ( ) { return = } r = f ( ) ; }"), SYNTAX); } // #7505 - segfault void garbageCode183() { - ASSERT_THROW(checkCode("= { int } enum return { r = f() f(); }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("= { int } enum return { r = f() f(); }"), SYNTAX); } void garbageCode184() { // #7699 - ASSERT_THROW(checkCode("unsigned int AquaSalSystem::GetDisplayScreenCount() {\n" - " NSArray* pScreens = [NSScreen screens];\n" - " return pScreens ? [pScreens count] : 1;\n" - "}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("unsigned int AquaSalSystem::GetDisplayScreenCount() {\n" + " NSArray* pScreens = [NSScreen screens];\n" + " return pScreens ? [pScreens count] : 1;\n" + "}"), SYNTAX); } void garbageCode185() { // #6011 crash in libreoffice failure to create proper AST @@ -1532,19 +1532,19 @@ class TestGarbage : public TestFixture { // #8151 - segfault due to incorrect template syntax void garbageCode186() { - ASSERT_THROW(checkCode("A<>C"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("A<>C"), SYNTAX); } void garbageCode187() { // # 8152 - segfault in handling const std::string inp("0|\0|0>;\n", 8); - ASSERT_THROW(checkCode(inp), InternalError); + ASSERT_THROW_INTERNAL(checkCode(inp), SYNTAX); checkCode("template struct S : A< B || C > {};"); // No syntax error: #8390 checkCode("static_assert(A || B, ab);"); } void garbageCode188() { // #8255 - ASSERT_THROW(checkCode("{z r(){(){for(;<(x);){if(0==0)}}}}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{z r(){(){for(;<(x);){if(0==0)}}}}"), SYNTAX); } void garbageCode189() { // #8317 @@ -1552,35 +1552,35 @@ class TestGarbage : public TestFixture { } void garbageCode190() { // #8307 - ASSERT_THROW(checkCode("void foo() {\n" - " int i;\n" - " i *= 0;\n" - " !i <;\n" - "}"), - InternalError); + ASSERT_THROW_INTERNAL(checkCode("void foo() {\n" + " int i;\n" + " i *= 0;\n" + " !i <;\n" + "}"), + AST); } void garbageCode191() { // #8333 - ASSERT_THROW(checkCode("struct A { int f(const); };"), InternalError); - ASSERT_THROW(checkCode("struct A { int f(int, const, char); };"), InternalError); - ASSERT_THROW(checkCode("struct A { int f(struct); };"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("struct A { int f(const); };"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("struct A { int f(int, const, char); };"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("struct A { int f(struct); };"), SYNTAX); // The following code is valid and should not trigger any error checkCode("struct A { int f ( char ) ; } ;"); } void garbageCode192() { // #8386 (segmentation fault) - ASSERT_THROW(checkCode("{(()[((0||0xf||))]0[])}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{(()[((0||0xf||))]0[])}"), SYNTAX); } // #8740 void garbageCode193() { - ASSERT_THROW(checkCode("d f(){!=[]&&0()!=0}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("d f(){!=[]&&0()!=0}"), SYNTAX); } // #8384 void garbageCode194() { - ASSERT_THROW(checkCode("{((()))(return 1||);}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{((()))(return 1||);}"), SYNTAX); } // #8709 - no garbage but to avoid stability regression @@ -1595,23 +1595,23 @@ class TestGarbage : public TestFixture { // #8265 void garbageCode196() { - ASSERT_THROW(checkCode("0|,0<= void { ( ()) } 1 name3 return >= >= ( ) >= name5 (\n" - " name5 name6 :nam00 [ ()])}))})})})};\n" - "}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f(){\n" + "x= ={(continue continue { ( struct continue { ( ++ name5 name5 ) ( name5 name5 n\n" + "ame5 ( name5 struct ( name5 name5 < ) ) ( default ) { name4 != name5 name5 name5\n" + " ( name5 name5 name5 ( { 1 >= void { ( ()) } 1 name3 return >= >= ( ) >= name5 (\n" + " name5 name6 :nam00 [ ()])}))})})})};\n" + "}"), SYNTAX); } // #8752 @@ -1621,47 +1621,47 @@ class TestGarbage : public TestFixture { // #8757 void garbageCode200() { - ASSERT_THROW(checkCode("(){e break,{(case)!{e:[]}}}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("(){e break,{(case)!{e:[]}}}"), SYNTAX); } // #8873 void garbageCode201() { - ASSERT_THROW(checkCode("void f() { std::string s=\"abc\"; return s + }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f() { std::string s=\"abc\"; return s + }"), SYNTAX); } // #8907 void garbageCode202() { - ASSERT_THROW(checkCode("void f() { UNKNOWN_MACRO(return); }"), InternalError); - ASSERT_THROW(checkCode("void f() { UNKNOWN_MACRO(throw); }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("void f() { UNKNOWN_MACRO(return); }"), UNKNOWN_MACRO); + ASSERT_THROW_INTERNAL(checkCode("void f() { UNKNOWN_MACRO(throw); }"), UNKNOWN_MACRO); } void garbageCode203() { // #8972 - ASSERT_THROW(checkCode("{ > () {} }"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{ > () {} }"), SYNTAX); checkCode("template <> a > ::b();"); } void garbageCode204() { - ASSERT_THROW(checkCode("template ()> c; template a as() {} as>();"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("template ()> c; template a as() {} as>();"), SYNTAX); } void garbageCode205() { - ASSERT_THROW(checkCode("class CodeSnippetsEvent : public wxCommandEvent {\n" - "public :\n" - " CodeSnippetsEvent ( wxEventType commandType = wxEventType , int id = 0 ) ;\n" - " CodeSnippetsEvent ( const CodeSnippetsEvent & event ) ;\n" - "virtual wxEvent * Clone ( ) const { return new CodeSnippetsEvent ( * this ) ; }\n" - "private :\n" - " int m_SnippetID ;\n" - "} ;\n" - "const wxEventType wxEVT_CODESNIPPETS_GETFILELINKS = wxNewEventType ( )\n" - "CodeSnippetsEvent :: CodeSnippetsEvent ( wxEventType commandType , int id )\n" - ": wxCommandEvent ( commandType , id ) {\n" - "}\n" - "CodeSnippetsEvent :: CodeSnippetsEvent ( const CodeSnippetsEvent & Event )\n" - ": wxCommandEvent ( Event )\n" - ", m_SnippetID ( 0 ) {\n" - "}"), - InternalError); + ASSERT_THROW_INTERNAL(checkCode("class CodeSnippetsEvent : public wxCommandEvent {\n" + "public :\n" + " CodeSnippetsEvent ( wxEventType commandType = wxEventType , int id = 0 ) ;\n" + " CodeSnippetsEvent ( const CodeSnippetsEvent & event ) ;\n" + "virtual wxEvent * Clone ( ) const { return new CodeSnippetsEvent ( * this ) ; }\n" + "private :\n" + " int m_SnippetID ;\n" + "} ;\n" + "const wxEventType wxEVT_CODESNIPPETS_GETFILELINKS = wxNewEventType ( )\n" + "CodeSnippetsEvent :: CodeSnippetsEvent ( wxEventType commandType , int id )\n" + ": wxCommandEvent ( commandType , id ) {\n" + "}\n" + "CodeSnippetsEvent :: CodeSnippetsEvent ( const CodeSnippetsEvent & Event )\n" + ": wxCommandEvent ( Event )\n" + ", m_SnippetID ( 0 ) {\n" + "}"), + INTERNAL); } void garbageCode206() { @@ -1670,31 +1670,31 @@ class TestGarbage : public TestFixture { } void garbageCode207() { // #8750 - ASSERT_THROW(checkCode("d f(){(.n00e0(return%n00e0''('')));}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("d f(){(.n00e0(return%n00e0''('')));}"), SYNTAX); } void garbageCode208() { // #8753 - ASSERT_THROW(checkCode("d f(){(for(((((0{t b;((((((((()))))))))}))))))}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("d f(){(for(((((0{t b;((((((((()))))))))}))))))}"), SYNTAX); } void garbageCode209() { // #8756 - ASSERT_THROW(checkCode("{(- -##0xf/-1 0)[]}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{(- -##0xf/-1 0)[]}"), SYNTAX); } void garbageCode210() { // #8762 - ASSERT_THROW(checkCode("{typedef typedef c n00e0[]c000(;n00e0&c000)}"), InternalError); + ASSERT_THROW_INTERNAL(checkCode("{typedef typedef c n00e0[]c000(;n00e0&c000)}"), SYNTAX); } void garbageCode211() { // #8764 - ASSERT_THROW(checkCode("{typedef f typedef[]({typedef e e,>;typedef(((typedef;typedef(((typedef\n"), InternalError); // don't crash + ASSERT_THROW_INTERNAL(checkCode("template\n"), SYNTAX); // don't crash } void garbageCode223() { // #11639 - ASSERT_THROW(checkCode("struct{}*"), InternalError); // don't crash + ASSERT_THROW_INTERNAL(checkCode("struct{}*"), SYNTAX); // don't crash } void garbageCode224() { - ASSERT_THROW(checkCode("void f(){ auto* b = dynamic_cast (size_t); foo) { } *(*const (size_t)() ; foo) { }"), InternalError); // #6858 - ASSERT_THROW(checkCode(">{ x while (y) z int = }"), InternalError); // #4175 - ASSERT_THROW(checkCode("&p(!{}e x){({(0?:?){({})}()})}"), InternalError); // #7118 - ASSERT_THROW(checkCode(" { struct { typename D4:typename Base }; };"), InternalError); // #3533 - ASSERT_THROW(checkCode(" > template < . > struct Y < T > { = } ;\n"), InternalError); // #6108 + ASSERT_THROW_INTERNAL(checkCode("&operator(){[]};"), SYNTAX); // #7818 + ASSERT_THROW_INTERNAL(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { }"), SYNTAX); // #6858 + ASSERT_THROW_INTERNAL(checkCode(">{ x while (y) z int = }"), SYNTAX); // #4175 + ASSERT_THROW_INTERNAL(checkCode("&p(!{}e x){({(0?:?){({})}()})}"), SYNTAX); // #7118 + ASSERT_THROW_INTERNAL(checkCode(" { struct { typename D4:typename Base }; };"), SYNTAX); // #3533 + ASSERT_THROW_INTERNAL(checkCode(" > template < . > struct Y < T > { = } ;\n"), SYNTAX); // #6108 } void syntaxErrorLastToken() { - 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 : \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\n"), InternalError); // #2967 - ASSERT_THROW(checkCode("char a[1]\n"), InternalError); // #2865 - ASSERT_THROW(checkCode("<><<"), InternalError); // #2612 - ASSERT_THROW(checkCode("z"), InternalError); // #2831 - ASSERT_THROW(checkCode("><,f\n"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("++4++ + + E++++++++++ + ch " "tp.oed5[.]"), SYNTAX); // #7074 + ASSERT_THROW_INTERNAL(checkCode("d a(){f s=0()8[]s?():0}*()?:0", false), SYNTAX); // #7236 + ASSERT_THROW_INTERNAL(checkCode("!2 : #h2 ?:", false), SYNTAX); // #7769 + ASSERT_THROW_INTERNAL(checkCode("--"), SYNTAX); + ASSERT_THROW_INTERNAL(checkCode("volatile true , test < test < #ifdef __ppc__ true ,"), SYNTAX); // #4169 + ASSERT_THROW_INTERNAL(checkCode("a,b--\n"), SYNTAX); // #2847 + ASSERT_THROW_INTERNAL(checkCode("x a[0] ="), SYNTAX); // #2682 + ASSERT_THROW_INTERNAL(checkCode("auto_ptr\n"), SYNTAX); // #2967 + ASSERT_THROW_INTERNAL(checkCode("char a[1]\n"), SYNTAX); // #2865 + ASSERT_THROW_INTERNAL(checkCode("<><<"), SYNTAX); // #2612 + ASSERT_THROW_INTERNAL(checkCode("z"), SYNTAX); // #2831 + ASSERT_THROW_INTERNAL(checkCode("><,f typedef name5 | ( , ;){ } (); }"), InternalError); // #9067 - ASSERT_THROW(checkCode("void f() { x= {}( ) ( 'x')[ ] (); }"), InternalError); // #9068 - ASSERT_THROW(checkCode("void f() { x= y{ } name5 y[ ] + y ^ name5 ^ name5 for ( ( y y y && y y y && name5 ++ int )); }"), InternalError); // #9069 + ASSERT_THROW_INTERNAL(checkCode("void f() { x= 'x' > typedef name5 | ( , ;){ } (); }"), SYNTAX); // #9067 + ASSERT_THROW_INTERNAL(checkCode("void f() { x= {}( ) ( 'x')[ ] (); }"), SYNTAX); // #9068 + ASSERT_THROW_INTERNAL(checkCode("void f() { x= y{ } name5 y[ ] + y ^ name5 ^ name5 for ( ( y y y && y y y && name5 ++ int )); }"), SYNTAX); // #9069 } void cliCode() { @@ -1836,7 +1836,7 @@ class TestGarbage : public TestFixture { } void enumTrailingComma() { - ASSERT_THROW(checkCode("enum ssl_shutdown_t {ssl_shutdown_none = 0,ssl_shutdown_close_notify = , } ;"), InternalError); // #8079 + ASSERT_THROW_INTERNAL(checkCode("enum ssl_shutdown_t {ssl_shutdown_none = 0,ssl_shutdown_close_notify = , } ;"), SYNTAX); // #8079 } void nonGarbageCode1() { diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index df09e4e8c6f..9208ad53b8e 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -3090,14 +3090,14 @@ class TestLeakAutoVarRecursiveCountLimit : public TestFixture { } void recursiveCountLimit() { // #5872 #6157 #9097 - ASSERT_THROW(checkP("#define ONE else if (0) { }\n" - "#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n" - "#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n" - "#define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN\n" - "void foo() {\n" - " if (0) { }\n" - " THOU THOU\n" - "}"), InternalError); + ASSERT_THROW_INTERNAL(checkP("#define ONE else if (0) { }\n" + "#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n" + "#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n" + "#define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN\n" + "void foo() {\n" + " if (0) { }\n" + " THOU THOU\n" + "}"), LIMIT); ASSERT_NO_THROW(checkP("#define ONE if (0) { }\n" "#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n" "#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n" diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 56644cb4396..b541457b62b 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -887,7 +887,7 @@ class TestSimplifyTemplate : public TestFixture { void template27() { // #3350 - template inside macro call const char code[] = "X(template class Fred);"; - ASSERT_THROW(tok(code), InternalError); + ASSERT_THROW_INTERNAL(tok(code), SYNTAX); } void template28() { @@ -1108,7 +1108,7 @@ class TestSimplifyTemplate : public TestFixture { " return sizeof...(args);\n" " }();\n" "}"; - ASSERT_THROW(tok(code), InternalError); + ASSERT_THROW_INTERNAL(tok(code), SYNTAX); } void template43() { // #5097 - Assert due to '>>' in 'B>' not being treated as end of template instantiation @@ -3059,14 +3059,14 @@ class TestSimplifyTemplate : public TestFixture { } void template125() { - ASSERT_THROW(tok("template\n" - "class GCD {\n" - "public:\n" - " enum { val = (N == 0) ? M : GCD::val };\n" - "};\n" - "int main() {\n" - " GCD< 1, 0 >::val;\n" - "}"), InternalError); + ASSERT_THROW_INTERNAL(tok("template\n" + "class GCD {\n" + "public:\n" + " enum { val = (N == 0) ? M : GCD::val };\n" + "};\n" + "int main() {\n" + " GCD< 1, 0 >::val;\n" + "}"), INSTANTIATION); } void template126() { // #9217 @@ -4952,15 +4952,15 @@ class TestSimplifyTemplate : public TestFixture { ASSERT_EQUALS("", errout_str()); // bad code.. missing ">" - ASSERT_THROW(tok("x xyz;\n"), InternalError); + ASSERT_THROW_INTERNAL(tok("x xyz;\n"), SYNTAX); // bad code - ASSERT_THROW(tok("typedef\n" - " typename boost::mpl::if_c<\n" - " _visitableIndex < boost::mpl::size< typename _Visitables::ConcreteVisitables >::value\n" - " , ConcreteVisitable\n" - " , Dummy< _visitableIndex >\n" - " >::type ConcreteVisitableOrDummy;\n"), InternalError); + ASSERT_THROW_INTERNAL(tok("typedef\n" + " typename boost::mpl::if_c<\n" + " _visitableIndex < boost::mpl::size< typename _Visitables::ConcreteVisitables >::value\n" + " , ConcreteVisitable\n" + " , Dummy< _visitableIndex >\n" + " >::type ConcreteVisitableOrDummy;\n"), SYNTAX); // code is ok, don't show syntax error tok("struct A {int a;int b};\n" diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index e49771b81a9..a4fc279427f 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -1613,7 +1613,7 @@ class TestSimplifyTokens : public TestFixture { void simplifyKnownVariables16() { // ticket #807 - segmentation fault when macro isn't found const char code[] = "void f ( ) { int n = 1; DISPATCH(while); }"; - ASSERT_THROW(simplifyKnownVariables(code), InternalError); + ASSERT_THROW_INTERNAL(simplifyKnownVariables(code), UNKNOWN_MACRO); } void simplifyKnownVariables17() { @@ -2266,7 +2266,7 @@ class TestSimplifyTokens : public TestFixture { " BENCH1(q = _mhz_M(n); n = 1;)\n" " use_pointer(q);\n" "}"; - ASSERT_THROW(tokenizeAndStringify(code, true), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify(code, true), UNKNOWN_MACRO); } void simplifyKnownVariables54() { // #4913 diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 88dad9f0674..955c5982a56 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -1755,7 +1755,7 @@ class TestSimplifyTypedef : public TestFixture { "LOCAL(type1) foo() { }"; // this is invalid C, assert that an "unknown macro" warning is written - ASSERT_THROW(checkSimplifyTypedef(code), InternalError); + ASSERT_THROW_INTERNAL(checkSimplifyTypedef(code), UNKNOWN_MACRO); } } @@ -2121,7 +2121,7 @@ class TestSimplifyTypedef : public TestFixture { } void simplifyTypedef76() { // ticket #2453 segmentation fault - ASSERT_THROW(checkSimplifyTypedef("void f1(typedef int x) {}"), InternalError); + ASSERT_THROW_INTERNAL(checkSimplifyTypedef("void f1(typedef int x) {}"), SYNTAX); } void simplifyTypedef77() { // ticket #2554 @@ -2166,9 +2166,9 @@ class TestSimplifyTypedef : public TestFixture { } void simplifyTypedef81() { // ticket #2603 segmentation fault - ASSERT_THROW(checkSimplifyTypedef("typedef\n"), InternalError); + ASSERT_THROW_INTERNAL(checkSimplifyTypedef("typedef\n"), SYNTAX); - ASSERT_THROW(checkSimplifyTypedef("typedef constexpr\n"), InternalError); + ASSERT_THROW_INTERNAL(checkSimplifyTypedef("typedef constexpr\n"), SYNTAX); } void simplifyTypedef82() { // ticket #2403 @@ -2200,13 +2200,13 @@ class TestSimplifyTypedef : public TestFixture { void simplifyTypedef84() { // ticket #2630 (segmentation fault) const char code1[] = "typedef y x () x"; - ASSERT_THROW(checkSimplifyTypedef(code1), InternalError); + ASSERT_THROW_INTERNAL(checkSimplifyTypedef(code1), SYNTAX); const char code2[] = "typedef struct template <>"; - ASSERT_THROW(checkSimplifyTypedef(code2), InternalError); + ASSERT_THROW_INTERNAL(checkSimplifyTypedef(code2), SYNTAX); const char code3[] = "typedef ::<>"; - ASSERT_THROW(checkSimplifyTypedef(code3), InternalError); + ASSERT_THROW_INTERNAL(checkSimplifyTypedef(code3), SYNTAX); } void simplifyTypedef85() { // ticket #2651 @@ -2444,7 +2444,7 @@ class TestSimplifyTypedef : public TestFixture { void simplifyTypedef96() { // ticket #2886 (segmentation fault) const char code[] = "typedef struct x { }"; - ASSERT_THROW(tok(code), InternalError); + ASSERT_THROW_INTERNAL(tok(code), SYNTAX); } void simplifyTypedef97() { // ticket #2983 (segmentation fault) @@ -2511,12 +2511,12 @@ class TestSimplifyTypedef : public TestFixture { void simplifyTypedef105() { // ticket #3616 (segmentation fault) const char code[] = "( int typedef char x; ){}"; - ASSERT_THROW(tok(code), InternalError); + ASSERT_THROW_INTERNAL(tok(code), SYNTAX); } void simplifyTypedef106() { // ticket #3619 (segmentation fault) const char code[] = "typedef void f ();\ntypedef { f }"; - ASSERT_THROW(tok(code), InternalError); + ASSERT_THROW_INTERNAL(tok(code), INTERNAL); } void simplifyTypedef107() { // ticket #3963 (bad code => segmentation fault) diff --git a/test/teststl.cpp b/test/teststl.cpp index 48f4f09b451..4a39b9a1fa2 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -3619,10 +3619,10 @@ class TestStl : public TestFixture { ASSERT_EQUALS("", errout_str()); // #3714 - segmentation fault for syntax error - ASSERT_THROW(check("void f() {\n" - " if (()) { }\n" - "}"), - InternalError); + ASSERT_THROW_INTERNAL(check("void f() {\n" + " if (()) { }\n" + "}"), + AST); // #3865 check("void f() {\n" diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index a9860efd227..ebe28bdb9f9 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -3257,9 +3257,9 @@ class TestSymbolDatabase : public TestFixture { void symboldatabase5() { // ticket #2178 - segmentation fault - ASSERT_THROW(check("int CL_INLINE_DECL(integer_decode_float) (int x) {\n" - " return (sign ? cl_I() : 0);\n" - "}"), InternalError); + ASSERT_THROW_INTERNAL(check("int CL_INLINE_DECL(integer_decode_float) (int x) {\n" + " return (sign ? cl_I() : 0);\n" + "}"), UNKNOWN_MACRO); } void symboldatabase6() { @@ -3360,7 +3360,7 @@ class TestSymbolDatabase : public TestFixture { void symboldatabase14() { // ticket #2589 - segmentation fault - ASSERT_THROW(check("struct B : A\n"), InternalError); + ASSERT_THROW_INTERNAL(check("struct B : A\n"), SYNTAX); } void symboldatabase17() { @@ -3382,7 +3382,7 @@ class TestSymbolDatabase : public TestFixture { void symboldatabase20() { // ticket #3013 - segmentation fault - ASSERT_THROW(check("struct x : virtual y\n"), InternalError); + ASSERT_THROW_INTERNAL(check("struct x : virtual y\n"), SYNTAX); } void symboldatabase21() { diff --git a/test/testtoken.cpp b/test/testtoken.cpp index a57ef81806b..a456e667168 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -665,7 +665,7 @@ class TestToken : public TestFixture { const SimpleTokenizer var(*this, "int a ; int b ;"); // Varid == 0 should throw exception - ASSERT_THROW((void)Token::Match(var.tokens(), "%type% %varid% ; %type% %name%", 0),InternalError); + ASSERT_THROW_INTERNAL((void)Token::Match(var.tokens(), "%type% %varid% ; %type% %name%", 0),INTERNAL); ASSERT_EQUALS(true, Token::Match(var.tokens(), "%type% %varid% ; %type% %name%", 1)); ASSERT_EQUALS(true, Token::Match(var.tokens(), "%type% %name% ; %type% %varid%", 2)); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index c60cc947901..f2b91b8118f 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -573,7 +573,7 @@ class TestTokenizer : public TestFixture { "-(Foo *)foo: (Bar *)bar\n" "{ }\n" "@end\n"; - ASSERT_THROW(tokenizeAndStringify(code), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify(code), SYNTAX); } // Ticket #2361: 0X10 => 16 @@ -611,7 +611,7 @@ class TestTokenizer : public TestFixture { void tokenize19() { // #3006 - added hasComplicatedSyntaxErrorsInTemplates to avoid segmentation fault - ASSERT_THROW(tokenizeAndStringify("x < () <"), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify("x < () <"), SYNTAX); // #3496 - make sure hasComplicatedSyntaxErrorsInTemplates works ASSERT_EQUALS("void a ( Fred * f ) { for ( ; n < f . x ( ) ; ) { } }", @@ -649,12 +649,12 @@ class TestTokenizer : public TestFixture { // #4239 - segfault for "f ( struct { int typedef T x ; } ) { }" void tokenize25() { - ASSERT_THROW(tokenizeAndStringify("f ( struct { int typedef T x ; } ) { }"), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify("f ( struct { int typedef T x ; } ) { }"), SYNTAX); } // #4245 - segfault void tokenize26() { - ASSERT_THROW(tokenizeAndStringify("class x { protected : template < int y = } ;"), InternalError); // Garbage code + ASSERT_THROW_INTERNAL(tokenizeAndStringify("class x { protected : template < int y = } ;"), SYNTAX); // Garbage code } void tokenize27() { @@ -783,15 +783,15 @@ class TestTokenizer : public TestFixture { void validate() { // C++ code in C file - ASSERT_THROW(tokenizeAndStringify(";using namespace std;",false,Platform::Type::Native,"test.c"), InternalError); - ASSERT_THROW(tokenizeAndStringify(";std::map m;",false,Platform::Type::Native,"test.c"), InternalError); - ASSERT_THROW(tokenizeAndStringify(";template class X { };",false,Platform::Type::Native,"test.c"), InternalError); - ASSERT_THROW(tokenizeAndStringify("int X() {};",false,Platform::Type::Native,"test.c"), InternalError); - ASSERT_THROW(tokenizeAndStringify("void foo(int i) { reinterpret_cast(i) };",false,Platform::Type::Native,"test.h"), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify(";using namespace std;",false,Platform::Type::Native,"test.c"), SYNTAX); + ASSERT_THROW_INTERNAL(tokenizeAndStringify(";std::map m;",false,Platform::Type::Native,"test.c"), SYNTAX); + ASSERT_THROW_INTERNAL(tokenizeAndStringify(";template class X { };",false,Platform::Type::Native,"test.c"), SYNTAX); + ASSERT_THROW_INTERNAL(tokenizeAndStringify("int X() {};",false,Platform::Type::Native,"test.c"), SYNTAX); + ASSERT_THROW_INTERNAL(tokenizeAndStringify("void foo(int i) { reinterpret_cast(i) };",false,Platform::Type::Native,"test.h"), SYNTAX); } void objectiveC() { - ASSERT_THROW(tokenizeAndStringify("void f() { [foo bar]; }"), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify("void f() { [foo bar]; }"), SYNTAX); } void syntax_case_default() { // correct syntax @@ -1108,7 +1108,7 @@ class TestTokenizer : public TestFixture { " for (int k=0; kb1, C = :c::c1;")); } @@ -5421,10 +5421,10 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("namespace { int a ; }", tokenizeAndStringify("ABA() namespace { int a ; }")); // #3750 - ASSERT_THROW(tokenizeAndStringify("; AB(foo*) foo::foo() { }"), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify("; AB(foo*) foo::foo() { }"), UNKNOWN_MACRO); // #4834 - syntax error - ASSERT_THROW(tokenizeAndStringify("A(B) foo() {}"), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify("A(B) foo() {}"), UNKNOWN_MACRO); // #3855 ASSERT_EQUALS("; class foo { }", @@ -5438,14 +5438,14 @@ class TestTokenizer : public TestFixture { " int x;\n" "};")); - ASSERT_THROW(tokenizeAndStringify("MACRO(test) void test() { }"), InternalError); // #7931 + ASSERT_THROW_INTERNAL(tokenizeAndStringify("MACRO(test) void test() { }"), UNKNOWN_MACRO); // #7931 - ASSERT_THROW(tokenizeAndStringify("BEGIN_MESSAGE_MAP(CSetProgsAdvDlg, CResizableStandAloneDialog)\n" - " ON_BN_CLICKED(IDC_ADDTOOL, OnBnClickedAddtool)\n" - "END_MESSAGE_MAP()\n" - "\n" - "BOOL CSetProgsAdvDlg::OnInitDialog() {}"), - InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify("BEGIN_MESSAGE_MAP(CSetProgsAdvDlg, CResizableStandAloneDialog)\n" + " ON_BN_CLICKED(IDC_ADDTOOL, OnBnClickedAddtool)\n" + "END_MESSAGE_MAP()\n" + "\n" + "BOOL CSetProgsAdvDlg::OnInitDialog() {}"), + UNKNOWN_MACRO); ASSERT_EQUALS("struct S {\n" "S ( ) : p { new ( malloc ( 4 ) ) int { } } { }\n" @@ -6894,7 +6894,7 @@ class TestTokenizer : public TestFixture { const std::string filedata = tokens1.stringify(); const std::string code = PreprocessorHelper::getcode(preprocessor, filedata, emptyString, emptyString); - ASSERT_THROW(tokenizeAndStringify(code.c_str()), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify(code.c_str()), AST); } #define isStartOfExecutableScope(offset, code) isStartOfExecutableScope_(offset, code, __FILE__, __LINE__) @@ -6948,47 +6948,47 @@ class TestTokenizer : public TestFixture { void reportUnknownMacros() { const char code1[] = "MY_UNKNOWN_IMP1(IInStream)\n" "STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) { if (ptr); }"; - ASSERT_THROW(tokenizeAndStringify(code1), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify(code1), UNKNOWN_MACRO); const char code2[] = "void foo() { dostuff(x 0); }"; - ASSERT_THROW(tokenizeAndStringify(code2), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify(code2), UNKNOWN_MACRO); const char code3[] = "f(\"1\" __stringify(48) \"1\");"; - ASSERT_THROW(tokenizeAndStringify(code3), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify(code3), UNKNOWN_MACRO); const char code4[] = "struct Foo {\n" " virtual MACRO(int) f1() {}\n" " virtual MACRO(int) f2() {}\n" "};"; - ASSERT_THROW(tokenizeAndStringify(code4), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify(code4), UNKNOWN_MACRO); const char code5[] = "void foo() {\n" " EVALUATE(123, int x=a; int y=b+c;);\n" "}"; - ASSERT_THROW(tokenizeAndStringify(code5), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify(code5), UNKNOWN_MACRO); const char code6[] = "void foo() { dostuff(a, .x=0); }"; - ASSERT_THROW(tokenizeAndStringify(code6), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify(code6), UNKNOWN_MACRO); const char code7[] = "void foo() { dostuff(ZEND_NUM_ARGS() TSRMLS_CC, x, y); }"; // #9476 - ASSERT_THROW(tokenizeAndStringify(code7), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify(code7), UNKNOWN_MACRO); const char code8[] = "void foo() { a = [](int x, decltype(vec) y){}; }"; ASSERT_NO_THROW(tokenizeAndStringify(code8)); const char code9[] = "void f(std::exception c) { b(M() c.what()); }"; - ASSERT_THROW(tokenizeAndStringify(code9), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify(code9), UNKNOWN_MACRO); const char code10[] = "void f(std::exception c) { b(M() M() + N(c.what())); }"; - ASSERT_THROW(tokenizeAndStringify(code10), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify(code10), UNKNOWN_MACRO); const char code11[] = "struct B { B(B&&) noexcept {} ~B() noexcept {} };"; ASSERT_NO_THROW(tokenizeAndStringify(code11)); ASSERT_NO_THROW(tokenizeAndStringify("alignas(8) alignas(16) int x;")); // alignas is not unknown macro - ASSERT_THROW(tokenizeAndStringify("void foo() { if(x) SYSTEM_ERROR }"), InternalError); - ASSERT_THROW(tokenizeAndStringify("void foo() { dostuff(); SYSTEM_ERROR }"), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify("void foo() { if(x) SYSTEM_ERROR }"), UNKNOWN_MACRO); + ASSERT_THROW_INTERNAL(tokenizeAndStringify("void foo() { dostuff(); SYSTEM_ERROR }"), UNKNOWN_MACRO); ASSERT_NO_THROW(tokenizeAndStringify("void f(void* q) {\n" " g(&(S) { .p = (int*)q });\n" @@ -6999,10 +6999,10 @@ class TestTokenizer : public TestFixture { "S s = (S){ .i = (int)a };\n" "}\n", /*expand*/ true, Platform::Type::Native, "test.c")); - ASSERT_THROW(tokenizeAndStringify("std::string g();\n" - "std::string f() {\n" - " return std::string{ g() + \"abc\" MACRO \"def\" };\n" - "}\n", /*expand*/ true, Platform::Type::Native, "test.cpp"), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify("std::string g();\n" + "std::string f() {\n" + " return std::string{ g() + \"abc\" MACRO \"def\" };\n" + "}\n", /*expand*/ true, Platform::Type::Native, "test.cpp"), UNKNOWN_MACRO); } void findGarbageCode() { // Test Tokenizer::findGarbageCode() @@ -7029,10 +7029,10 @@ class TestTokenizer : public TestFixture { ASSERT_NO_THROW(tokenizeAndStringify("void f() { []() -> int * {}; }")); ASSERT_NO_THROW(tokenizeAndStringify("void f() { const char* var = \"1\" \"2\"; }")); - ASSERT_THROW(tokenizeAndStringify("void f() { MACRO(switch); }"), InternalError); - ASSERT_THROW(tokenizeAndStringify("void f() { MACRO(x,switch); }"), InternalError); - ASSERT_THROW(tokenizeAndStringify("void foo() { for_chain( if (!done) done = 1); }"), InternalError); - ASSERT_THROW(tokenizeAndStringify("void foo() { for_chain( a, b, if (!done) done = 1); }"), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify("void f() { MACRO(switch); }"), UNKNOWN_MACRO); + ASSERT_THROW_INTERNAL(tokenizeAndStringify("void f() { MACRO(x,switch); }"), UNKNOWN_MACRO); + ASSERT_THROW_INTERNAL(tokenizeAndStringify("void foo() { for_chain( if (!done) done = 1); }"), UNKNOWN_MACRO); + ASSERT_THROW_INTERNAL(tokenizeAndStringify("void foo() { for_chain( a, b, if (!done) done = 1); }"), UNKNOWN_MACRO); ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { if (retval==){} }"), InternalError, "syntax error: ==)"); @@ -7149,7 +7149,7 @@ class TestTokenizer : public TestFixture { InternalError, "There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it."); - ASSERT_THROW(tokenizeAndStringify("{ for (()()) }"), InternalError); // #11643 + ASSERT_THROW_INTERNAL(tokenizeAndStringify("{ for (()()) }"), SYNTAX); // #11643 ASSERT_NO_THROW(tokenizeAndStringify("S* g = ::new(ptr) S();")); // #12552 ASSERT_NO_THROW(tokenizeAndStringify("void f(int* p) { return ::delete p; }")); @@ -7658,9 +7658,9 @@ class TestTokenizer : public TestFixture { } void noCrash7() { - ASSERT_THROW(tokenizeAndStringify("void g() {\n"// TODO: don't throw - " for (using T = int; (T)false;) {}\n" // C++23 P2360R0: Extend init-statement to allow alias-declaration - "}\n"), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify("void g() {\n"// TODO: don't throw + " for (using T = int; (T)false;) {}\n" // C++23 P2360R0: Extend init-statement to allow alias-declaration + "}\n"), SYNTAX); } void checkConfig(const char code[]) { @@ -7699,7 +7699,7 @@ class TestTokenizer : public TestFixture { } void unknownMacroBeforeReturn() { - ASSERT_THROW(tokenizeAndStringify("int f() { X return 0; }"), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify("int f() { X return 0; }"), UNKNOWN_MACRO); } void cppcast() { @@ -7837,7 +7837,7 @@ class TestTokenizer : public TestFixture { const char code[] = "struct S { int a:2 = 0; };"; ASSERT_EQUALS("struct S { int a ; a = 0 ; } ;", tokenizeAndStringify(code, s1)); const Settings s2 = settingsBuilder().cpp(Standards::CPP17).build(); - ASSERT_THROW(tokenizeAndStringify(code, s2), InternalError); + ASSERT_THROW_INTERNAL(tokenizeAndStringify(code, s2), SYNTAX); } void cpp11init() { diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 3ce6c654036..5df7a444900 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -3535,10 +3535,10 @@ class TestUninitVar : public TestFixture { "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: a\n", errout_str()); - ASSERT_THROW(checkUninitVar("void f() {\n" // Don't crash - " int a;\n" - " dostuff(\"ab\" cd \"ef\", x?a:z);\n" // <- No AST is created for ? - "}"), InternalError); + ASSERT_THROW_INTERNAL(checkUninitVar("void f() {\n" // Don't crash + " int a;\n" + " dostuff(\"ab\" cd \"ef\", x?a:z);\n" // <- No AST is created for ? + "}"), UNKNOWN_MACRO); // Unknown => bail out.. checkUninitVar("void f(int x) {\n" @@ -3657,10 +3657,10 @@ class TestUninitVar : public TestFixture { "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Uninitialized variable: a\n", errout_str()); - ASSERT_THROW(valueFlowUninit("void f() {\n" // Don't crash - " int a;\n" - " dostuff(\"ab\" cd \"ef\", x?a:z);\n" // <- No AST is created for ? - "}"), InternalError); + ASSERT_THROW_INTERNAL(valueFlowUninit("void f() {\n" // Don't crash + " int a;\n" + " dostuff(\"ab\" cd \"ef\", x?a:z);\n" // <- No AST is created for ? + "}"), UNKNOWN_MACRO); // Unknown => bail out.. valueFlowUninit("void f(int x) {\n" @@ -5401,7 +5401,7 @@ class TestUninitVar : public TestFixture { " struct cgroup_taskset tset = { };\n" " do { } while_each_thread(leader, tsk);\n" "}"; - ASSERT_THROW(checkUninitVar(code), InternalError); + ASSERT_THROW_INTERNAL(checkUninitVar(code), SYNTAX); } void trac_5970() { // Ticket #5970 diff --git a/test/testvarid.cpp b/test/testvarid.cpp index a6e5e132042..55899d38357 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -751,7 +751,7 @@ class TestVarID : public TestFixture { } void varid28() { // ticket #2630 (segmentation fault) - ASSERT_THROW(tokenize("template \n"), InternalError); + ASSERT_THROW_INTERNAL(tokenize("template \n"), SYNTAX); } void varid29() { @@ -908,12 +908,12 @@ class TestVarID : public TestFixture { const char code1[] = "union evt; void f(const evt & event);"; ASSERT_EQUALS("1: union evt ; void f ( const evt & event@1 ) ;\n", tokenize(code1)); - ASSERT_THROW(tokenize(code1, "test.c"), InternalError); + ASSERT_THROW_INTERNAL(tokenize(code1, "test.c"), SYNTAX); const char code2[] = "struct evt; void f(const evt & event);"; ASSERT_EQUALS("1: struct evt ; void f ( const evt & event@1 ) ;\n", tokenize(code2)); - ASSERT_THROW(tokenize(code2, "test.c"), InternalError); + ASSERT_THROW_INTERNAL(tokenize(code2, "test.c"), SYNTAX); } void varid42() { From 82a4220818588df03743bd4a4321e22b55bb5e1d Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 10 Apr 2024 09:40:12 +0200 Subject: [PATCH 2/2] testrunner: added `ASSERT_THROW_INTERNAL_EQUALS` --- test/fixture.h | 1 + test/testerrorlogger.cpp | 14 +++--- test/testgarbage.cpp | 8 +-- test/testleakautovar.cpp | 16 +++--- test/testmathlib.cpp | 94 +++++++++++++++++------------------ test/testsimplifytemplate.cpp | 2 +- test/testsimplifytypedef.cpp | 2 +- test/testtoken.cpp | 2 +- test/testtokenize.cpp | 50 +++++++++---------- 9 files changed, 95 insertions(+), 94 deletions(-) diff --git a/test/fixture.h b/test/fixture.h index ab1e1ecdfdf..feda9caf540 100644 --- a/test/fixture.h +++ b/test/fixture.h @@ -300,6 +300,7 @@ class TestFixture : public ErrorLogger { #define ASSERT_THROW_EQUALS( CMD, EXCEPTION, EXPECTED ) do { try { CMD; assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&e) { assertEquals(__FILE__, __LINE__, EXPECTED, e.errorMessage); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) #define ASSERT_THROW_EQUALS_2( CMD, EXCEPTION, EXPECTED ) do { try { CMD; assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&e) { assertEquals(__FILE__, __LINE__, EXPECTED, e.what()); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) #define ASSERT_THROW_INTERNAL( CMD, TYPE ) do { try { CMD; assertThrowFail(__FILE__, __LINE__); } catch (const InternalError& e) { assertEqualsEnum(__FILE__, __LINE__, InternalError::TYPE, e.type); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) +#define ASSERT_THROW_INTERNAL_EQUALS( CMD, TYPE, EXPECTED ) do { try { CMD; assertThrowFail(__FILE__, __LINE__); } catch (const InternalError& e) { assertEqualsEnum(__FILE__, __LINE__, InternalError::TYPE, e.type); assertEquals(__FILE__, __LINE__, EXPECTED, e.errorMessage); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) #define ASSERT_NO_THROW( CMD ) do { try { CMD; } catch (...) { assertNoThrowFail(__FILE__, __LINE__); } } while (false) #define TODO_ASSERT_THROW( CMD, EXCEPTION ) do { try { CMD; } catch (const EXCEPTION&) {} catch (...) { assertThrow(__FILE__, __LINE__); } } while (false) #define TODO_ASSERT( CONDITION ) do { const bool condition=(CONDITION); todoAssertEquals(__FILE__, __LINE__, true, false, condition); } while (false) diff --git a/test/testerrorlogger.cpp b/test/testerrorlogger.cpp index f7d5c11f794..49da36cfa6b 100644 --- a/test/testerrorlogger.cpp +++ b/test/testerrorlogger.cpp @@ -348,22 +348,22 @@ class TestErrorLogger : public TestFixture { // missing/invalid length // missing separator ErrorMessage msg; - ASSERT_THROW_EQUALS(msg.deserialize("500foobar"), InternalError, "Internal Error: Deserialization of error message failed - invalid separator"); + ASSERT_THROW_INTERNAL_EQUALS(msg.deserialize("500foobar"), INTERNAL, "Internal Error: Deserialization of error message failed - invalid separator"); } { // invalid length ErrorMessage msg; - ASSERT_THROW_EQUALS(msg.deserialize("foo foobar"), InternalError, "Internal Error: Deserialization of error message failed - invalid length"); + ASSERT_THROW_INTERNAL_EQUALS(msg.deserialize("foo foobar"), INTERNAL, "Internal Error: Deserialization of error message failed - invalid length"); } { // mismatching length ErrorMessage msg; - ASSERT_THROW_EQUALS(msg.deserialize("8 errorId"), InternalError, "Internal Error: Deserialization of error message failed - premature end of data"); + ASSERT_THROW_INTERNAL_EQUALS(msg.deserialize("8 errorId"), INTERNAL, "Internal Error: Deserialization of error message failed - premature end of data"); } { // incomplete message ErrorMessage msg; - ASSERT_THROW_EQUALS(msg.deserialize("7 errorId"), InternalError, "Internal Error: Deserialization of error message failed - invalid length"); + ASSERT_THROW_INTERNAL_EQUALS(msg.deserialize("7 errorId"), INTERNAL, "Internal Error: Deserialization of error message failed - invalid length"); } { // invalid CWE ID @@ -376,7 +376,7 @@ class TestErrorLogger : public TestFixture { "17 Programming error" "0 "; ErrorMessage msg; - ASSERT_THROW_EQUALS(msg.deserialize(str), InternalError, "Internal Error: Deserialization of error message failed - invalid CWE ID - not an integer"); + ASSERT_THROW_INTERNAL_EQUALS(msg.deserialize(str), INTERNAL, "Internal Error: Deserialization of error message failed - invalid CWE ID - not an integer"); } { // invalid hash @@ -389,7 +389,7 @@ class TestErrorLogger : public TestFixture { "17 Programming error" "0 "; ErrorMessage msg; - ASSERT_THROW_EQUALS(msg.deserialize(str), InternalError, "Internal Error: Deserialization of error message failed - invalid hash - not an integer"); + ASSERT_THROW_INTERNAL_EQUALS(msg.deserialize(str), INTERNAL, "Internal Error: Deserialization of error message failed - invalid hash - not an integer"); } { // out-of-range CWE ID @@ -402,7 +402,7 @@ class TestErrorLogger : public TestFixture { "17 Programming error" "0 "; ErrorMessage msg; - ASSERT_THROW_INTERNAL(msg.deserialize(str), INTERNAL); + ASSERT_THROW_INTERNAL_EQUALS(msg.deserialize(str), INTERNAL, "Internal Error: Deserialization of error message failed - invalid CWE ID - out of range (limits)"); } } diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 3b52c7493e1..86757545194 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -868,10 +868,10 @@ class TestGarbage : public TestFixture { } void garbageCode99() { // #6726 - ASSERT_THROW_INTERNAL(checkCode("{ xs :: i(:) ! ! x/5 ! !\n" - "i, :: a :: b integer, } foo2(x) :: j(:)\n" - "b type(*), d(:), a x :: end d(..), foo end\n" - "foo4 b d(..), a a x type(*), b foo2 b"), INTERNAL); + ASSERT_THROW_INTERNAL_EQUALS(checkCode("{ xs :: i(:) ! ! x/5 ! !\n" + "i, :: a :: b integer, } foo2(x) :: j(:)\n" + "b type(*), d(:), a x :: end d(..), foo end\n" + "foo4 b d(..), a a x type(*), b foo2 b"), INTERNAL, "Internal error. AST cyclic dependency."); } void garbageCode100() { // #6840 diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 9208ad53b8e..2a7e6ed6d7c 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -3090,14 +3090,14 @@ class TestLeakAutoVarRecursiveCountLimit : public TestFixture { } void recursiveCountLimit() { // #5872 #6157 #9097 - ASSERT_THROW_INTERNAL(checkP("#define ONE else if (0) { }\n" - "#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n" - "#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n" - "#define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN\n" - "void foo() {\n" - " if (0) { }\n" - " THOU THOU\n" - "}"), LIMIT); + ASSERT_THROW_INTERNAL_EQUALS(checkP("#define ONE else if (0) { }\n" + "#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n" + "#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n" + "#define THOU HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN\n" + "void foo() {\n" + " if (0) { }\n" + " THOU THOU\n" + "}"), LIMIT, "Internal limit: CheckLeakAutoVar::checkScope() Maximum recursive count of 1000 reached."); ASSERT_NO_THROW(checkP("#define ONE if (0) { }\n" "#define TEN ONE ONE ONE ONE ONE ONE ONE ONE ONE ONE\n" "#define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN\n" diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index 1af3f7bd9d0..5973f670a9c 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -144,13 +144,13 @@ class TestMathLib : public TestFixture { ASSERT_EQUALS("5.0", MathLib::divide("25.5", "5.1")); ASSERT_EQUALS("7.0", MathLib::divide("21.", "3")); ASSERT_EQUALS("1", MathLib::divide("3", "2")); - ASSERT_THROW_EQUALS(MathLib::divide("123", "0"), InternalError, "Internal Error: Division by zero"); // decimal zero: throw - ASSERT_THROW_EQUALS(MathLib::divide("123", "00"), InternalError, "Internal Error: Division by zero"); // octal zero: throw - ASSERT_THROW_EQUALS(MathLib::divide("123", "0x0"), InternalError, "Internal Error: Division by zero"); // hex zero: throw + ASSERT_THROW_INTERNAL_EQUALS(MathLib::divide("123", "0"), INTERNAL, "Internal Error: Division by zero"); // decimal zero: throw + ASSERT_THROW_INTERNAL_EQUALS(MathLib::divide("123", "00"), INTERNAL, "Internal Error: Division by zero"); // octal zero: throw + ASSERT_THROW_INTERNAL_EQUALS(MathLib::divide("123", "0x0"), INTERNAL, "Internal Error: Division by zero"); // hex zero: throw MathLib::divide("123", "0.0f"); // float zero: don't throw MathLib::divide("123", "0.0"); // double zero: don't throw MathLib::divide("123", "0.0L"); // long double zero: don't throw - ASSERT_THROW_EQUALS(MathLib::divide("-9223372036854775808", "-1"), InternalError, "Internal Error: Division overflow"); // #4520 - out of range => throw + ASSERT_THROW_INTERNAL_EQUALS(MathLib::divide("-9223372036854775808", "-1"), INTERNAL, "Internal Error: Division overflow"); // #4520 - out of range => throw ASSERT_EQUALS("4611686018427387904", MathLib::divide("-9223372036854775808", "-2")); // #6679 @@ -165,7 +165,7 @@ class TestMathLib : public TestFixture { ASSERT_EQUALS("1", MathLib::calculate("0", "1", '^')); // Unknown action should throw exception - ASSERT_THROW_EQUALS(MathLib::calculate("1","2",'j'),InternalError, "Unexpected action 'j' in MathLib::calculate(). Please report this to Cppcheck developers."); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::calculate("1","2",'j'),INTERNAL, "Unexpected action 'j' in MathLib::calculate(). Please report this to Cppcheck developers."); } void calculate1() const { @@ -182,7 +182,7 @@ class TestMathLib : public TestFixture { MathLib::calculate("123", "0.0", '%'); // don't throw #endif - ASSERT_THROW_EQUALS(MathLib::calculate("123", "0", '%'), InternalError, "Internal Error: Division by zero"); // throw + ASSERT_THROW_INTERNAL_EQUALS(MathLib::calculate("123", "0", '%'), INTERNAL, "Internal Error: Division by zero"); // throw ASSERT_EQUALS("0", MathLib::calculate("1", "1", '^')); ASSERT_EQUALS("3", MathLib::calculate("2", "1", '^')); @@ -365,8 +365,8 @@ class TestMathLib : public TestFixture { ASSERT_EQUALS(i, MathLib::toBigNumber("-0xFFFFFFFFFFFFFFFF")); } - ASSERT_THROW_EQUALS(MathLib::toBigNumber("0x10000000000000000"), InternalError, "Internal Error. MathLib::toBigNumber: out_of_range: 0x10000000000000000"); - ASSERT_THROW_EQUALS(MathLib::toBigNumber("-0x10000000000000000"), InternalError, "Internal Error. MathLib::toBigNumber: out_of_range: -0x10000000000000000"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toBigNumber("0x10000000000000000"), INTERNAL, "Internal Error. MathLib::toBigNumber: out_of_range: 0x10000000000000000"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toBigNumber("-0x10000000000000000"), INTERNAL, "Internal Error. MathLib::toBigNumber: out_of_range: -0x10000000000000000"); // min/max and out-of-bounds - octal { @@ -380,8 +380,8 @@ class TestMathLib : public TestFixture { ASSERT_EQUALS(i, MathLib::toBigNumber("-01777777777777777777777")); } - ASSERT_THROW_EQUALS(MathLib::toBigNumber("02000000000000000000000"), InternalError, "Internal Error. MathLib::toBigNumber: out_of_range: 02000000000000000000000"); - ASSERT_THROW_EQUALS(MathLib::toBigNumber("-02000000000000000000000"), InternalError, "Internal Error. MathLib::toBigNumber: out_of_range: -02000000000000000000000"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toBigNumber("02000000000000000000000"), INTERNAL, "Internal Error. MathLib::toBigNumber: out_of_range: 02000000000000000000000"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toBigNumber("-02000000000000000000000"), INTERNAL, "Internal Error. MathLib::toBigNumber: out_of_range: -02000000000000000000000"); // min/max and out-of-bounds - decimal SUPPRESS_WARNING_CLANG_PUSH("-Wimplicitly-unsigned-literal") @@ -399,13 +399,13 @@ class TestMathLib : public TestFixture { SUPPRESS_WARNING_GCC_POP SUPPRESS_WARNING_CLANG_POP - ASSERT_THROW_EQUALS(MathLib::toBigNumber("18446744073709551616"), InternalError, "Internal Error. MathLib::toBigNumber: out_of_range: 18446744073709551616"); - ASSERT_THROW_EQUALS(MathLib::toBigNumber("-18446744073709551616"), InternalError, "Internal Error. MathLib::toBigNumber: out_of_range: -18446744073709551616"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toBigNumber("18446744073709551616"), INTERNAL, "Internal Error. MathLib::toBigNumber: out_of_range: 18446744073709551616"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toBigNumber("-18446744073709551616"), INTERNAL, "Internal Error. MathLib::toBigNumber: out_of_range: -18446744073709551616"); - ASSERT_THROW_EQUALS(MathLib::toBigNumber("invalid"), InternalError, "Internal Error. MathLib::toBigNumber: invalid_argument: invalid"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toBigNumber("invalid"), INTERNAL, "Internal Error. MathLib::toBigNumber: invalid_argument: invalid"); - ASSERT_THROW_EQUALS(MathLib::toBigNumber("1invalid"), InternalError, "Internal Error. MathLib::toBigNumber: input was not completely consumed: 1invalid"); - ASSERT_THROW_EQUALS(MathLib::toBigNumber("1 invalid"), InternalError, "Internal Error. MathLib::toBigNumber: input was not completely consumed: 1 invalid"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toBigNumber("1invalid"), INTERNAL, "Internal Error. MathLib::toBigNumber: input was not completely consumed: 1invalid"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toBigNumber("1 invalid"), INTERNAL, "Internal Error. MathLib::toBigNumber: input was not completely consumed: 1 invalid"); // TODO: test binary // TODO: test floating point @@ -530,8 +530,8 @@ class TestMathLib : public TestFixture { ASSERT_EQUALS(u, MathLib::toBigUNumber("-0xFFFFFFFFFFFFFFFF")); } - ASSERT_THROW_EQUALS(MathLib::toBigUNumber("0x10000000000000000"), InternalError, "Internal Error. MathLib::toBigUNumber: out_of_range: 0x10000000000000000"); - ASSERT_THROW_EQUALS(MathLib::toBigUNumber("-0x10000000000000000"), InternalError, "Internal Error. MathLib::toBigUNumber: out_of_range: -0x10000000000000000"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toBigUNumber("0x10000000000000000"), INTERNAL, "Internal Error. MathLib::toBigUNumber: out_of_range: 0x10000000000000000"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toBigUNumber("-0x10000000000000000"), INTERNAL, "Internal Error. MathLib::toBigUNumber: out_of_range: -0x10000000000000000"); // min/max and out-of-bounds - octal { @@ -545,8 +545,8 @@ class TestMathLib : public TestFixture { ASSERT_EQUALS(u, MathLib::toBigUNumber("-01777777777777777777777")); } - ASSERT_THROW_EQUALS(MathLib::toBigUNumber("02000000000000000000000"), InternalError, "Internal Error. MathLib::toBigUNumber: out_of_range: 02000000000000000000000"); - ASSERT_THROW_EQUALS(MathLib::toBigUNumber("-02000000000000000000000"), InternalError, "Internal Error. MathLib::toBigUNumber: out_of_range: -02000000000000000000000"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toBigUNumber("02000000000000000000000"), INTERNAL, "Internal Error. MathLib::toBigUNumber: out_of_range: 02000000000000000000000"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toBigUNumber("-02000000000000000000000"), INTERNAL, "Internal Error. MathLib::toBigUNumber: out_of_range: -02000000000000000000000"); // min/max and out-of-bounds - decimal SUPPRESS_WARNING_CLANG_PUSH("-Wimplicitly-unsigned-literal") @@ -564,13 +564,13 @@ class TestMathLib : public TestFixture { SUPPRESS_WARNING_GCC_POP SUPPRESS_WARNING_CLANG_POP - ASSERT_THROW_EQUALS(MathLib::toBigUNumber("18446744073709551616"), InternalError, "Internal Error. MathLib::toBigUNumber: out_of_range: 18446744073709551616"); - ASSERT_THROW_EQUALS(MathLib::toBigUNumber("-18446744073709551616"), InternalError, "Internal Error. MathLib::toBigUNumber: out_of_range: -18446744073709551616"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toBigUNumber("18446744073709551616"), INTERNAL, "Internal Error. MathLib::toBigUNumber: out_of_range: 18446744073709551616"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toBigUNumber("-18446744073709551616"), INTERNAL, "Internal Error. MathLib::toBigUNumber: out_of_range: -18446744073709551616"); - ASSERT_THROW_EQUALS(MathLib::toBigUNumber("invalid"), InternalError, "Internal Error. MathLib::toBigUNumber: invalid_argument: invalid"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toBigUNumber("invalid"), INTERNAL, "Internal Error. MathLib::toBigUNumber: invalid_argument: invalid"); - ASSERT_THROW_EQUALS(MathLib::toBigUNumber("1invalid"), InternalError, "Internal Error. MathLib::toBigUNumber: input was not completely consumed: 1invalid"); - ASSERT_THROW_EQUALS(MathLib::toBigUNumber("1 invalid"), InternalError, "Internal Error. MathLib::toBigUNumber: input was not completely consumed: 1 invalid"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toBigUNumber("1invalid"), INTERNAL, "Internal Error. MathLib::toBigUNumber: input was not completely consumed: 1invalid"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toBigUNumber("1 invalid"), INTERNAL, "Internal Error. MathLib::toBigUNumber: input was not completely consumed: 1 invalid"); // TODO: test binary // TODO: test floating point @@ -657,39 +657,39 @@ class TestMathLib : public TestFixture { ASSERT_EQUALS_DOUBLE((double)('\200'), MathLib::toDoubleNumber("'\\200'"), 0.000001); ASSERT_EQUALS_DOUBLE((double)(L'A'), MathLib::toDoubleNumber("L'A'"), 0.000001); - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("invalid"), InternalError, "Internal Error. MathLib::toDoubleNumber: conversion failed: invalid"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("invalid"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: conversion failed: invalid"); #ifdef _LIBCPP_VERSION - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1invalid"), InternalError, "Internal Error. MathLib::toDoubleNumber: conversion failed: 1invalid"); - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1.1invalid"), InternalError, "Internal Error. MathLib::toDoubleNumber: conversion failed: 1.1invalid"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1invalid"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: conversion failed: 1invalid"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1.1invalid"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: conversion failed: 1.1invalid"); #else - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1invalid"), InternalError, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1invalid"); - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1.1invalid"), InternalError, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1.1invalid"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1invalid"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1invalid"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1.1invalid"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1.1invalid"); #endif - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1 invalid"), InternalError, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1 invalid"); - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("-1e-08.0"), InternalError, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: -1e-08.0"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1 invalid"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1 invalid"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("-1e-08.0"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: -1e-08.0"); // invalid suffices #ifdef _LIBCPP_VERSION - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1f"), InternalError, "Internal Error. MathLib::toDoubleNumber: conversion failed: 1f"); - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1F"), InternalError, "Internal Error. MathLib::toDoubleNumber: conversion failed: 1F"); - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1.ff"), InternalError, "Internal Error. MathLib::toDoubleNumber: conversion failed: 1.ff"); - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1.FF"), InternalError, "Internal Error. MathLib::toDoubleNumber: conversion failed: 1.FF"); - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1.0ff"), InternalError, "Internal Error. MathLib::toDoubleNumber: conversion failed: 1.0ff"); - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1.0FF"), InternalError, "Internal Error. MathLib::toDoubleNumber: conversion failed: 1.0FF"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1f"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: conversion failed: 1f"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1F"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: conversion failed: 1F"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1.ff"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: conversion failed: 1.ff"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1.FF"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: conversion failed: 1.FF"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1.0ff"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: conversion failed: 1.0ff"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1.0FF"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: conversion failed: 1.0FF"); #else - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1f"), InternalError, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1f"); - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1F"), InternalError, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1F"); - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1.ff"), InternalError, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1.ff"); - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1.FF"), InternalError, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1.FF"); - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1.0ff"), InternalError, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1.0ff"); - ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1.0FF"), InternalError, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1.0FF"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1f"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1f"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1F"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1F"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1.ff"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1.ff"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1.FF"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1.FF"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1.0ff"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1.0ff"); + ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1.0FF"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1.0FF"); #endif // TODO: needs to fail - //ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1.ll"), InternalError, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1.ll"); - //ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1.0LL"), InternalError, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1.0LL"); - //ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1.0ll"), InternalError, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1.0ll"); - //ASSERT_THROW_EQUALS(MathLib::toDoubleNumber("1.0LL"), InternalError, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1.0LL"); + //ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1.ll"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1.ll"); + //ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1.0LL"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1.0LL"); + //ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1.0ll"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1.0ll"); + //ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("1.0LL"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: input was not completely consumed: 1.0LL"); // verify: string --> double --> string conversion ASSERT_EQUALS("1.0", MathLib::toString(MathLib::toDoubleNumber("1.0f"))); diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index b541457b62b..bc7ee1095fc 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -3662,7 +3662,7 @@ class TestSimplifyTemplate : public TestFixture { const char code[] = "BEGIN_VERSIONED_NAMESPACE_DECL\n" "template class Fred { };\n" "END_VERSIONED_NAMESPACE_DECL"; - ASSERT_THROW_EQUALS(tok(code), InternalError, "There is an unknown macro here somewhere. Configuration is required. If BEGIN_VERSIONED_NAMESPACE_DECL is a macro then please configure it."); + ASSERT_THROW_INTERNAL_EQUALS(tok(code), UNKNOWN_MACRO, "There is an unknown macro here somewhere. Configuration is required. If BEGIN_VERSIONED_NAMESPACE_DECL is a macro then please configure it."); } void template150() { // syntax error diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 955c5982a56..aa2ceb66937 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -2516,7 +2516,7 @@ class TestSimplifyTypedef : public TestFixture { void simplifyTypedef106() { // ticket #3619 (segmentation fault) const char code[] = "typedef void f ();\ntypedef { f }"; - ASSERT_THROW_INTERNAL(tok(code), INTERNAL); + ASSERT_THROW_INTERNAL_EQUALS(tok(code), INTERNAL, "Internal error. AST cyclic dependency."); } void simplifyTypedef107() { // ticket #3963 (bad code => segmentation fault) diff --git a/test/testtoken.cpp b/test/testtoken.cpp index a456e667168..273d04984f6 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -665,7 +665,7 @@ class TestToken : public TestFixture { const SimpleTokenizer var(*this, "int a ; int b ;"); // Varid == 0 should throw exception - ASSERT_THROW_INTERNAL((void)Token::Match(var.tokens(), "%type% %varid% ; %type% %name%", 0),INTERNAL); + ASSERT_THROW_INTERNAL_EQUALS((void)Token::Match(var.tokens(), "%type% %varid% ; %type% %name%", 0),INTERNAL,"Internal error. Token::Match called with varid 0. Please report this to Cppcheck developers"); ASSERT_EQUALS(true, Token::Match(var.tokens(), "%type% %varid% ; %type% %name%", 1)); ASSERT_EQUALS(true, Token::Match(var.tokens(), "%type% %name% ; %type% %varid%", 2)); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index f2b91b8118f..559ab577939 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -963,25 +963,25 @@ class TestTokenizer : public TestFixture { // #4725 - ^{} void simplifyAsm2() { - ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { ^{} }"), InternalError, "syntax error"); - ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { x(^{}); }"), InternalError, "syntax error"); - ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { foo(A(), ^{ bar(); }); }"), InternalError, "syntax error"); - ASSERT_THROW_EQUALS(tokenizeAndStringify("int f0(Args args) {\n" - " return ^{\n" - " return sizeof...(Args);\n" - " }() + ^ {\n" - " return sizeof...(args);\n" - " }();\n" - "};"), InternalError, "syntax error"); - ASSERT_THROW_EQUALS(tokenizeAndStringify("int(^block)(void) = ^{\n" - " static int test = 0;\n" - " return test;\n" - "};"), InternalError, "syntax error"); - - ASSERT_THROW_EQUALS(tokenizeAndStringify("; return f(a[b=c],^{});"), InternalError, "syntax error: keyword 'return' is not allowed in global scope"); // #7185 + ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("void f() { ^{} }"), SYNTAX, "syntax error"); + ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("void f() { x(^{}); }"), SYNTAX, "syntax error"); + ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("void f() { foo(A(), ^{ bar(); }); }"), SYNTAX, "syntax error"); + ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("int f0(Args args) {\n" + " return ^{\n" + " return sizeof...(Args);\n" + " }() + ^ {\n" + " return sizeof...(args);\n" + " }();\n" + "};"), SYNTAX, "syntax error"); + ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("int(^block)(void) = ^{\n" + " static int test = 0;\n" + " return test;\n" + "};"), SYNTAX, "syntax error"); + + ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("; return f(a[b=c],^{});"), SYNTAX, "syntax error: keyword 'return' is not allowed in global scope"); // #7185 ASSERT_EQUALS("{ return f ( asm ( \"^(void){somecode}\" ) ) ; }", tokenizeAndStringify("{ return f(^(void){somecode}); }")); - ASSERT_THROW_EQUALS(tokenizeAndStringify(";a?(b?(c,^{}):0):^{};"), InternalError, "syntax error"); + ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify(";a?(b?(c,^{}):0):^{};"), SYNTAX, "syntax error"); ASSERT_EQUALS("template < typename T > " "CImg < T > operator| ( const char * const expression , const CImg < T > & img ) { " "return img | expression ; " @@ -7007,7 +7007,7 @@ class TestTokenizer : public TestFixture { void findGarbageCode() { // Test Tokenizer::findGarbageCode() // C++ try/catch in global scope - ASSERT_THROW_EQUALS(tokenizeAndStringify("try { }"), InternalError, "syntax error: keyword 'try' is not allowed in global scope"); + ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("try { }"), SYNTAX, "syntax error: keyword 'try' is not allowed in global scope"); ASSERT_NO_THROW(tokenizeAndStringify("void f() try { } catch (int) { }")); ASSERT_NO_THROW(tokenizeAndStringify("struct S {\n" // #9716 " S();\n" @@ -7034,7 +7034,7 @@ class TestTokenizer : public TestFixture { ASSERT_THROW_INTERNAL(tokenizeAndStringify("void foo() { for_chain( if (!done) done = 1); }"), UNKNOWN_MACRO); ASSERT_THROW_INTERNAL(tokenizeAndStringify("void foo() { for_chain( a, b, if (!done) done = 1); }"), UNKNOWN_MACRO); - ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { if (retval==){} }"), InternalError, "syntax error: ==)"); + ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("void f() { if (retval==){} }"), SYNTAX, "syntax error: ==)"); // after (expr) ASSERT_NO_THROW(tokenizeAndStringify("void f() { switch (a) int b; }")); @@ -7084,18 +7084,18 @@ class TestTokenizer : public TestFixture { // op op - ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { dostuff (x==>y); }"), InternalError, "syntax error: == >"); + ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("void f() { dostuff (x==>y); }"), SYNTAX, "syntax error: == >"); - ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { assert(a==()); }"), InternalError, "syntax error: ==()"); - ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { assert(a+()); }"), InternalError, "syntax error: +()"); + ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("void f() { assert(a==()); }"), SYNTAX, "syntax error: ==()"); + ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("void f() { assert(a+()); }"), SYNTAX, "syntax error: +()"); // #9445 - typeof is not a keyword in C ASSERT_NO_THROW(tokenizeAndStringify("void foo() { char *typeof, *value; }", false, Platform::Type::Native, "test.c")); - ASSERT_THROW_EQUALS(tokenizeAndStringify("enum : { };"), InternalError, "syntax error: Unexpected token '{'"); - ASSERT_THROW_EQUALS(tokenizeAndStringify("enum : 3 { };"), InternalError, "syntax error: Unexpected token '3'"); + ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("enum : { };"), SYNTAX, "syntax error: Unexpected token '{'"); + ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("enum : 3 { };"), SYNTAX, "syntax error: Unexpected token '3'"); - ASSERT_THROW_EQUALS(tokenizeAndStringify("int a() { b((c)return 0) }"), InternalError, "syntax error"); + ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("int a() { b((c)return 0) }"), SYNTAX, "syntax error"); ASSERT_THROW_EQUALS(tokenizeAndStringify("int f() { MACRO(x) return 0; }"), InternalError, "There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it.");