The following code in VS2015 displays x , but for some reason the result in ideone is x1 . Why??

http://ideone.com/K5ZKxR

 #include <iostream> #include <string> #include <regex> using namespace std; int main() { string s = "x"; s = regex_replace(s + "0123456789", regex("(\\b(?=9.*(1))|0(?=.*(1))|1(?=.*(2))|2(?=.*(3))|3(?=.*(4))|4(?=.*(5))|5(?=.*(6))|6(?=.*(7))|7(?=.*(8))|8(?=.*(9))|9(?=.*(0)))(?=9*-)|\\d{10}$"), "$2$3$4$5$6$7$8$9$10$11$12"); cout << s << '\n'; return 0; } 

In the given example, the coincidence should go only along the last branch of |\\d{10}$ , i.e. all groups should be empty. T. o. The added tail of 10 digits should be removed. But from somewhere the number 1 is taken. Why is this happening? And how to fix it?


Reduced the example
http://ideone.com/THHiay

 #include <iostream> #include <string> #include <regex> using namespace std; int main() { string s = "x"; s = regex_replace(s + "0123456789", regex("0(?=.*(1))(?=9*-)|\\d{10}$"), "<$1>"); cout << s << '\n'; return 0; } 
 x<1> 

However, other zeros in the string do not deteriorate (they change only before the nines and the hyphen)
http://ideone.com/XcFF6M

 #include <iostream> #include <string> #include <regex> using namespace std; int main() { string s = "100#100-100,101#101-101,109#109-109"; s = regex_replace(s + "0123456789", regex("0(?=.*(1))(?=9*-)|\\d{10}$"), "<$1>"); cout << s << '\n'; return 0; } 
 100#10<1>-100,101#101-101,109#1<1>9-109<1> 

Meanwhile, VS for the last example gives

 100#10<1>-100,101#101-101,109#1<1>9-109<> 

Which is logical - there is no group, but there is a replacement with erasing the tail.

  • it is logical that the failed search branches do not save groups (replacing ?= with ?: we get the expected result), so we can assume that this is a compiler bug - BOPOH
  • @BOPOH, are there any ideone counterparts that support the 11th or 14th standard of benefits? - Qwertiy
  • four
    This is a bug; non-triggered alternatives should not be captured in groups. Specifically, this regular expression can be cured like this: ideone.com/B9n6fo - ReinRaus
  • @ReinRaus What, report a bug on GCC (or whatever)? :) - Athari
  • 2
    Then write the answer, somebody. - VladD

2 answers 2

Apparently this is not an ideone bug, but a gcc bug that appeared somewhere around version 5.

4.9.3 gives:

x <>

5.1.0 gives:

x <1>

    As @ReinRaus rightly pointed out, this is really an Ideone bug.

    I wrote to their support team about this.