From 3159d151d30c1b5d2fc9c88420788468a99b037d Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Sun, 21 Jan 2018 15:22:26 -0500 Subject: [PATCH] Fix symbol database crash on template type aliases by ignoring them. (#1045) --- lib/symboldatabase.cpp | 2 +- test/testsymboldatabase.cpp | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 5bf6ca913..6b61fda3b 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -278,7 +278,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() // using type alias else if (_tokenizer->isCPP() && Token::Match(tok, "using %name% =")) { - if (!findType(tok->next(), scope)) { + if (tok->strAt(-1) != ">" && !findType(tok->next(), scope)) { // fill typeList.. typeList.push_back(Type(tok, nullptr, scope)); Type* new_type = &typeList.back(); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index b0101feae..920fcd0ef 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -351,7 +351,8 @@ private: TEST_CASE(unionWithConstructor); TEST_CASE(using1); - TEST_CASE(using2); // #8331 + TEST_CASE(using2); // #8331 (segmentation fault) + TEST_CASE(using3); // #8343 (segmentation fault) } void array() { @@ -5390,6 +5391,17 @@ private: settings1.standards.cpp = original_std; } + void using3() { // #8343 (segmentation fault) + Standards::cppstd_t original_std = settings1.standards.cpp; + settings1.standards.cpp = Standards::CPP11; + GET_SYMBOL_DB("template \n" + "using vector = typename MemoryModel::template vector;\n" + "vector m_bits;"); + settings1.standards.cpp = original_std; + + ASSERT(db); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestSymbolDatabase)