Bug 17157 – ctRegex.matchAll doesn't set last item in Captures
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-02-08T09:41:45Z
Last change time
2018-01-05T13:27:41Z
Keywords
pull
Assigned to
No Owner
Creator
Alexey Kulentsov
Comments
Comment #0 by crimaniak — 2017-02-08T09:41:45Z
Reproduce code:
int main()
{
import std.stdio;
import std.regex;
// auto r = ctRegex!"(a)|(b)|(c)|(d)"; /* // <- uncomment to switch to ctRegex
auto r = regex("(a)|(b)|(c)|(d)"); //*/
auto s = "--a--b--c--d--";
foreach(match; s.matchAll(r))
{
foreach(i; 0..match.length)
write(i,":",match[i]," ");
writeln();
}
return 0;
}
if line 6 commented and regex() is used then output is correct:
0:a 1:a 2: 3: 4:
0:b 1: 2:b 3: 4:
0:c 1: 2: 3:c 4:
0:d 1: 2: 3: 4:d
if comment at line 6 beginning is removed and ctRegex is used then we have exception:
core.exception.AssertError@/usr/include/dmd/phobos/std/regex/package.d(565): wrong match: 1..0
----------------
??:? _d_assert_msg [0x4edba6]
??:? std.regex.Captures!(immutable(char)[], ulong).Captures.opIndex!().opIndexinout(pure nothrow @trusted inout(immutable(char)[]) function(ulong)) [0x4e4f01]
??:? _Dmain [0x4bb73e]
??:? _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv [0x4ef333]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x4ef25b]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() [0x4ef2d8]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x4ef25b]
??:? _d_run_main [0x4ef1c7]
??:? main [0x4eae0f]
??:? __libc_start_main [0xc012282f]
More experiments have shown: last element of match is not set and attempt to access it leads to exception.
Compiler: DMD64 D Compiler v2.073.0
OS: Ubuntu 16.04 LTS
Comment #1 by dmitry.olsh — 2017-03-08T13:48:03Z
(In reply to Alexey Kulentsov from comment #0)
> if comment at line 6 beginning is removed and ctRegex is used then we have
> exception:
>
> core.exception.AssertError@/usr/include/dmd/phobos/std/regex/package.d(565):
> wrong match: 1..0
> ----------------
> ??:? _d_assert_msg [0x4edba6]
> ??:? std.regex.Captures!(immutable(char)[],
> ulong).Captures.opIndex!().opIndexinout(pure nothrow @trusted
> inout(immutable(char)[]) function(ulong)) [0x4e4f01]
> ??:? _Dmain [0x4bb73e]
> ??:? _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv
> [0x4ef333]
> ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int
> function(char[][])*).tryExec(scope void delegate()) [0x4ef25b]
> ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int
> function(char[][])*).runAll() [0x4ef2d8]
> ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int
> function(char[][])*).tryExec(scope void delegate()) [0x4ef25b]
> ??:? _d_run_main [0x4ef1c7]
> ??:? main [0x4eae0f]
> ??:? __libc_start_main [0xc012282f]
>
> More experiments have shown: last element of match is not set and attempt to
> access it leads to exception.
>
> Compiler: DMD64 D Compiler v2.073.0
> OS: Ubuntu 16.04 LTS
Trying to reproduce with latest master (2.074~alpha) I see no exception but the output of 2 runs differs.
With regex correctly:
0:a 1:a 2: 3: 4:
0:b 1: 2:b 3: 4:
0:c 1: 2: 3:c 4:
0:d 1: 2: 3: 4:d
With ctRegex:
0:a 1:a 2: 3: 4:
0:b 1:a 2:b 3: 4:
0:c 1:a 2: 3:c 4:
0:d 1:a 2: 3: 4:d
Investigating...