Fixed #3760: Added explicit to C++ keyword list in setVarId

Made some constant arrays static
This commit is contained in:
PKEuS 2012-05-16 01:59:52 -07:00
parent e8cd119ebd
commit 0157f937bf
2 changed files with 11 additions and 3 deletions

View File

@ -2621,7 +2621,7 @@ void Tokenizer::setVarId()
notstart.insert("return");
notstart.insert("sizeof");
if (!isC()) {
const char *str[] = {"delete","friend","new","throw","using","virtual"};
static const char *str[] = {"delete","friend","new","throw","using","virtual","explicit"};
notstart.insert(str, str+(sizeof(str)/sizeof(*str)));
}
@ -6101,7 +6101,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
// Variable is used in function call..
if (Token::Match(tok3, ("%var% ( " + structname + " %varid% ,").c_str(), varid)) {
const char * const functionName[] = {
static const char * const functionName[] = {
"memcmp","memcpy","memmove","memset",
"strcmp","strcpy","strncmp","strncpy","strdup"
};
@ -6121,7 +6121,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
// Variable is used as 2nd parameter in function call..
if (Token::Match(tok3, ("%var% ( %any% , " + structname + " %varid% ,|)").c_str(), varid)) {
const char * const functionName[] = {
static const char * const functionName[] = {
"memcmp","memcpy","memmove",
"strcmp","strcpy","strncmp","strncpy"
};

View File

@ -215,6 +215,7 @@ private:
TEST_CASE(varid47); // function parameters
TEST_CASE(varid48); // #3785 - return (a*b)
TEST_CASE(varid49); // #3799 - void f(std::vector<int>)
TEST_CASE(varid50); // #3760 - explicit
TEST_CASE(varid_cpp_keywords_in_c_code);
TEST_CASE(varidFunctionCall1);
TEST_CASE(varidFunctionCall2);
@ -3259,6 +3260,13 @@ private:
tokenizeDebugListing(code, false, "test.cpp"));
}
void varid50() { // #3760 - explicit
const std::string code("class A { explicit A(const A&); };");
ASSERT_EQUALS("\n\n##file 0\n"
"1: class A { explicit A ( const A & ) ; } ;\n",
tokenizeDebugListing(code, false, "test.cpp"));
}
void varid_cpp_keywords_in_c_code() {
const char code[] = "void f() {\n"
" delete d;\n"