From 4dbcfd25b33f0fd205efc7014f3c9e7da93114ad Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Wed, 16 Dec 2020 15:27:41 +0100 Subject: [PATCH] Fix non support of break in M_LET_IF --- m-core.h | 4 ++-- tests/test-mcore.c | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/m-core.h b/m-core.h index a925136a..14bb0bbe 100644 --- a/m-core.h +++ b/m-core.h @@ -3135,7 +3135,7 @@ m_core_parse2_enum (const char str[], const char **endptr) #define M_DEFER_INTERNAL(clear, cont) \ for(bool cont = true; cont; cont = false) \ - for( (void) 0; cont ; (clear)) \ + for( (void) 0; cont ; (clear), cont = false) \ for( (void) 0; cont; cont = false) \ @@ -3157,7 +3157,7 @@ m_core_parse2_enum (const char str[], const char **endptr) #define M_LET_IF_INTERNAL(init, test, clear, else_a, cont) \ for(bool cont = true; cont; cont = false) \ - for( init ; cont && ( (test) || (else_a, false) ); (clear)) \ + for( init ; cont && ( (test) || (else_a, false) ); (clear), cont = false) \ for( (void) 0; cont; cont = false) \ diff --git a/tests/test-mcore.c b/tests/test-mcore.c index 1a30cdc7..db13997b 100644 --- a/tests/test-mcore.c +++ b/tests/test-mcore.c @@ -214,6 +214,13 @@ static void test_let(void) } assert(c++ == 14); + M_LET_IF( assert(c++ == 15), (assert(c++ == 16), true), assert(c++ == 18) ) { + assert(c++ == 17); + break; + assert(0); + } + assert(c++ == 19); + c = 7; int *p = (int*)malloc(sizeof(int)); assert(p != NULL); @@ -222,6 +229,12 @@ static void test_let(void) assert(c++ == 7); } assert(c++ == 9); + M_DEFER ( assert(c++ == 11) ) { + assert(c++ == 10); + break; + assert(0); + } + assert(c++ == 12); } static void test_va(void)