* Fix #11309 debug: Scope::checkVariable found variable 'v' with varid 0 * Format
This commit is contained in:
parent
6820b70dd1
commit
9ea223b367
|
@ -6000,14 +6000,25 @@ static std::string getExpression(const Token *tok)
|
||||||
|
|
||||||
void Tokenizer::splitTemplateRightAngleBrackets(bool check)
|
void Tokenizer::splitTemplateRightAngleBrackets(bool check)
|
||||||
{
|
{
|
||||||
std::set<std::string> vars;
|
std::vector<std::pair<std::string, int>> vars;
|
||||||
|
|
||||||
|
int scopeLevel = 0;
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
|
if (tok->str() == "{")
|
||||||
|
++scopeLevel;
|
||||||
|
else if (tok->str() == "}") {
|
||||||
|
vars.erase(std::remove_if(vars.begin(), vars.end(), [scopeLevel](const std::pair<std::string, int>& v) {
|
||||||
|
return v.second == scopeLevel;
|
||||||
|
}), vars.end());
|
||||||
|
--scopeLevel;
|
||||||
|
}
|
||||||
if (Token::Match(tok, "[;{}] %type% %type% [;,=]") && tok->next()->isStandardType())
|
if (Token::Match(tok, "[;{}] %type% %type% [;,=]") && tok->next()->isStandardType())
|
||||||
vars.insert(tok->strAt(2));
|
vars.emplace_back(tok->strAt(2), scopeLevel);
|
||||||
|
|
||||||
// Ticket #6181: normalize C++11 template parameter list closing syntax
|
// Ticket #6181: normalize C++11 template parameter list closing syntax
|
||||||
if (tok->previous() && tok->str() == "<" && TemplateSimplifier::templateParameters(tok) && vars.find(tok->previous()->str()) == vars.end()) {
|
if (tok->previous() && tok->str() == "<" && TemplateSimplifier::templateParameters(tok) && std::none_of(vars.begin(), vars.end(), [&](const std::pair<std::string, int>& v) {
|
||||||
|
return v.first == tok->previous()->str();
|
||||||
|
})) {
|
||||||
Token *endTok = tok->findClosingBracket();
|
Token *endTok = tok->findClosingBracket();
|
||||||
if (check) {
|
if (check) {
|
||||||
if (Token::Match(endTok, ">>|>>="))
|
if (Token::Match(endTok, ">>|>>="))
|
||||||
|
@ -6022,7 +6033,9 @@ void Tokenizer::splitTemplateRightAngleBrackets(bool check)
|
||||||
endTok->insertToken("=");
|
endTok->insertToken("=");
|
||||||
endTok->insertToken(">");
|
endTok->insertToken(">");
|
||||||
}
|
}
|
||||||
} else if (Token::Match(tok, "class|struct|union|=|:|public|protected|private %name% <") && vars.find(tok->next()->str()) == vars.end()) {
|
} else if (Token::Match(tok, "class|struct|union|=|:|public|protected|private %name% <") && std::none_of(vars.begin(), vars.end(), [&](const std::pair<std::string, int>& v) {
|
||||||
|
return v.first == tok->next()->str();
|
||||||
|
})) {
|
||||||
Token *endTok = tok->tokAt(2)->findClosingBracket();
|
Token *endTok = tok->tokAt(2)->findClosingBracket();
|
||||||
if (check) {
|
if (check) {
|
||||||
if (Token::simpleMatch(endTok, ">>"))
|
if (Token::simpleMatch(endTok, ">>"))
|
||||||
|
|
|
@ -3939,6 +3939,14 @@ private:
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(std::string::npos, tokenizeAndStringify(code).find("> >"));
|
ASSERT_EQUALS(std::string::npos, tokenizeAndStringify(code).find("> >"));
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
const char code[] = "struct S { bool vector; };\n"
|
||||||
|
"struct T { std::vector<std::shared_ptr<int>> v; };\n";
|
||||||
|
ASSERT_EQUALS("struct S { bool vector ; } ;\n"
|
||||||
|
"struct T { std :: vector < std :: shared_ptr < int > > v ; } ;",
|
||||||
|
tokenizeAndStringify(code));
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cpp03template1() {
|
void cpp03template1() {
|
||||||
|
|
Loading…
Reference in New Issue