I am experimenting with proto and phoenix and what is one of my first toy examples crash and I have no idea where I should be looking at. Since someone on the #boost IRC channel told me to ensure that the phoenix expression tree is first deep copied (so that there are no dangling references left when x
has been constructed), I wrapped the expression by boost::proto::deep_copy
. However that didn't quite work. It still crashes when compiled with the -O2
flag, and works fine when omitting it.
#include <boost/phoenix/phoenix.hpp>
#include <boost/proto/deep_copy.hpp>
#include <iostream>
namespace bpr = boost::proto;
int main(int argc, char **argv) {
using namespace boost::phoenix;
using namespace placeholders;
auto x = bpr::deep_copy(
switch_(arg1)[
case_<1>(std::cout << val("hello")),
case_<2>(std::cout << val("bye")),
default_(std::cout << val("default"))
]);
x(1);
x(2);
}
I expect this to output hellobye
.
Looks like this is a known bug in Phoenix. I would avoid using phoenix::switch_
until this is sorted. Unfortunately, the maintainer of Phoenix seems to be busy with other things these days. :-(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With