From 0854fda28acc715defd384da2681d9506cc02c18 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sat, 3 Dec 2022 07:50:21 +0100 Subject: [PATCH] Get type from smartpointer (#4608) * Fix #11223 checkLibraryFunction treats "auto" as type * Use utility function * Get type from 'auto p = new ...' * Fix merge * Add test for recent fix * Format * Get type from smartpointer --- lib/token.cpp | 5 +++++ test/testfunctions.cpp | 6 ++++++ test/testtokenize.cpp | 2 ++ 3 files changed, 13 insertions(+) diff --git a/lib/token.cpp b/lib/token.cpp index 31ef9cad2..3a0e4987b 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -2278,6 +2278,11 @@ std::pair Token::typeDecl(const Token * tok) if (vt && vt->containerTypeToken) return { vt->containerTypeToken, vt->containerTypeToken->linkAt(-1) }; } + if (astIsSmartPointer(var->nameToken())) { + const ValueType* vt = var->valueType(); + if (vt && vt->smartPointerTypeToken) + return { vt->smartPointerTypeToken, vt->smartPointerTypeToken->linkAt(-1) }; + } } return {var->typeStartToken(), var->typeEndToken()->next()}; } else if (Token::simpleMatch(tok, "return")) { diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 5ba700e26..c39663371 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -1916,6 +1916,12 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + check("void f() {\n" + " auto p = std::make_shared>();\n" + " p->push_back(1);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + settings.severity = severity_old; settings.checkLibrary = false; } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 1cf64dc31..6b57caaf7 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6758,6 +6758,8 @@ private: "void h() { " " [func=foo]{func();}(); " "}")); + ASSERT_NO_THROW(tokenizeAndStringify("template constexpr int n = 1;\n" + "template T a[n];\n")); // op op