Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ namespace {
return;
while (tok->str() == "}" && !scopeInfo->empty() && tok == scopeInfo->back().bodyEnd)
scopeInfo->pop_back();
if (!Token::Match(tok, "namespace|class|struct|union %name% {|:|::")) {
if (!Token::Match(tok, "namespace|class|struct|union %name% {|:|::|<")) {
// check for using namespace
if (Token::Match(tok, "using namespace %name% ;|::")) {
const Token * tok1 = tok->tokAt(2);
Expand Down Expand Up @@ -1778,6 +1778,12 @@ namespace {
while (tok && !Token::Match(tok, ";|{"))
tok = tok->next();
}
// skip template parameters
if (tok && tok->str() == "<") {
tok = tok->findClosingBracket();
if (tok)
tok = tok->next();
}
if (tok && tok->str() == "{") {
scopeInfo->emplace_back(classname,tok->link());
}
Expand Down
16 changes: 16 additions & 0 deletions test/testsimplifyusing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class TestSimplifyUsing : public TestFixture {
TEST_CASE(simplifyUsing9385);
TEST_CASE(simplifyUsing9388);
TEST_CASE(simplifyUsing9518);
TEST_CASE(simplifyUsing9757);
}

std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) {
Expand Down Expand Up @@ -627,6 +628,21 @@ class TestSimplifyUsing : public TestFixture {
ASSERT_EQUALS(exp, tok(code, false));
}

void simplifyUsing9757() {
const char code[] = "enum class Type_t { Nil = 0 };\n"
"template<Type_t type> class MappedType { };\n"
"template<> class MappedType<Type_t::Nil> { using type = void; };\n"
"std::string to_string (Example::Type_t type) {\n"
" switch (type) {}\n"
"}";
const char exp[] = "enum class Type_t { Nil = 0 } ; "
"class MappedType<Type_t::Nil> ; "
"template < Type_t type > class MappedType { } ; "
"class MappedType<Type_t::Nil> { } ; "
"std :: string to_string ( Example :: Type_t type ) { "
"switch ( type ) { } }";
ASSERT_EQUALS(exp, tok(code, false));
}
};

REGISTER_TEST(TestSimplifyUsing)