Fix #12013 crash: crashes in release builds if cppcheck build dir is used (#5489)

This commit is contained in:
chrchr-github 2023-09-27 16:44:22 +02:00 committed by GitHub
parent ca20152e51
commit 73d305ea46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -248,7 +248,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
continue;
// funcname ( => Assert that the end parentheses isn't followed by {
if (Token::Match(funcname, "%name% (|<")) {
if (Token::Match(funcname, "%name% (|<") && funcname->linkAt(1)) {
const Token *ftok = funcname->next();
if (ftok->str() == "<")
ftok = ftok->link();

View File

@ -52,6 +52,7 @@ private:
TEST_CASE(template7); // #9766 crash
TEST_CASE(template8);
TEST_CASE(template9);
TEST_CASE(template10);
TEST_CASE(throwIsNotAFunction);
TEST_CASE(unusedError);
TEST_CASE(unusedMain);
@ -358,6 +359,15 @@ private:
ASSERT_EQUALS("", errout.str());
}
void template10() {
check("template<typename T>\n" // #12013, don't crash
"struct S {\n"
" static const int digits = std::numeric_limits<T>::digits;\n"
" using type = std::conditional<digits < 32, std::int32_t, std::int64_t>::type;\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void throwIsNotAFunction() {
check("struct A {void f() const throw () {}}; int main() {A a; a.f();}");
ASSERT_EQUALS("", errout.str());