From 466da1e77a5d351acfd3cc5ff2503a7ce4ff8dca Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sun, 13 Aug 2023 22:24:17 +0200 Subject: [PATCH] Fix FP misusedScopedObject (#5321) --- lib/checkother.cpp | 2 +- test/testother.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 8663ed91e..9ab231a36 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2139,7 +2139,7 @@ void CheckOther::checkMisusedScopedObject() return; auto getConstructorTok = [](const Token* tok, std::string& typeStr) -> const Token* { - if (!Token::Match(tok, "[;{}] %name%")) + if (!Token::Match(tok, "[;{}] %name%") || tok->next()->isKeyword()) return nullptr; tok = tok->next(); typeStr.clear(); diff --git a/test/testother.cpp b/test/testother.cpp index eb1b30012..1d351ec34 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5648,6 +5648,12 @@ private: "[test.cpp:6]: (style) Instance of 'std::scoped_lock' object is destroyed immediately.\n" "[test.cpp:9]: (style) Instance of 'std::scoped_lock' object is destroyed immediately.\n", errout.str()); + + check("struct S { int i; };\n" + "namespace {\n" + " S s() { return ::S{42}; }\n" + "}\n", "test.cpp"); + ASSERT_EQUALS("", errout.str()); } void testMisusedScopeObjectAssignment() { // #11371