File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3918,3 +3918,23 @@ const Token *skipUnreachableBranch(const Token *tok)
39183918
39193919 return tok;
39203920}
3921+
3922+ bool isEscapeKeyword (const Token *tok, const Settings &settings)
3923+ {
3924+ if (!tok)
3925+ return false ;
3926+
3927+ if (tok->str () == " return" )
3928+ return true ;
3929+
3930+ if (!tok->isCpp ())
3931+ return false ;
3932+
3933+ if (tok->str () == " throw" )
3934+ return true ;
3935+
3936+ if (settings.standards .cpp < Standards::CPP20 )
3937+ return false ;
3938+
3939+ return tok->str () == " co_return" ;
3940+ }
Original file line number Diff line number Diff line change @@ -463,4 +463,6 @@ bool isUnreachableOperand(const Token *tok);
463463
464464const Token *skipUnreachableBranch (const Token *tok);
465465
466+ bool isEscapeKeyword (const Token *tok, const Settings &settings);
467+
466468#endif // astutilsH
Original file line number Diff line number Diff line change @@ -144,7 +144,7 @@ namespace {
144144 // If we are in a loop then jump to the end
145145 if (out)
146146 *out = loopEnds.back ();
147- } else if (Token::Match (tok, " return|throw " )) {
147+ } else if (isEscapeKeyword (tok, settings )) {
148148 traverseRecursive (tok->astOperand2 (), f, traverseUnknown);
149149 traverseRecursive (tok->astOperand1 (), f, traverseUnknown);
150150 return Break (Analyzer::Terminate::Escape);
Original file line number Diff line number Diff line change @@ -146,6 +146,7 @@ class TestNullPointer : public TestFixture {
146146 TEST_CASE (nullpointer106); // #13682
147147 TEST_CASE (nullpointer107); // #13682 (FP/FN cases around guards that depend on the pointer indirectly)
148148 TEST_CASE (nullpointer108);
149+ TEST_CASE (nullpointer109);
149150 TEST_CASE (nullpointer_addressOf); // address of
150151 TEST_CASE (nullpointerSwitch); // #2626
151152 TEST_CASE (nullpointer_cast); // #4692
@@ -3115,6 +3116,18 @@ class TestNullPointer : public TestFixture {
31153116 ASSERT_EQUALS (" [test.cpp:4:10]: (error) Null pointer dereference: r [nullPointer]\n " , errout_str ());
31163117 }
31173118
3119+ void nullpointer109 ()
3120+ {
3121+ check (" boost::asio::awaitable<int> test()\n "
3122+ " {\n "
3123+ " const auto *s = getStr();\n "
3124+ " if(!s) co_return int{1};\n "
3125+ " std::print(\" {}\" ,*s);\n "
3126+ " co_return int{9};\n "
3127+ " }\n " );
3128+ ASSERT_EQUALS (" " , errout_str ());
3129+ }
3130+
31183131 void nullpointer_addressOf () { // address of
31193132 check (" void f() {\n "
31203133 " struct X *x = 0;\n "
You can’t perform that action at this time.
0 commit comments