Merge pull request #603 from simartin/ticket_6708
Ticket #6708: Check that a function name is not a reserved keyword in SymbolDatabase::isFunction instead of later.
This commit is contained in:
commit
0bd7cbfbeb
|
@ -745,8 +745,6 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
// save function prototype in database
|
// save function prototype in database
|
||||||
if (newFunc) {
|
if (newFunc) {
|
||||||
Function* func = addGlobalFunctionDecl(scope, tok, argStart, funcStart);
|
Function* func = addGlobalFunctionDecl(scope, tok, argStart, funcStart);
|
||||||
if (!func)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (Token::Match(argStart->link(), ") const| noexcept")) {
|
if (Token::Match(argStart->link(), ") const| noexcept")) {
|
||||||
int arg = 2;
|
int arg = 2;
|
||||||
|
@ -1301,7 +1299,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
|
||||||
}
|
}
|
||||||
|
|
||||||
// regular function?
|
// 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->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
|
tok->strAt(-1) == "::" || tok->strAt(-1) == "~" || // or a scope qualifier in front of tok
|
||||||
outerScope->isClassOrStruct())) { // or a ctor/dtor
|
outerScope->isClassOrStruct())) { // or a ctor/dtor
|
||||||
|
@ -1660,9 +1658,6 @@ Function* SymbolDatabase::addGlobalFunction(Scope*& scope, const Token*& tok, co
|
||||||
if (!function)
|
if (!function)
|
||||||
function = addGlobalFunctionDecl(scope, tok, argStart, funcStart);
|
function = addGlobalFunctionDecl(scope, tok, argStart, funcStart);
|
||||||
|
|
||||||
if (!function)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
function->arg = argStart;
|
function->arg = argStart;
|
||||||
function->token = funcStart;
|
function->token = funcStart;
|
||||||
function->hasBody(true);
|
function->hasBody(true);
|
||||||
|
@ -1688,8 +1683,6 @@ Function* SymbolDatabase::addGlobalFunctionDecl(Scope*& scope, const Token *tok,
|
||||||
function.access = Public;
|
function.access = Public;
|
||||||
|
|
||||||
// save the function name location
|
// save the function name location
|
||||||
if (funcStart && isReservedName(funcStart->str()))
|
|
||||||
return 0;
|
|
||||||
function.tokenDef = funcStart;
|
function.tokenDef = funcStart;
|
||||||
|
|
||||||
function.isInline(false);
|
function.isInline(false);
|
||||||
|
|
|
@ -1001,7 +1001,7 @@ private:
|
||||||
Function *addGlobalFunctionDecl(Scope*& scope, const Token* tok, const Token *argStart, const Token* funcStart);
|
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);
|
Function *addGlobalFunction(Scope*& scope, const Token*& tok, const Token *argStart, const Token* funcStart);
|
||||||
void addNewFunction(Scope **info, const Token **tok);
|
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 Type *findTypeInNested(const Token *tok, const Scope *startScope) const;
|
||||||
const Scope *findNamespace(const Token * tok, const Scope * scope) const;
|
const Scope *findNamespace(const Token * tok, const Scope * scope) const;
|
||||||
Function *findFunctionInScope(const Token *func, const Scope *ns);
|
Function *findFunctionInScope(const Token *func, const Scope *ns);
|
||||||
|
|
|
@ -462,15 +462,15 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void garbageCode40() { // #6620
|
void garbageCode40() { // #6620
|
||||||
ASSERT_THROW(checkCode("{ ( ) () { virtual } ; { } E } A { : { } ( ) } * const ( ) const { }"), InternalError);
|
checkCode("{ ( ) () { virtual } ; { } E } A { : { } ( ) } * const ( ) const { }");
|
||||||
}
|
}
|
||||||
|
|
||||||
void garbageCode41() { // #6685
|
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
|
void garbageCode42() { // #5760
|
||||||
ASSERT_THROW(checkCode("{ } * const ( ) { }"), InternalError);
|
checkCode("{ } * const ( ) { }");
|
||||||
}
|
}
|
||||||
|
|
||||||
void garbageCode43() { // #6703
|
void garbageCode43() { // #6703
|
||||||
|
|
|
@ -805,7 +805,7 @@ private:
|
||||||
ASSERT_EQUALS("\n\n##file 0\n1: else { if ( ab ) { cd } else { ef } } gh\n", elseif(code));
|
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
|
// 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"
|
const char src[] = "void f(int g,int f) {\n"
|
||||||
|
|
|
@ -1920,7 +1920,8 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void symboldatabase36() { // ticket #4892
|
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() {
|
void symboldatabase37() {
|
||||||
|
|
|
@ -336,6 +336,7 @@ private:
|
||||||
TEST_CASE(cpp0xtemplate2);
|
TEST_CASE(cpp0xtemplate2);
|
||||||
TEST_CASE(cpp0xtemplate3);
|
TEST_CASE(cpp0xtemplate3);
|
||||||
TEST_CASE(cpp0xtemplate4); // Ticket #6181: Mishandled C++11 syntax
|
TEST_CASE(cpp0xtemplate4); // Ticket #6181: Mishandled C++11 syntax
|
||||||
|
TEST_CASE(cpp14template); // Ticket #6708
|
||||||
|
|
||||||
TEST_CASE(arraySize);
|
TEST_CASE(arraySize);
|
||||||
|
|
||||||
|
@ -1270,7 +1271,7 @@ private:
|
||||||
|
|
||||||
void ifAddBraces15() {
|
void ifAddBraces15() {
|
||||||
// ticket #2616 - unknown macro before if
|
// 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)
|
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) {
|
std::string arraySize_(const std::string &code) {
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
|
Loading…
Reference in New Issue