Bug 59709

Summary: break program behavior with optimization
Product: gcc Reporter: Akira Takahashi <faithandbrave>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED INVALID    
Severity: normal    
Priority: P3    
Version: 4.8.2   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Akira Takahashi 2014-01-07 07:01:20 UTC
Hi, I encountered difficult problem. If I use -O2 option, follow code behavior be break. (in GCC 4.8.2)

#include <iostream>
#include <string>
#include <boost/spirit/include/qi.hpp>

namespace qi = boost::spirit::qi;

int main()
{
    const std::string input = "hello:";

    auto rule = *(qi::char_ - ':') >> ':';

    std::string::const_iterator it = input.begin();
    std::string result;
    if (qi::parse(it, input.end(), rule, result)) {
        std::cout << "parse successful" << std::endl;
    }
    else {
        std::cout << "parse failed" << std::endl;
    }
}

If I don't use optimization, the problem result is "parse successful". But if I use optimization, the problem result is output "parse failed" or output nothing.

If I don't use `auto` and I write type, the problem result is "parse successful" correctly :

#include <iostream>
#include <string>
#include <boost/spirit/include/qi.hpp>

namespace qi = boost::spirit::qi;

int main()
{
    const std::string input = "hello:";

    qi::rule<std::string::const_iterator, std::string()> rule = *(qi::char_ - ':') >> ':';

    std::string::const_iterator it = input.begin();
    std::string result;
    if (qi::parse(it, input.end(), rule, result)) {
        std::cout << "parse successful" << std::endl;
    }
    else {
        std::cout << "parse failed" << std::endl;
    }
}

I couldn't write minimal code without Boost.Spirit. Sorry.
Comment 1 Akira Takahashi 2014-01-07 07:03:25 UTC
Boost version is 1.55.0.
Comment 2 Akira Takahashi 2014-01-08 04:47:21 UTC
http://stackoverflow.com/questions/20763665/boost-spirit-v2-qi-bug-associated-with-optimization-level

Sorry, this is Boost.Spirit's issue. not optimization issue.