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.)
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.cpptest assumes this non-standard extension as well: It expects in various places that theerror_backreferror code is thrown on illegal backreferences for extended and egrep regular expressions. Example:llvm-project/libcxx/test/std/re/re.regex/re.regex.construct/bad_backref.pass.cpp
Line 37 in 7532958
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_escapeinstead oferror_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:
llvm-project/libcxx/test/std/re/re.regex/re.regex.construct/bad_backref.pass.cpp
Line 38 in 7532958
But what is actually checked here is that no
regex_errorwith codeerror_backrefis 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:llvm-project/libcxx/test/std/re/re.regex/re.regex.construct/bad_backref.pass.cpp
Line 73 in 7532958
llvm-project/libcxx/test/std/re/re.regex/re.regex.construct/bad_backref.pass.cpp
Line 77 in 7532958
llvm-project/libcxx/test/std/re/re.regex/re.regex.construct/bad_backref.pass.cpp
Line 82 in 7532958
llvm-project/libcxx/test/std/re/re.regex/re.regex.construct/bad_backref.pass.cpp
Line 88 in 7532958
(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.)