File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -2579,8 +2579,8 @@ static bool isEarlyExit(const Token *start)
2579
2579
if (start->str () != " {" )
2580
2580
return false ;
2581
2581
const Token *endToken = start->link ();
2582
- const Token *tok = Token::findmatch (start, " return|throw|break" , endToken);
2583
- if (!tok)
2582
+ const Token *tok = Token::findmatch (start, " return|throw|break|continue " , endToken);
2583
+ if (!tok || tok-> scope () != start-> scope () || tok-> str () == " continue " )
2584
2584
return false ;
2585
2585
const Token *endStatement = Token::findsimplematch (tok, " ; }" , endToken);
2586
2586
if (!endStatement)
Original file line number Diff line number Diff line change @@ -5873,6 +5873,28 @@ class TestStl : public TestFixture {
5873
5873
" return b;\n "
5874
5874
" }\n " );
5875
5875
ASSERT_EQUALS (" " , errout_str ());
5876
+
5877
+ check (" bool get_index(const std::vector<int>& items, int value, size_t& index) {\n " // #14047
5878
+ " size_t current_index = 0;\n "
5879
+ " for (size_t i = 0; i < items.size(); ++i) {\n "
5880
+ " if (items[i] == value) {\n "
5881
+ " if (current_index != index) {\n "
5882
+ " current_index++;\n "
5883
+ " continue;\n "
5884
+ " }\n "
5885
+ " index = i;\n "
5886
+ " return true;\n "
5887
+ " }\n "
5888
+ " }\n "
5889
+ " return false;\n "
5890
+ " }\n "
5891
+ " int main() {\n "
5892
+ " std::vector<int> items{ 0, 1, 1, 1 };\n "
5893
+ " size_t index = 2;\n "
5894
+ " get_index(items, 1, index);\n "
5895
+ " return index;\n "
5896
+ " }\n " );
5897
+ ASSERT_EQUALS (" " , errout_str ());
5876
5898
}
5877
5899
5878
5900
void loopAlgoMinMax () {
You can’t perform that action at this time.
0 commit comments