Check for more garbage code (#1949)

* Check for garbage commas

* Find garbage dot operator
This commit is contained in:
Paul Fultz II 2019-07-03 01:28:24 -05:00 committed by Daniel Marjamäki
parent d6f6e68fa2
commit 8f4cb36e1e
4 changed files with 22 additions and 14 deletions

View File

@ -9227,6 +9227,21 @@ void Tokenizer::findGarbageCode() const
syntaxError(tok);
if (Token::Match(tok, "[+-] [;,)]}]") && !(isCPP() && Token::Match(tok->previous(), "operator [+-] ;")))
syntaxError(tok);
if (Token::simpleMatch(tok, ",")) {
if (Token::Match(tok->previous(), "(|[|{|<|%assign%|%or%|%oror%|==|!=|+|-|/|!|>=|<=|~|^|::|sizeof|throw|decltype|typeof"))
syntaxError(tok);
if (Token::Match(tok->next(), ")|]|>|%assign%|%or%|%oror%|==|!=|/|>=|<=|&&"))
syntaxError(tok);
}
if (Token::simpleMatch(tok, ".") &&
!Token::simpleMatch(tok->previous(), ".") &&
!Token::simpleMatch(tok->next(), ".") &&
!Token::Match(tok->previous(), "{|, . %name% =")) {
if (!Token::Match(tok->previous(), ")|]|>|}|%name%"))
syntaxError(tok);
if (!Token::Match(tok->next(), "template|operator|*|~|%name%"))
syntaxError(tok);
}
}
// ternary operator without :

View File

@ -841,9 +841,9 @@ private:
void garbageCode101() { // #6835
// Reported case
checkCode("template < class , =( , int) X = 1 > struct A { } ( ) { = } [ { } ] ( ) { A < void > 0 }");
ASSERT_THROW(checkCode("template < class , =( , int) X = 1 > struct A { } ( ) { = } [ { } ] ( ) { A < void > 0 }"), InternalError);
// Reduced case
checkCode("template < class =( , ) X = 1> struct A {}; A<void> a;");
ASSERT_THROW(checkCode("template < class =( , ) X = 1> struct A {}; A<void> a;"), InternalError);
}
void garbageCode102() { // #6846
@ -1416,7 +1416,7 @@ private:
void garbageCode170() {
// 7255
checkCode("d i(){{f*s=typeid(()0,)}}", false);
ASSERT_THROW(checkCode("d i(){{f*s=typeid(()0,)}}", false), InternalError);
}
void garbageCode171() {
@ -1595,7 +1595,7 @@ private:
}
void garbageCode204() {
checkCode("template <a, = b<>()> c; template <a> a as() {} as<c<>>();");
ASSERT_THROW(checkCode("template <a, = b<>()> c; template <a> a as() {} as<c<>>();"), InternalError);
}
void syntaxErrorFirstToken() {

View File

@ -3781,13 +3781,13 @@ private:
check("void f() {\n"
" enum { Four = 4 };\n"
" static_assert(Four == 4, "");\n"
" static_assert(Four == 4, \"\");\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" enum { Four = 4 };\n"
" static_assert(4 == Four, "");\n"
" static_assert(4 == Four, \"\");\n"
"}");
ASSERT_EQUALS("", errout.str());
@ -3801,7 +3801,7 @@ private:
check("void f() {\n"
" enum { FourInEnumOne = 4 };\n"
" enum { FourInEnumTwo = 4 };\n"
" static_assert(FourInEnumOne == FourInEnumTwo, "");\n"
" static_assert(FourInEnumOne == FourInEnumTwo, \"\");\n"
"}");
ASSERT_EQUALS("", errout.str());

View File

@ -204,7 +204,6 @@ private:
TEST_CASE(functionArgs1);
TEST_CASE(functionArgs2);
TEST_CASE(functionArgs3);
TEST_CASE(functionArgs4);
TEST_CASE(functionArgs5); // #7650
TEST_CASE(functionArgs6); // #7651
@ -1917,12 +1916,6 @@ private:
ASSERT_EQUALS(true, a->dimensions()[1].known);
}
void functionArgs3() {
GET_SYMBOL_DB("void f(int i,) { }"); // Don't crash
const Variable *a = db->getVariableFromVarId(1);
ASSERT_EQUALS("i", a->nameToken()->str());
}
void functionArgs4() {
GET_SYMBOL_DB("void f1(char [10], struct foo [10]);");
ASSERT_EQUALS(true, db->scopeList.front().functionList.size() == 1UL);