diff libinterp/parse-tree/oct-parse.yy @ 26981:12532d392693

error if continue is used outside of a for loop (bug #55995) * oct-parse.yy (jump_command): Handle CONTINUE the same way as BREAK. (base_parser::make_continue_command): Error if "continue" is not inside a loop command.
author John W. Eaton <jwe@octave.org>
date Tue, 26 Mar 2019 15:48:31 +0000
parents db59dabf1685
children 258195ea1a76
line wrap: on
line diff
--- a/libinterp/parse-tree/oct-parse.yy	Tue Mar 26 14:06:44 2019 +0000
+++ b/libinterp/parse-tree/oct-parse.yy	Tue Mar 26 15:48:31 2019 +0000
@@ -1228,7 +1228,10 @@
                       YYABORT;
                   }
                 | CONTINUE
-                  { $$ = parser.make_continue_command ($1); }
+                  {
+                    if (! ($$ = parser.make_continue_command ($1)))
+                      YYABORT;
+                  }
                 | FUNC_RET
                   { $$ = parser.make_return_command ($1); }
                 ;
@@ -2991,7 +2994,13 @@
     int l = continue_tok->line ();
     int c = continue_tok->column ();
 
-    return new tree_continue_command (l, c);
+    if (! m_lexer.m_looping)
+      {
+        bison_error ("continue must appear in a loop in the same file as loop command");
+        return nullptr;
+      }
+    else
+      return new tree_continue_command (l, c);
   }
 
   // Build a return command.