diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 6c1a7e309..c82a6c7fd 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9308,6 +9308,21 @@ void Tokenizer::reportUnknownMacros() } } + // Report unknown macros that contain several statements "MACRO(a;b;c)" + for (const Token *tok = tokens(); tok; tok = tok->next()) { + if (!Token::Match(tok, "%name% (")) + continue; + if (!tok->isUpperCaseName()) + continue; + const Token *endTok = tok->linkAt(1); + for (const Token *inner = tok->tokAt(2); inner != endTok; inner = inner->next()) { + if (Token::Match(inner, "[[({]")) + inner = inner->link(); + else if (inner->str() == ";") + unknownMacroError(inner); + } + } + // Report unknown macros in non-executable scopes.. std::set possible; for (const Token *tok = tokens(); tok; tok = tok->next()) { diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index b69d6990c..1e0472628 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -1153,12 +1153,6 @@ private: "}", "test.cpp", &settings2); ASSERT_EQUALS("", errout.str()); - // #7979 - code is not well configured - check("void foo() {\n" - " DEBUG(x(); mystrcmp(a,b););\n" - "}", "test.cpp", &settings2); - ASSERT_EQUALS("", errout.str()); - check("void foo() {\n" // don't crash " DEBUG(123)(mystrcmp(a,b))(fd);\n" "}", "test.c", &settings2); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 4d540b0be..245a8ae93 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -3550,9 +3550,7 @@ private: ASSERT_EQUALS("void f ( int i ) { goto label ; { label : ; exit ( 0 ) ; } }", tokWithStdLib("void f (int i) { goto label; switch(i) { label: exit(0); } }")); //ticket #3148 ASSERT_EQUALS("void f ( ) { MACRO ( exit ( 0 ) ) }", tokWithStdLib("void f() { MACRO(exit(0)) }")); - ASSERT_EQUALS("void f ( ) { MACRO ( exit ( 0 ) ; , NULL ) }", tokWithStdLib("void f() { MACRO(exit(0);, NULL) }")); ASSERT_EQUALS("void f ( ) { MACRO ( bar1 , exit ( 0 ) ) }", tokWithStdLib("void f() { MACRO(bar1, exit(0)) }")); - ASSERT_EQUALS("void f ( ) { MACRO ( exit ( 0 ) ; bar2 , foo ) }", tokWithStdLib("void f() { MACRO(exit(0); bar2, foo) }")); } { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 30959a316..0993e40dd 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -2735,7 +2735,7 @@ private: " BENCH1(q = _mhz_M(n); n = 1;)\n" " use_pointer(q);\n" "}"; - tokenizeAndStringify(code, true); // don't hang + ASSERT_THROW(tokenizeAndStringify(code, true), InternalError); } void simplifyKnownVariables52() { // #4728 "= x %op%" @@ -5338,7 +5338,7 @@ private: ASSERT_EQUALS("void f ( ) { ab : ; { & b = 0 ; } }", tokenizeAndStringify("void f() { ab: { &b=0;} }")); ASSERT_EQUALS("void f ( ) { ab : ; { & ( * b . x ) = 0 ; } }", tokenizeAndStringify("void f() { ab: {&(*b.x)=0;} }")); //with unhandled MACRO() code - ASSERT_EQUALS("void f ( ) { MACRO ( ab : b = 0 ; , foo ) }", tokenizeAndStringify("void f() { MACRO(ab: b=0;, foo)}")); + ASSERT_THROW(tokenizeAndStringify("void f() { MACRO(ab: b=0;, foo)}"), InternalError); ASSERT_EQUALS("void f ( ) { MACRO ( bar , ab : { & ( * b . x ) = 0 ; } ) }", tokenizeAndStringify("void f() { MACRO(bar, ab: {&(*b.x)=0;})}")); } @@ -7994,6 +7994,11 @@ private: " virtual MACRO(int) f2() {}\n" "};"; ASSERT_THROW(tokenizeAndStringify(code4), InternalError); + + const char code5[] = "void foo() {\n" + " EVALUATE(123, int x=a; int y=b+c;);\n" + "}"; + ASSERT_THROW(tokenizeAndStringify(code5), InternalError); } void findGarbageCode() { // Test Tokenizer::findGarbageCode() @@ -8344,8 +8349,8 @@ private: } void checkConfiguration() { - checkConfig("void f() { DEBUG(x();y()); }"); - ASSERT_EQUALS("[test.cpp:1]: (information) Ensure that 'DEBUG' is defined either using -I, --include or -D.\n", errout.str()); + ASSERT_THROW(checkConfig("void f() { DEBUG(x();y()); }"), InternalError); + //ASSERT_EQUALS("[test.cpp:1]: (information) Ensure that 'DEBUG' is defined either using -I, --include or -D.\n", errout.str()); } void unknownType() { // #8952