Skip to content

Commit e7fb594

Browse files
authored
fix #13592: False positive (regression): warning: printf format string requires 1 parameter but 4 are given. [wrongPrintfScanfArgNum] (#7269)
1 parent efef484 commit e7fb594

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/tokenize.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3718,7 +3718,7 @@ void Tokenizer::simplifyParenthesizedLibraryFunctions()
37183718
if (!Token::simpleMatch(tok, ") ("))
37193719
continue;
37203720
Token *rpar = tok, *lpar = tok->link();
3721-
if (!lpar)
3721+
if (!lpar || Token::Match(lpar->previous(), "%name%"))
37223722
continue;
37233723
const Token *ftok = rpar->previous();
37243724
if (mSettings.library.isNotLibraryFunction(ftok))

test/testio.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class TestIO : public TestFixture {
7878
TEST_CASE(testParameterPack); // #11289
7979

8080
TEST_CASE(testDefaultSignInt); // #13363
81+
TEST_CASE(testPrintfWithGeneric); // #13592
8182
}
8283

8384
struct CheckOptions
@@ -4952,6 +4953,16 @@ class TestIO : public TestFixture {
49524953
check(code, dinit(CheckOptions, $.defaultSign = 'u'));
49534954
ASSERT_EQUALS("", errout_str());
49544955
}
4956+
4957+
void testPrintfWithGeneric() { // #13592
4958+
const char code[] =
4959+
"void f(void) {\n"
4960+
" float x = 27.0f;\n"
4961+
" printf(\"%s\\n\", _Generic(x, double: cbrt, float: cbrtf)(x));\n"
4962+
"}\n";
4963+
check(code);
4964+
ASSERT_EQUALS("", errout_str());
4965+
}
49554966
};
49564967

49574968
REGISTER_TEST(TestIO)

0 commit comments

Comments
 (0)