From fee86b9684bed0e7a5c095b5f534963e0a94fb9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 5 Apr 2017 22:05:29 +0200 Subject: [PATCH] ValueType: Better handling of 'new Container' --- lib/symboldatabase.cpp | 8 ++++++++ test/testsymboldatabase.cpp | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 9c0578625..ec7f566b3 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -5031,6 +5031,14 @@ void SymbolDatabase::setValueTypeInTokenList() const Token *typeTok = tok->next(); if (Token::Match(typeTok, "( std| ::| nothrow )")) typeTok = typeTok->link()->next(); + if (const Library::Container *c = _settings->library.detectContainer(typeTok)) { + ValueType vt; + vt.pointer = 1; + vt.container = c; + vt.type = ValueType::Type::CONTAINER; + setValueType(tok, vt); + continue; + } std::string typestr; while (Token::Match(typeTok, "%name% :: %name%")) { typestr += typeTok->str() + "::"; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 96e0ba26a..7fc171a1d 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -4431,6 +4431,14 @@ private: ASSERT_EQUALS(true, vt.fromLibraryType("s32", &settingsUnix32)); ASSERT_EQUALS(ValueType::Type::INT, vt.type); } + { + // Container + Settings sC; + Library::Container c; + c.startPattern = "C"; + sC.library.containers["C"] = c; + ASSERT_EQUALS("container(C) *", typeOf("C*c=new C;","new","test.cpp",&sC)); + } // new ASSERT_EQUALS("C *", typeOf("class C {}; x = new C();", "new"));