Skip to content

<regex>: regex_match() throws regex_error(error_stack) when a repeated pattern contains a lookahead assertion #5792

@muellerj2

Description

@muellerj2

Describe the bug

Since MSVC Build Tools 14.50, a lookahead assertion inside a repeated pattern results in a regex_error(error_stack).

Test case

#include <iostream>
#include <regex>
#include <string>

using namespace std;

int main() {
    try {
        regex re("(?:(?=ab))*");
        (void) regex_match("xyz", re);
        cout << "no exception\n";
    } catch (const regex_error& ex) {
        cout << "regex_error with code " << ex.code() << "\n";
    }

    return 0;
}

This prints "regex_error with code 12".

Expected behavior

Should print "no exception".

STL version

MSVC Build Tools 18.50 up to current head.

Additional context

I introduced this bug in #5456. But I expect that its practical impact is very limited: It is very difficult to reason about a repeated pattern that contains a lookahead assertion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!regexmeow is a substring of homeowner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions