Bug 39145 - g++ -O3 -std=c++0x causes compile error in boost regex
Summary: g++ -O3 -std=c++0x causes compile error in boost regex
Status: RESOLVED WORKSFORME
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-10 04:45 UTC by John Yau
Modified: 2009-10-18 07:01 UTC (History)
3 users (show)

See Also:
Host: x86_64-linux-gnu
Target: x86_64-linux-gnu
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 John Yau 2009-02-10 04:45:00 UTC
Compiling the snippet below using

g++ -O3 -std=c++0x foo.cpp -lboost_regex

fails.

However, the compile succeeds with:

g++ -O2 -std=c++0x foo.cpp -lboost_regex
g++ -O2 -std=c++0x foo.cpp -funswitch-loops -fpredictive-commoning -fgcse-after-reload -ftree-vectorize foo.cpp -lboost_regex (i.e. -O3 without -finline-functions)
g++ -O3 foo.cpp -lboost_regex

foo.cpp is below:

#include <iostream>
#include <stdint.h>
#include <boost/regex.hpp>
#include <cstdio>
#include <cstring>

int main(int argc, char**argv) {
  const char *first = "abcd"; 
  const char *last = first + strlen(first); 
  boost::cmatch mr; 
  boost::regex rx("abc"); 
  boost::regex_constants::match_flag_type fl = 
        boost::regex_constants::match_default; 
  
  std::cout << "search(f, f+1, \"abc\") == " << std::boolalpha 
	    << regex_search(first, first + 1, rx, fl) << std::endl; 
  
  std::cout << "search(f, l, \"abc\") == " << std::boolalpha 
	    << regex_search(first, last, mr, rx) << std::endl; 
  std::cout << "  matched: \"" << mr.str() << "\"" << std::endl; 
  
  std::cout << "search(\"a\", \"abc\") == " << std::boolalpha 
	    << regex_search("a", rx) << std::endl; 
  
  std::cout << "search(\"xabcd\", \"abc\") == " << std::boolalpha 
	    << regex_search("xabcd", mr, rx) << std::endl; 
  std::cout << "  matched: \"" << mr.str() << "\"" << std::endl; 
  
  std::cout << "search(string, \"abc\") == " << std::boolalpha 
	    << regex_search(std::string("a"), rx) << std::endl; 
  
  std::string str("abcabc"); 
  boost::match_results<std::string::const_iterator> mr2; 
  std::cout << "search(string, \"abc\") == " << std::boolalpha 
	    << boost::regex_search(str, mr2, rx) << std::endl; 
  std::cout << "  matched: \"" << mr2.str() << "\"" << std::endl; 
  
  return 0;
}


The compile error generated is:

/usr/include/c++/4.3/bits/stl_pair.h: In constructor ‘std::pair<_T1, _T2>::pair(_U1&&, _U2&&) [with _U1 = boost::shared_ptr<const boost::re_detail::cpp_regex_traits_implementation<char> >&, _U2 = int, _T1 = boost::shared_ptr<const boost::re_detail::cpp_regex_traits_implementation<char> >, _T2 = const boost::re_detail::cpp_regex_traits_base<char>*]’:
/usr/include/boost/regex/pending/object_cache.hpp:122:   instantiated from ‘static boost::shared_ptr<const Object> boost::object_cache<Key, Object>::do_get(const Key&, typename std::list<std::pair<boost::shared_ptr<const Object>, const Key*>, std::allocator<std::pair<boost::shared_ptr<const Object>, const Key*> > >::size_type) [with Key = boost::re_detail::cpp_regex_traits_base<char>, Object = boost::re_detail::cpp_regex_traits_implementation<char>]’
/usr/include/boost/regex/pending/object_cache.hpp:69:   instantiated from ‘static boost::shared_ptr<const Object> boost::object_cache<Key, Object>::get(const Key&, typename std::list<std::pair<boost::shared_ptr<const Object>, const Key*>, std::allocator<std::pair<boost::shared_ptr<const Object>, const Key*> > >::size_type) [with Key = boost::re_detail::cpp_regex_traits_base<char>, Object = boost::re_detail::cpp_regex_traits_implementation<char>]’
/usr/include/boost/regex/v4/cpp_regex_traits.hpp:828:   instantiated from ‘boost::shared_ptr<const boost::re_detail::cpp_regex_traits_implementation<charT> > boost::re_detail::create_cpp_regex_traits(const std::locale&) [with charT = char]’
/usr/include/boost/regex/v4/cpp_regex_traits.hpp:848:   instantiated from ‘boost::cpp_regex_traits<charT>::cpp_regex_traits() [with charT = char]’
/usr/include/boost/regex/v4/regex_traits.hpp:75:   instantiated from ‘boost::regex_traits<charT, implementationT>::regex_traits() [with charT = char, implementationT = boost::cpp_regex_traits<char>]’
/usr/include/boost/regex/v4/regex_traits.hpp:169:   instantiated from ‘boost::regex_traits_wrapper<BaseT>::regex_traits_wrapper() [with BaseT = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/include/boost/regex/v4/basic_regex.hpp:61:   instantiated from ‘boost::re_detail::regex_data<charT, traits>::regex_data() [with charT = char, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/include/boost/regex/v4/basic_regex.hpp:93:   instantiated from ‘boost::re_detail::basic_regex_implementation<charT, traits>::basic_regex_implementation() [with charT = char, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/include/boost/regex/v4/basic_regex.hpp:525:   instantiated from ‘boost::basic_regex<charT, traits>& boost::basic_regex<charT, traits>::do_assign(const charT*, const charT*, boost::regex_constants::syntax_option_type) [with charT = char, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/include/boost/regex/v4/basic_regex.hpp:262:   instantiated from ‘boost::basic_regex<charT, traits>& boost::basic_regex<charT, traits>::assign(const charT*, const charT*, boost::regex_constants::syntax_option_type) [with charT = char, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/include/boost/regex/v4/basic_regex.hpp:247:   instantiated from ‘boost::basic_regex<charT, traits>& boost::basic_regex<charT, traits>::assign(const charT*, boost::regex_constants::syntax_option_type) [with charT = char, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/include/boost/regex/v4/basic_regex.hpp:216:   instantiated from ‘boost::basic_regex<charT, traits>::basic_regex(const charT*, boost::regex_constants::syntax_option_type) [with charT = char, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
foo.cpp:11:   instantiated from here
/usr/include/c++/4.3/bits/stl_pair.h:95: error: invalid conversion from ‘int’ to ‘const boost::re_detail::cpp_regex_traits_base<char>*’


gcc -v is:
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.2-1ubuntu12' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu12)
Comment 1 Karl Miller 2009-02-27 00:25:43 UTC
The same code and cmd line arguments compile without problems for me.

$ gcc -v
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.3 --enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --program-suffix=-4.3 --enable-linux-futex --without-system-libunwind --with-cpu=generic --build=x86_64-suse-linux
Thread model: posix
gcc version 4.3.2 [gcc-4_3-branch revision 141291] (SUSE Linux) 
Comment 2 Jason Merrill 2009-10-18 07:01:19 UTC
I can't reproduce this with 4.4 or 4.5, either.