Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
muellerj2 opened this issue Jan 12, 2025 · 0 comments
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. test-suite

Comments

@muellerj2
Copy link

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.)

@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jan 12, 2025
@muellerj2 muellerj2 changed the title [libc++][test] re.regex.construct/bad_backref.cpp assumes non-standard extension to extended regular expressions [libc++][test] re.regex.construct/bad_backref.pass.cpp assumes non-standard extension to extended regular expressions Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. test-suite
Projects
None yet
Development

No branches or pull requests

3 participants