On Tue Aug 26, 2025 at 9:53 PM CEST, Joseph Myers wrote: > There has been a significant discussion on the reflector in the past few > days concerning jumping backwards across a defer block within a scope. > How do you handle this case, what is the rationale for the decisions made > about that case, and are there appropriate testcases for it included? > > int v () { > int n = 0; > b: if (n >= 5) return 1; > defer { fputs("message", stdout); } > n++; > goto b; > }
this is similar to the failure test `i ()` in gcc/testsuite/gcc.dg/defer-2.c, and the technical specification covers such case: > 6.4: > Constraints: > Jumps by means of goto in E shall not jump over a defer statement in E. for a rationale, i don't quite see one in the ts itself, but for myself, i'd say it makes sense, as otherwise we'd need to either execute the deferred block when jumping back, or allow it to be reached multiple times while only executing on scope exit proper, both behaviours can seem unintuitive, depending on user expectation thus the patchset currently outputs the following error: > nya.c: In function 'main': > nya.c:9:9: error: jump over defer block > 9 | goto b; > | ^~~~ > nya.c:5:1: note: label 'b' defined here > 5 | b: if (n >= 5) return 1; > | ^
68990292A7A98C5E.asc
Description: application/pgp-keys
signature.asc
Description: PGP signature