Ticket #8333: Properly report a syntax error for functions with invalid parameter types. (#1030)

This commit is contained in:
Simon Martin 2018-01-18 08:51:35 +01:00 committed by amai2012
parent d08709d10f
commit 8878e6dd0d
2 changed files with 15 additions and 1 deletions

View File

@ -3082,6 +3082,10 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
// skip over stuff to get to type // skip over stuff to get to type
while (Token::Match(typeTok, "const|enum|struct|::")) while (Token::Match(typeTok, "const|enum|struct|::"))
typeTok = typeTok->next(); typeTok = typeTok->next();
if (Token::Match(typeTok, ",|)")) { // #8333
symbolDatabase->_tokenizer->syntaxError(typeTok);
return;
}
// skip over qualification // skip over qualification
while (Token::Match(typeTok, "%type% ::")) while (Token::Match(typeTok, "%type% ::"))
typeTok = typeTok->tokAt(2); typeTok = typeTok->tokAt(2);

View File

@ -221,6 +221,7 @@ private:
TEST_CASE(garbageCode188); TEST_CASE(garbageCode188);
TEST_CASE(garbageCode189); // #8317 TEST_CASE(garbageCode189); // #8317
TEST_CASE(garbageCode190); // #8307 TEST_CASE(garbageCode190); // #8307
TEST_CASE(garbageCode191); // #8333
TEST_CASE(garbageValueFlow); TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageSymbolDatabase);
TEST_CASE(garbageAST); TEST_CASE(garbageAST);
@ -1203,7 +1204,7 @@ private:
"{\n" "{\n"
" (foo(s, , 2, , , 5, , 7)) abort()\n" " (foo(s, , 2, , , 5, , 7)) abort()\n"
"}\n"; "}\n";
checkCode(code); ASSERT_THROW(checkCode(code), InternalError);
// #6106 // #6106
code = " f { int i ; b2 , [ ] ( for ( i = 0 ; ; ) ) }"; code = " f { int i ; b2 , [ ] ( for ( i = 0 ; ; ) ) }";
@ -1451,6 +1452,15 @@ private:
"}"); "}");
} }
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);
// The following code is valid and should not trigger any error
checkCode("struct A { int f ( char ) ; } ;");
}
void syntaxErrorFirstToken() { void syntaxErrorFirstToken() {
ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818 ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818
ASSERT_THROW(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { }"), InternalError); // #6858 ASSERT_THROW(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { }"), InternalError); // #6858