5

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.

2
  • @llonesmiz see liveworkspace.org/code/3Rdg5D$0 . there is no output . Dec 28, 2012 at 15:48
  • Since then, liveworkspace has update boost to version 1.53, now your code works as expected. I believe the problem was solved in 1.52.
    – user1252091
    Feb 19, 2013 at 16:48

1 Answer 1

2

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. :-(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.