diff --git a/lib/checkio.cpp b/lib/checkio.cpp index fa896a7d3..8b0c49974 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -1306,6 +1306,8 @@ void CheckIO::checkFormatString(const Token * const tok, // Count printf/scanf parameters.. int numFunction = 0; while (argListTok2) { + if (Token::Match(argListTok2, "%name% ...")) // bailout for parameter pack + return; numFunction++; argListTok2 = argListTok2->nextArgument(); // Find next argument } diff --git a/test/testio.cpp b/test/testio.cpp index ab200834a..91280a0fe 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -80,6 +80,7 @@ private: TEST_CASE(testPrintfAuto); // #8992 TEST_CASE(testPrintfParenthesis); // #8489 TEST_CASE(testStdDistance); // #10304 + TEST_CASE(testParameterPack); // #11289 } #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) @@ -4868,6 +4869,16 @@ private: "}", /*inconclusive*/ false, /*portability*/ true); ASSERT_EQUALS("", errout.str()); } + + void testParameterPack() { // #11289 + check("template auto f(const char* format, const Args&... args) {\n" + " return snprintf(nullptr, 0, format, args...);\n" + "}\n" + "void g() {\n" + " f(\"%d%d\", 1, 2);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestIO)