diff --git a/lib/token.cpp b/lib/token.cpp index 8fb104c1c..42c450b38 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -2270,7 +2270,7 @@ std::pair 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 diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 9dc8fc70e..088582f23 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -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; diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 3e53ca8ce..e72194af0 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -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(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" diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 78ac42431..dfb01f8d7 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7535,6 +7535,13 @@ private: "}\n", "{ } }", TokenImpl::Cpp11init::NOINIT); + + testIsCpp11init("template \n" + "struct C : public C, public B {\n" + " ~C() {}\n" + "};\n", + "{ } }", + TokenImpl::Cpp11init::NOINIT); #undef testIsCpp11init } };