[Issue 17157] New: ctRegex.matchAll doesn't set last item in Captures

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Feb 8 01:41:45 PST 2017


https://issues.dlang.org/show_bug.cgi?id=17157

          Issue ID: 17157
           Summary: ctRegex.matchAll doesn't set last item in Captures
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: crimaniak at gmail.com

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

--


More information about the Digitalmars-d-bugs mailing list