Partial fix for #11378 internalAstError regressions (iscpp11init) (#4629)

* Partial fix for #11378 internalAstError regressions (iscpp11init)

* Use %cop%

* Add test for #11229

* Format

* Format
This commit is contained in:
chrchr-github 2022-12-16 10:46:15 +01:00 committed by GitHub
parent 9c55b933c1
commit 4c8aa56d8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 2 deletions

View File

@ -2270,7 +2270,7 @@ std::pair<const Token*, const Token*> Token::typeDecl(const Token* tok, bool poi
const Token* declEnd = nextAfterAstRightmostLeaf(tok2->astOperand1());
if (Token::simpleMatch(declEnd, "<") && declEnd->link())
declEnd = declEnd->link()->next();
return { tok2->next(), declEnd };
return { tok2->next(), declEnd };
}
}
if (astIsRangeBasedForDecl(var->nameToken()) && astIsContainer(var->nameToken()->astParent()->astOperand2())) { // range-based for

View File

@ -691,7 +691,7 @@ static bool iscpp11init_impl(const Token * const tok)
if (!Token::simpleMatch(endtok, "} ;"))
return true;
const Token *prev = nameToken;
while (Token::Match(prev, "%name%|::|:|<|>|,|%num%")) {
while (Token::Match(prev, "%name%|::|:|<|>|,|%num%|%cop%")) {
if (Token::Match(prev, "class|struct|union|enum"))
return false;

View File

@ -140,6 +140,7 @@ private:
TEST_CASE(nullpointer94); // #11040
TEST_CASE(nullpointer95); // #11142
TEST_CASE(nullpointer96); // #11416
TEST_CASE(nullpointer97); // #11229
TEST_CASE(nullpointer_addressOf); // address of
TEST_CASE(nullpointerSwitch); // #2626
TEST_CASE(nullpointer_cast); // #4692
@ -2783,6 +2784,20 @@ private:
ASSERT_EQUALS("", errout.str());
}
void nullpointer97() // #11229
{
check("struct B { virtual int f() = 0; };\n"
"struct D : public B { int f() override; };\n"
"int g(B* p) {\n"
" if (p) {\n"
" auto d = dynamic_cast<B*>(p);\n"
" return d ? d->f() : 0;\n"
" }\n"
" return 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void nullpointer_addressOf() { // address of
check("void f() {\n"
" struct X *x = 0;\n"

View File

@ -7535,6 +7535,13 @@ private:
"}\n",
"{ } }",
TokenImpl::Cpp11init::NOINIT);
testIsCpp11init("template <std::size_t N>\n"
"struct C : public C<N - 1>, public B {\n"
" ~C() {}\n"
"};\n",
"{ } }",
TokenImpl::Cpp11init::NOINIT);
#undef testIsCpp11init
}
};