Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this proto/phoenix toy example crash?

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.

like image 653
Johannes Schaub - litb Avatar asked Nov 03 '22 07:11

Johannes Schaub - litb


1 Answers

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

like image 98
Eric Niebler Avatar answered Nov 15 '22 04:11

Eric Niebler