diff --git a/lib/checkstring.cpp b/lib/checkstring.cpp index c6d4cb88cab..64b575df72d 100644 --- a/lib/checkstring.cpp +++ b/lib/checkstring.cpp @@ -318,6 +318,7 @@ void CheckString::checkIncorrectStringCompare() } } } else if (Token::Match(tok, "%str%|%char%") && + !Token::Match(tok->next(), "%name%") && isUsedAsBool(tok, *mSettings) && !isMacroUsage(tok)) incorrectStringBooleanError(tok, tok->str()); diff --git a/test/teststring.cpp b/test/teststring.cpp index 3d07b4774a9..02bf749bf04 100644 --- a/test/teststring.cpp +++ b/test/teststring.cpp @@ -823,6 +823,13 @@ class TestString : public TestFixture { " if (strequ(p, \"ALL\")) {}\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("void f(std::string_view);\n" + "void f(bool);\n" + "void g() {\n" + " f(\"\"sv);\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void deadStrcmp() {