Fixed #9094 (Tokenizer::createLinks2 problem with 'x%x<--a==x>x')
This commit is contained in:
parent
1e2f1bac1f
commit
4d9b1e6c3d
|
@ -3792,6 +3792,9 @@ void Tokenizer::createLinks2()
|
||||||
const Token * templateToken = nullptr;
|
const Token * templateToken = nullptr;
|
||||||
bool isStruct = false;
|
bool isStruct = false;
|
||||||
|
|
||||||
|
std::map<std::string, bool> templateNames;
|
||||||
|
templateNames["template"] = true;
|
||||||
|
|
||||||
std::stack<Token*> type;
|
std::stack<Token*> type;
|
||||||
for (Token *token = list.front(); token; token = token->next()) {
|
for (Token *token = list.front(); token; token = token->next()) {
|
||||||
if (Token::Match(token, "%name%|> %name% [:<]"))
|
if (Token::Match(token, "%name%|> %name% [:<]"))
|
||||||
|
@ -3848,6 +3851,28 @@ void Tokenizer::createLinks2()
|
||||||
while (!type.empty() && type.top()->str() == "<")
|
while (!type.empty() && type.top()->str() == "<")
|
||||||
type.pop();
|
type.pop();
|
||||||
} else if (token->str() == "<" && token->previous() && token->previous()->isName() && !token->previous()->varId()) {
|
} else if (token->str() == "<" && token->previous() && token->previous()->isName() && !token->previous()->varId()) {
|
||||||
|
if (!Token::simpleMatch(token->tokAt(-2), "::")) {
|
||||||
|
std::map<std::string, bool>::const_iterator it = templateNames.find(token->previous()->str());
|
||||||
|
if (it == templateNames.end()) {
|
||||||
|
const std::string &name = token->previous()->str();
|
||||||
|
bool isTemplateType = true;
|
||||||
|
for (const Token *tok2 = list.front(); tok2; tok2 = tok2->next()) {
|
||||||
|
if (!tok2->isName() || tok2->str() != name)
|
||||||
|
continue;
|
||||||
|
if (Token::Match(tok2->previous(), "class|struct"))
|
||||||
|
break;
|
||||||
|
if (!Token::Match(tok2->next(), "[<:({]")) {
|
||||||
|
isTemplateType = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templateNames[name] = isTemplateType;
|
||||||
|
if (!isTemplateType)
|
||||||
|
continue;
|
||||||
|
} else if (!it->second) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
type.push(token);
|
type.push(token);
|
||||||
if (!templateToken && (token->previous()->str() == "template"))
|
if (!templateToken && (token->previous()->str() == "template"))
|
||||||
templateToken = token;
|
templateToken = token;
|
||||||
|
|
|
@ -1372,9 +1372,8 @@ private:
|
||||||
" delete [] (double*)f;\n"
|
" delete [] (double*)f;\n"
|
||||||
" delete [] (long double const*)(new float[10]);\n"
|
" delete [] (long double const*)(new float[10]);\n"
|
||||||
"}");
|
"}");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (portability) Casting between float* and double* which have an incompatible binary data representation.\n"
|
ASSERT_EQUALS("[test.cpp:3]: (portability) Casting between float* and double* which have an incompatible binary data representation.\n"
|
||||||
"[test.cpp:4]: (portability) Casting between float* and const long double* which have an incompatible binary data representation.\n",
|
"[test.cpp:4]: (portability) Casting between float* and const long double* which have an incompatible binary data representation.\n", errout.str());
|
||||||
"[test.cpp:3]: (portability) Casting between float* and double* which have an incompatible binary data representation.\n", errout.str());
|
|
||||||
|
|
||||||
checkInvalidPointerCast("void test(const float* f) {\n"
|
checkInvalidPointerCast("void test(const float* f) {\n"
|
||||||
" double *d = (double*)f;\n"
|
" double *d = (double*)f;\n"
|
||||||
|
|
|
@ -1881,8 +1881,8 @@ private:
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" vector<int> v;\n"
|
" vector<int> v;\n"
|
||||||
" vector.push_back(1);\n"
|
" v.push_back(1);\n"
|
||||||
" vector.push_back(2);\n"
|
" v.push_back(2);\n"
|
||||||
" for (vector<int>::iterator it = v.begin(); it != v.end(); ++it)\n"
|
" for (vector<int>::iterator it = v.begin(); it != v.end(); ++it)\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
" if (*it == 1)\n"
|
" if (*it == 1)\n"
|
||||||
|
|
|
@ -4768,6 +4768,15 @@ private:
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
tokenizer.tokenize(istr, "test.cpp");
|
||||||
ASSERT_EQUALS(true, Token::simpleMatch(tokenizer.tokens()->next()->link(), "> void"));
|
ASSERT_EQUALS(true, Token::simpleMatch(tokenizer.tokens()->next()->link(), "> void"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// #9094
|
||||||
|
const char code[] = "a = f(x%x<--a==x>x);";
|
||||||
|
Tokenizer tokenizer(&settings0, this);
|
||||||
|
std::istringstream istr(code);
|
||||||
|
tokenizer.tokenize(istr, "test.cpp");
|
||||||
|
ASSERT(nullptr == Token::findsimplematch(tokenizer.tokens(), "<")->link());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void simplifyString() {
|
void simplifyString() {
|
||||||
|
|
Loading…
Reference in New Issue