Boost logo

Boost :

Subject: Re: [boost] Interest in breakable labeled scope emulation?
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2013-01-14 02:42:39

Le 14/01/13 02:50, TONGARI a écrit :
> 2013/1/14 Brian Ravnsgaard Riis <brian_at_[hidden]>
>> Den Sun, 13 Jan 2013 20:30:14 +0100 skrev Vicente J. Botet Escriba <
>> vicente.botet_at_[hidden]>:
>> [snip]
>> Of course in order to be really structired the jumping to the underlying
>>> label should be forbiden (by the compiler), but I don't think that a
>>> preprocessor solution could take care of this. So the following not desired
>>> and not structured code could compile even if we would like an compile
>>> error.
>>> {
>>> // ...
>>> }
>>> // [1]
>>> //...
>>> BOOST_BREAK(L); // go to [1]
>> So, the underlying idea is to get something like "break" and "continue" to
>> work inside any "named" block, not just loops? If so (as you demonstrate
>> above) I'm fairly certain a correct solution cannot be implemented using
>> just the preprocessor.
> Hey guys,
> Please try the code attached and see the error message that your compiler
> gives.
> It DOES avoid the ill-formed code like that to compile.
Yeah. I was your macro forbid the access from outside the block. I
though that the trick was used only to be able to add a label at the end
of the block. But the use of the variable on the BREAK macro make it
fail. Really clever.

#define BOOST_SCOPE(name) \
if (const bool LABELED_SCOPE_##name = false){BOOST_BREAK(name);
name##_end_scope:;} else

#define BOOST_BREAK(name) \
(void)LABELED_SCOPE_##name; goto name##_end_scope

I have tried

int main()
cout << "123\n";
cout << "123\n";
return 0;

and here are the error for gcc

../example/test_so.cpp: In function ‘int main()’:
../example/test_so.cpp:22:1: erreur: ‘LABELED_SCOPE_a2’ was not declared
in this scope
../example/test_so.cpp:15:1: attention : jump to label ‘a2_end_scope’
../example/test_so.cpp:22:1: attention : à partir d'ici [-fpermissive]
../example/test_so.cpp:15:1: erreur: skips initialization of ‘const bool

and clang

../example/test_so.cpp:22:7: error: use of undeclared identifier
../example/test_so.cpp:10:7: note: expanded from macro 'BOOST_BREAK'
(void)LABELED_SCOPE_##name; goto name##_end_scope
<scratch space>:232:1: note: expanded from macro 'LABELED_SCOPE_'


Boost list run by bdawes at, gregod at, cpdaniel at, john at