I develop my code in my spare time. Preferably in debug mode. Recently, when I tried to build release version, then I got the error (runtime, output: 1
2
then failure). I located the piece of code (below), which contains the error, and I found, that the error only occurs, when optimization level is -Os, -Ofast, -O2, -O3
but not -O, -O0, -O1, -Og
. In release mode I am constrained in debug abilities. What is the cause of the error? What is the method to find such errors?
#!/usr/bin/env bash -vex WARN="-W -Wall -Wextra" INCLUDE="-isystem /c/libs/boost-trunk" OPT="-O2" g++ -x c++ - -std=gnu++1y $INCLUDE
$WARN $OPT -o a <<__EOF && ./a && echo -e "e[1;32msucceedede[0m" ||
echo -e "e[1;31mfailede[0m"
#include <iterator>
#include <string>
#include <iostream>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/support_multi_pass.hpp>
using namespace boost::spirit;
template< typename Iterator >
struct skipper
: qi::grammar< Iterator >
{
skipper();
private :
typename skipper::base_type::start_type skipper_;
};
template< typename Iterator >
skipper< Iterator >::skipper()
: skipper::base_type(skipper_, "skipper")
{
std::cerr << 1 << std::endl;
auto const ana =
*~qi::char_('*') > +qi::char_('*')
;
std::cerr << 2 << std::endl;
skipper_ =
qi::space
| ("/*" > ana > *(~qi::char_("/*") > ana) > '/')
| ("//" > *(qi::char_ - qi::eol) > (qi::eol | qi::eoi))
; // R"(s+|(/*[^*]**+([^/*][^*]**+)*/)|(//[^
]*))"
std::cerr << 3 << std::endl;
}
using input_type = std::string;
using input_iterator_type = std::istreambuf_iterator< typename input_type::value_type >;
using base_iterator_type = multi_pass< input_iterator_type >;
template struct skipper< base_iterator_type >;
using skipper_type = skipper< base_iterator_type >;
int main()
{
skipper_type const skipper_;
std::cerr << 4 << std::endl;
return EXIT_SUCCESS;
}
__EOF
gcc -v 2>&1 | tail -n1
:
gcc version 4.8.1 (rev5, Built by MinGW-W64 project)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…