Ticket #6708: Check that a function name is not a reserved keyword in SymbolDatabase::isFunction instead of later.

This commit is contained in:
Simon Martin 2015-05-26 00:28:08 +02:00
parent 729b240d9c
commit 50e5595845
6 changed files with 15 additions and 15 deletions

View File

@ -745,8 +745,6 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
// save function prototype in database
if (newFunc) {
Function* func = addGlobalFunctionDecl(scope, tok, argStart, funcStart);
if (!func)
break;
if (Token::Match(argStart->link(), ") const| noexcept")) {
int arg = 2;
@ -1301,7 +1299,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
}
// regular function?
else if (Token::Match(tok, "%name% (") && tok->previous() &&
else if (Token::Match(tok, "%name% (") && !isReservedName(tok->str()) && tok->previous() &&
(tok->previous()->isName() || tok->strAt(-1) == ">" || tok->strAt(-1) == "&" || tok->strAt(-1) == "*" || // Either a return type in front of tok
tok->strAt(-1) == "::" || tok->strAt(-1) == "~" || // or a scope qualifier in front of tok
outerScope->isClassOrStruct())) { // or a ctor/dtor
@ -1660,9 +1658,6 @@ Function* SymbolDatabase::addGlobalFunction(Scope*& scope, const Token*& tok, co
if (!function)
function = addGlobalFunctionDecl(scope, tok, argStart, funcStart);
if (!function)
return 0;
function->arg = argStart;
function->token = funcStart;
function->hasBody(true);
@ -1688,8 +1683,6 @@ Function* SymbolDatabase::addGlobalFunctionDecl(Scope*& scope, const Token *tok,
function.access = Public;
// save the function name location
if (funcStart && isReservedName(funcStart->str()))
return 0;
function.tokenDef = funcStart;
function.isInline(false);

View File

@ -1001,7 +1001,7 @@ private:
Function *addGlobalFunctionDecl(Scope*& scope, const Token* tok, const Token *argStart, const Token* funcStart);
Function *addGlobalFunction(Scope*& scope, const Token*& tok, const Token *argStart, const Token* funcStart);
void addNewFunction(Scope **info, const Token **tok);
static bool isFunction(const Token *tok, const Scope* outerScope, const Token **funcStart, const Token **argStart);
bool isFunction(const Token *tok, const Scope* outerScope, const Token **funcStart, const Token **argStart);
const Type *findTypeInNested(const Token *tok, const Scope *startScope) const;
const Scope *findNamespace(const Token * tok, const Scope * scope) const;
Function *findFunctionInScope(const Token *func, const Scope *ns);

View File

@ -462,15 +462,15 @@ private:
}
void garbageCode40() { // #6620
ASSERT_THROW(checkCode("{ ( ) () { virtual } ; { } E } A { : { } ( ) } * const ( ) const { }"), InternalError);
checkCode("{ ( ) () { virtual } ; { } E } A { : { } ( ) } * const ( ) const { }");
}
void garbageCode41() { // #6685
ASSERT_THROW(checkCode(" { } { return } *malloc(__SIZE_TYPE__ size); *memcpy(void n); static * const () { memcpy (*slot, 3); } { (); } { }"), InternalError);
checkCode(" { } { return } *malloc(__SIZE_TYPE__ size); *memcpy(void n); static * const () { memcpy (*slot, 3); } { (); } { }");
}
void garbageCode42() { // #5760
ASSERT_THROW(checkCode("{ } * const ( ) { }"), InternalError);
checkCode("{ } * const ( ) { }");
}
void garbageCode43() { // #6703

View File

@ -805,7 +805,7 @@ private:
ASSERT_EQUALS("\n\n##file 0\n1: else { if ( ab ) { cd } else { ef } } gh\n", elseif(code));
// syntax error: assert there is no segmentation fault
ASSERT_THROW(elseif("else if (x) { }"), InternalError);
ASSERT_EQUALS("\n\n##file 0\n1: else if ( x ) { }\n", elseif("else if (x) { }"));
{
const char src[] = "void f(int g,int f) {\n"

View File

@ -1920,7 +1920,8 @@ private:
}
void symboldatabase36() { // ticket #4892
ASSERT_THROW(check("void struct ( ) { if ( 1 ) } int main ( ) { }"), InternalError);
check("void struct ( ) { if ( 1 ) } int main ( ) { }");
ASSERT_EQUALS("", errout.str());
}
void symboldatabase37() {

View File

@ -336,6 +336,7 @@ private:
TEST_CASE(cpp0xtemplate2);
TEST_CASE(cpp0xtemplate3);
TEST_CASE(cpp0xtemplate4); // Ticket #6181: Mishandled C++11 syntax
TEST_CASE(cpp14template); // Ticket #6708
TEST_CASE(arraySize);
@ -1270,7 +1271,7 @@ private:
void ifAddBraces15() {
// ticket #2616 - unknown macro before if
ASSERT_THROW(tokenizeAndStringify("{A if(x)y();}", false), InternalError);
ASSERT_EQUALS("{ A if ( x ) { y ( ) ; } }", tokenizeAndStringify("{A if(x)y();}", false));
}
void ifAddBraces16() { // ticket # 2739 (segmentation fault)
@ -5264,6 +5265,11 @@ private:
"}");
}
void cpp14template() { // Ticket #6708
tokenizeAndStringify("template <typename T> "
"decltype(auto) forward(T& t) { return 0; }");
}
std::string arraySize_(const std::string &code) {
errout.str("");
Settings settings;