diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7a218f668..a89975128 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2825,6 +2825,12 @@ void Tokenizer::simplifyTemplates() endTok->str(">"); endTok->insertToken(">"); } + } else if (Token::Match(tok, "class|struct|union|=|:|public|protected|private %name% <")) { + Token *endTok = tok->tokAt(2)->findClosingBracket(); + if (Token::Match(endTok, ">> ;|{")) { + endTok->str(">"); + endTok->insertToken(">"); + } } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 1d9ea705b..c71cd064c 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -343,6 +343,7 @@ private: TEST_CASE(cpp0xtemplate2); TEST_CASE(cpp0xtemplate3); TEST_CASE(cpp0xtemplate4); // Ticket #6181: Mishandled C++11 syntax + TEST_CASE(cpp0xtemplate5); // Ticket #9154 change >> to > > TEST_CASE(cpp14template); // Ticket #6708 TEST_CASE(arraySize); @@ -5266,6 +5267,34 @@ private: "}"); } + void cpp0xtemplate5() { // #9154 + { + const char *code = "struct s>;"; + ASSERT_EQUALS("struct s < x < u . . . > > ;", + tokenizeAndStringify(code)); + } + { + const char *code = "template using c = e,b...>>;"; + ASSERT_EQUALS("template < class f > using c = e < i < q < f , r > , b . . . > > ;", + tokenizeAndStringify(code)); + } + { + const char *code = "struct s> { };"; + ASSERT_EQUALS("struct s < x < u . . . > > { } ;", + tokenizeAndStringify(code)); + } + { + const char *code = "struct q : s> { };"; + ASSERT_EQUALS("struct q : s < x < u . . . > > { } ;", + tokenizeAndStringify(code)); + } + { + const char *code = "struct q : private s> { };"; + ASSERT_EQUALS("struct q : private s < x < u . . . > > { } ;", + tokenizeAndStringify(code)); + } + } + void cpp14template() { // Ticket #6708 tokenizeAndStringify("template " "decltype(auto) forward(T& t) { return 0; }");