|
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.
>>>
>>>
>>> BOOST_NAMED_BLOCK(L)
>>> {
>>> // ...
>>> }
>>> // [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()
{
BOOST_SCOPE(a2)
{
BOOST_BREAK(a2);
cout << "123\n";
}
BOOST_SCOPE(a1)
{
BOOST_BREAK(a2);
cout << "123\n";
}
return 0;
}
and here are the error for gcc
darwin.compile.c++
../../../bin.v2/libs/thread/test/test_so.test/darwin-4.7.2x/debug/threading-multi/test_so.o
../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
[-fpermissive]
../example/test_so.cpp:22:1: attention : à partir d'ici [-fpermissive]
../example/test_so.cpp:15:1: erreur: skips initialization of const bool
LABELED_SCOPE_a2
and clang
clang-darwin.compile.c++
../../../bin.v2/libs/thread/test/test_so.test/clang-darwin-3.2xl/debug/threading-multi/test_so.o
../example/test_so.cpp:22:7: error: use of undeclared identifier
'LABELED_SCOPE_a2'
BOOST_BREAK(a2);
^
../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_'
LABELED_SCOPE_a2
^
Best,
Vicente
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk