[llvm-bugs] [Bug 34297] New: regex constructor does not throw an exception for invalid backreferences in basic/grep patterns

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Aug 23 00:12:24 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=34297

            Bug ID: 34297
           Summary: regex constructor does not throw an exception for
                    invalid backreferences in basic/grep patterns
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: arthur.j.odwyer at gmail.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

#include <regex>
#include <stdio.h>

int main() {
    std::regex rx("(cat)\\1", std::regex::basic);
    puts("Constructed without throwing: oops!");
    try {
        std::regex_match("(cat)", rx);
    } catch (std::exception& e) {
        puts("regex_match threw instead: oops!");
        puts(e.what());
    }
}

The output is:

Constructed without throwing: oops!
regex_match threw instead: oops!
The expression contained an invalid back reference.

I claim that the constructor should detect and throw on this pattern, rather
than throwing at match time. The same issue happens with the "std::regex::grep"
dialect, too.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170823/c2aef78d/attachment-0001.html>


More information about the llvm-bugs mailing list