简体   繁体   中英

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM