From e8c3a80678a0b695eb643cd87879a277a1c99cd8 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 1 Feb 2023 14:53:57 +0100 Subject: [PATCH] Improve --check-library error message (#4755) --- lib/token.cpp | 24 ++++++++++++------------ test/testfunctions.cpp | 10 ++++++++++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/token.cpp b/lib/token.cpp index 012c6e86a..9b1bdece3 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -2300,19 +2300,19 @@ std::pair Token::typeDecl(const Token* tok, bool poi if (vt && vt->containerTypeToken) return { vt->containerTypeToken, vt->containerTypeToken->linkAt(-1) }; } - if (pointedToType && astIsSmartPointer(var->nameToken())) { - const ValueType* vt = var->valueType(); - if (vt && vt->smartPointerTypeToken) - return { vt->smartPointerTypeToken, vt->smartPointerTypeToken->linkAt(-1) }; - } - if (pointedToType && astIsIterator(var->nameToken())) { - const ValueType* vt = var->valueType(); - if (vt && vt->containerTypeToken) - return { vt->containerTypeToken, vt->containerTypeToken->linkAt(-1) }; - } - if (result.first) - return result; } + if (pointedToType && astIsSmartPointer(var->nameToken())) { + const ValueType* vt = var->valueType(); + if (vt && vt->smartPointerTypeToken) + return { vt->smartPointerTypeToken, vt->smartPointerTypeToken->linkAt(-1) }; + } + if (pointedToType && astIsIterator(var->nameToken())) { + const ValueType* vt = var->valueType(); + if (vt && vt->containerTypeToken) + return { vt->containerTypeToken, vt->containerTypeToken->linkAt(-1) }; + } + if (result.first) + return result; return {var->typeStartToken(), var->typeEndToken()->next()}; } else if (Token::simpleMatch(tok, "return")) { const Scope* scope = tok->scope(); diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 5b531894e..63be8faa4 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -1949,6 +1949,16 @@ private: "[test.cpp:5]: (information) --check-library: There is no matching configuration for function auto::push_back()\n", errout.str()); + check("struct F { void g(int); };\n" + "void f(std::list& l) {\n" + " std::list::iterator it;\n" + " for (it = l.begin(); it != l.end(); ++it)\n" + " it->g(0);\n" + "}\n"); + TODO_ASSERT_EQUALS("", + "[test.cpp:5]: (information) --check-library: There is no matching configuration for function F::g()\n", + errout.str()); + settings = settings_old; }