From 57c3d48711236e7438ac73609ae1d91560955798 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Mon, 7 Jan 2013 15:19:53 +0100 Subject: [PATCH] error when trying to break/continue outside of loops/switches instead of segfaulting at codegen --- parser.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/parser.c b/parser.c index d374af7..4432ed4 100644 --- a/parser.c +++ b/parser.c @@ -2644,6 +2644,13 @@ static bool parse_break_continue(parser_t *parser, ast_block *block, ast_express return false; } + if (!vec_size(loops)) { + if (is_continue) + parseerror(parser, "`continue` can only be used inside loops"); + else + parseerror(parser, "`break` can only be used inside loops or switches"); + } + if (parser->tok == TOKEN_IDENT) { if (!OPTS_FLAG(LOOP_LABELS)) parseerror(parser, "labeled loops not activated, try using -floop-labels"); -- 2.39.2