diff --git a/lib/checkvaarg.cpp b/lib/checkvaarg.cpp index 8e25fca71..d7801dd16 100644 --- a/lib/checkvaarg.cpp +++ b/lib/checkvaarg.cpp @@ -114,7 +114,10 @@ void CheckVaarg::va_list_usage() tok = tok->linkAt(1); } else if (Token::Match(tok, "throw|return")) exitOnEndOfStatement = true; - else if (!open && tok->varId() == var->declarationId()) + else if (_tokenizer->isCPP() && tok->str() == "try") { + open = false; + break; + } else if (!open && tok->varId() == var->declarationId()) va_list_usedBeforeStartedError(tok, var->name()); else if (exitOnEndOfStatement && tok->str() == ";") break; diff --git a/test/testvaarg.cpp b/test/testvaarg.cpp index 8e7c6f11f..8d152f39b 100644 --- a/test/testvaarg.cpp +++ b/test/testvaarg.cpp @@ -116,6 +116,18 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + // #6186 + check("void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\n" + " va_list arg_ptr;\n" + " va_start(arg_ptr, szBuffer);\n" + " try {\n" + " throw sth;\n" + " } catch(...) {\n" + " va_end(arg_ptr);\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); + check("void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\n" " va_list arg_ptr;\n" " va_start(arg_ptr, szBuffer);\n"