Skip to content

[libc++][test] re.regex.construct/bad_backref.pass.cpp assumes non-standard extension to extended regular expressions #122638

Open
@muellerj2

Description

@muellerj2

libc++ supports backreferences as a non-standard extension to POSIX extended regular expressions (see Section 9.5.1 of the POSIX standard, which specifies that the token "BACKREF" is applicable to basic regular expressions only).

The bad_backref.cpp test assumes this non-standard extension as well: It expects in various places that the error_backref error code is thrown on illegal backreferences for extended and egrep regular expressions. Example:

assert(error_badbackref_thrown("\\1abd", std::regex::extended));

These extended and egrep mode tests fail for MSVC STL, because it does not support backreferences in extended regular expressions in accordance with the POSIX standard. Consequently, it produces the error code error_escape instead of error_backref, because there is no concept of backreferences in extended regular expressions from MSVC STL's point of view.

Side note: The test also tries to check in various places that some regular expressions with backreferences are parsed successfully:

assert(error_badbackref_thrown("\\1abd", std::regex::awk) == false);

But what is actually checked here is that no regex_error with code error_backref is thrown. Because of this, MSVC STL actually passes a few lines that try to check that backreferences are parsed successfully in extended and egrep mode even though it doesn't support backreferences in these modes at all:

assert(error_badbackref_thrown("(cat)\\10", std::regex::extended) == false);

assert(error_badbackref_thrown("(cat)\\10", std::regex::egrep) == false);

assert(error_badbackref_thrown("(cat)\\1", std::regex::extended) == false);

assert(error_badbackref_thrown("(cat)\\1", std::regex::egrep) == false);

(If these four lines are changed to actually test a successful parse, they should be moved to a libc++-specific test file since they test a non-standard extension.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.regexIssues related to regextest-suite

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions