11

The following code:

#include <regex>
using namespace std;

(snippage)

regex_search(s, m, re);

works in Microsoft C++, but GCC 4.4.3 gives the following error message:

/usr/include/c++/4.4/tr1_impl/regex:2255: warning: inline function ‘bool std::regex_search(_Bi_iter, _Bi_iter, std::match_results<_Bi_iter, _Allocator>&, const std::basic_regex<_Ch_type, _Rx_traits>&, std::regex_constants::match_flag_type) [with _Bi_iter = __gnu_cxx::__normal_iterator, std::allocator > >, _Allocator = std::allocator, std::allocator > > > >, _Ch_type = char, _Rx_traits = std::regex_traits]’ used but never defined

Of course it wouldn't surprise me if regex were simply one of the C++0x features still on the to-do list for GCC, but what I'm scratching my head over is, in that case, why does it happily take the include directive, variable declarations etc. and only trip over the function call (which it even seems to understand).

Is there something I'm missing?

rwallace
  • 31,405
  • 40
  • 123
  • 242

2 Answers2

15

The regex library was mostly not implemented in libstdc++ up to branch 4.8.

Versions 4.9 and above do have <regex> implemented though.

Mat
  • 202,337
  • 40
  • 393
  • 406
Michael Burr
  • 333,147
  • 50
  • 533
  • 760
  • Here's a link to the c++0x project that covers all versions of gcc and their support statuses. http://gcc.gnu.org/projects/cxx0x.html – slm Dec 16 '12 at 14:57
  • 5
    [`` is now implemented as of GCC 4.9](http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631#c17) – JohnCand Nov 06 '13 at 03:42
0

For g++, compile with flag "-std=c++0x"

  • 2
    This will only work for versions of gcc that have the feature implemented. For example I was trying to use std::basic_regex but there is no implementation behind this function in gcc 4.4 and 4.5. – slm Dec 16 '12 at 14:55