diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index e26744aeb..52cd55162 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1860,8 +1860,14 @@ void Tokenizer::combineOperators() // combine +-*/ and = if (c2 == '=' && (std::strchr("+-*/%|^=!<>", c1))) { - if (cpp && Token::Match(tok->tokAt(-2), "< %any% >")) - continue; + // skip templates + if (cpp && tok->str() == ">") { + const Token *opening = tok->findOpeningBracket(); + if (opening) { + if (Token::Match(opening->previous(), "%name%")) + continue; + } + } tok->str(tok->str() + c2); tok->deleteNext(); continue; diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index ddf4a9f9f..a347f5b41 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -137,6 +137,7 @@ private: TEST_CASE(template97); TEST_CASE(template98); // #8959 TEST_CASE(template99); // #8960 + TEST_CASE(template100); // #8967 TEST_CASE(template_specialization_1); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_specialization_2); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template) @@ -2101,6 +2102,21 @@ private: ASSERT_EQUALS(exp, tok(code)); } + void template100() { // #8967 + const char code[] = "enum class Device { I2C0, I2C1 };\n" + "template \n" + "const char* deviceFile;\n" + "template <>\n" + "const char* deviceFile = \"/tmp/i2c-0\";\n"; + + const char exp[] = "enum class Device { I2C0 , I2C1 } ; " + "template < Device D > " + "const char * deviceFile ; " + "const char * deviceFile ; deviceFile = \"/tmp/i2c-0\" ;"; + + ASSERT_EQUALS(exp, tok(code)); + } + void template_specialization_1() { // #7868 - template specialization template struct S> {..}; const char code[] = "template struct C {};\n" "template struct S {a};\n"