Fixed bug in fixAngleBrackets

This commit is contained in:
Daniel Marjamäki 2020-11-29 12:56:13 +01:00
parent e2debac882
commit 7112f69d7b
2 changed files with 21 additions and 0 deletions

View File

@ -865,6 +865,16 @@ const Token * Token::findClosingBracket() const
const bool templateParameter(strAt(-1) == "template"); const bool templateParameter(strAt(-1) == "template");
std::set<std::string> templateParameters; std::set<std::string> templateParameters;
bool isDecl = true;
for (const Token *prev = previous(); prev; prev = prev->previous()) {
if (prev->str() == "=")
isDecl = false;
if (Token::simpleMatch(prev, "template <"))
isDecl = true;
if (Token::Match(prev, "[;{}]"))
break;
}
unsigned int depth = 0; unsigned int depth = 0;
for (closing = this; closing != nullptr; closing = closing->next()) { for (closing = this; closing != nullptr; closing = closing->next()) {
if (Token::Match(closing, "{|[|(")) { if (Token::Match(closing, "{|[|(")) {
@ -882,6 +892,8 @@ const Token * Token::findClosingBracket() const
if (--depth == 0) if (--depth == 0)
return closing; return closing;
} else if (closing->str() == ">>" || closing->str() == ">>=") { } else if (closing->str() == ">>" || closing->str() == ">>=") {
if (!isDecl && depth == 1)
continue;
if (depth <= 2) if (depth <= 2)
return closing; return closing;
depth -= 2; depth -= 2;

View File

@ -348,6 +348,8 @@ private:
TEST_CASE(functionAttributeBefore); TEST_CASE(functionAttributeBefore);
TEST_CASE(functionAttributeAfter); TEST_CASE(functionAttributeAfter);
TEST_CASE(fixAngleBrackets);
TEST_CASE(cpp03template1); TEST_CASE(cpp03template1);
TEST_CASE(cpp0xtemplate1); TEST_CASE(cpp0xtemplate1);
TEST_CASE(cpp0xtemplate2); TEST_CASE(cpp0xtemplate2);
@ -5270,6 +5272,13 @@ private:
ASSERT(func5 && func5->isAttributeNoreturn()); ASSERT(func5 && func5->isAttributeNoreturn());
} }
void fixAngleBrackets() {
{
const char *code = "; z = x < 0 ? x >> y : x >> y;";
ASSERT_EQUALS("; z = x < 0 ? x >> y : x >> y ;", tokenizeAndStringify(code));
}
}
void cpp03template1() { void cpp03template1() {
{ {
const char *code = "template<typename> struct extent {};"; const char *code = "template<typename> struct extent {};";