Bug 59709 - break program behavior with optimization
Summary: break program behavior with optimization
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-07 07:01 UTC by Akira Takahashi
Modified: 2014-01-08 04:47 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.