Curious behavior of continue command inside a macro body
project(proj)
set(vec 1 2 3)
macro(please_continue val)
message(">> val ${val}")
if("${val}" EQUAL 2)
message(">> before continue for ${val}")
continue()
message(">> after continue for val ${val}")
endif()
message(">> after if for val ${val}")
endmacro()
foreach(elem IN LISTS vec)
please_continue(${elem})
endforeach()
The output is:
>> val 1
>> after if for val 1
>> val 2
>> before continue for 2
>> after if for val 2
>> val 3
>> after if for val 3
I would expect >> after if for val 2
not to be shown. It seems like it continue()
s out of the if
command rather than the foreach
command.
This is not documented of course, the docs for macro
only mention return
.
It is still surprising behavior.