c++ - Is gcc 4.8 or earlier buggy about regular expressions? -


i trying use std::regex in c++11 piece of code, appears support bit buggy. example:

#include <regex> #include <iostream>  int main (int argc, const char * argv[]) {     std::regex r("st|mt|tr");     std::cerr << "st|mt|tr" << " matches st? " << std::regex_match("st", r) << std::endl;     std::cerr << "st|mt|tr" << " matches mt? " << std::regex_match("mt", r) << std::endl;     std::cerr << "st|mt|tr" << " matches tr? " << std::regex_match("tr", r) << std::endl; } 

outputs:

st|mt|tr matches st? 1 st|mt|tr matches mt? 1 st|mt|tr matches tr? 0 

when compiled gcc (macports gcc47 4.7.1_2) 4.7.1, either

g++ *.cc -o test -std=c++11 g++ *.cc -o test -std=c++0x 

or

g++ *.cc -o test -std=gnu++0x 

besides, regex works if have 2 alternative patterns, e.g. st|mt, looks last 1 not matched reasons. code works apple llvm compiler.

any ideas how solve issue?

update 1 possible solution use groups implement multiple alternatives, e.g. (st|mt)|tr.

<regex> implemented , released in gcc 4.9.0.

in (older) version of gcc, not implemented.

that prototype <regex> code added when of gcc's c++0x support highly experimental, tracking c++0x drafts , being made available people experiment with. allowed people find problems , give feedback standard committee before standard finalised. @ time lots of people grateful have had access bleeding edge features long before c++11 finished , before many other compilers provided any support, , feedback helped improve c++11. thingtm.

the <regex> code never in useful state, added work-in-progress many other bits of code @ time. checked in , made available others collaborate on if wanted to, intention finished eventually.

that's how open source works: release early, release often -- unfortunately in case of <regex> got part right , not part have finished implementation.

most parts of library more complete , implemented, <regex> hadn't been, stayed in same unfinished state since added.

seriously though, though shipping implementation of regex_search "return false" idea?

it wasn't such bad idea few years ago, when c++0x still work in progress , shipped lots of partial implementations. no-one thought remain unusable long so, hindsight, maybe should have been disabled , required macro or built-time option enable it. ship sailed long ago. there exported symbols libstdc++.so library depend on regex code, removing (in, say, gcc 4.8) not have been trivial.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -