Fixed #6386: Improved behaviour on unknown language (header file)
This commit is contained in:
parent
a3fbc5aee5
commit
88990bac59
|
@ -2295,7 +2295,7 @@ void Tokenizer::simplifyTemplates()
|
|||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::string,unsigned int> &variableId, bool executableScope, bool cpp)
|
||||
static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::string,unsigned int> &variableId, bool executableScope, bool cpp, bool c)
|
||||
{
|
||||
const Token *tok2 = *tok;
|
||||
|
||||
|
@ -2312,7 +2312,7 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::stri
|
|||
if (tok2->isName()) {
|
||||
if (cpp && Token::Match(tok2, "namespace|public|private|protected"))
|
||||
return false;
|
||||
if (Token::Match(tok2, "struct|union") || (cpp && Token::Match(tok2, "class|typename"))) {
|
||||
if (Token::Match(tok2, "struct|union") || (!c && Token::Match(tok2, "class|typename"))) {
|
||||
hasstruct = true;
|
||||
typeCount = 0;
|
||||
singleNameCount = 0;
|
||||
|
@ -2648,7 +2648,7 @@ void Tokenizer::setVarId()
|
|||
if (Token::simpleMatch(tok2, "const new") && !isC())
|
||||
continue;
|
||||
|
||||
bool decl = setVarIdParseDeclaration(&tok2, variableId, executableScope.top(), isCPP());
|
||||
bool decl = setVarIdParseDeclaration(&tok2, variableId, executableScope.top(), isCPP(), isC());
|
||||
if (decl) {
|
||||
const Token* prev2 = tok2->previous();
|
||||
if (Token::Match(prev2, "%type% [;[=,)]") && tok2->previous()->str() != "const")
|
||||
|
|
|
@ -137,6 +137,7 @@ private:
|
|||
TEST_CASE(varid_pointerToArray); // #2645
|
||||
TEST_CASE(varid_cpp11initialization); // #4344
|
||||
TEST_CASE(varid_inheritedMembers); // #4101
|
||||
TEST_CASE(varid_header); // #6386
|
||||
|
||||
TEST_CASE(varidclass1);
|
||||
TEST_CASE(varidclass2);
|
||||
|
@ -1965,6 +1966,18 @@ private:
|
|||
"};"));
|
||||
}
|
||||
|
||||
void varid_header() {
|
||||
ASSERT_EQUALS("\n\n##file 0\n"
|
||||
"1: class A ;\n"
|
||||
"2: struct B {\n"
|
||||
"3: void setData ( const A & a@1 ) ;\n"
|
||||
"4: } ;\n",
|
||||
tokenize("class A;\n"
|
||||
"struct B {\n"
|
||||
" void setData(const A & a);\n"
|
||||
"}; ", false, "test.h"));
|
||||
}
|
||||
|
||||
void varidclass1() {
|
||||
const std::string actual = tokenize(
|
||||
"class Fred\n"
|
||||
|
|
Loading…
Reference in New Issue