<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/122638>122638</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc++][test] `re.regex.construct/bad_backref.cpp` assumes non-standard extension to extended regular expressions
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
muellerj2
</td>
</tr>
</table>
<pre>
libc++ supports backreferences as a non-standard extension to POSIX extended regular expressions (see [Section 9.5.1 of the POSIX standard](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_05_01), 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:
https://github.com/llvm/llvm-project/blob/753295835544f16b4e180576aa020680231c4318/libcxx/test/std/re/re.regex/re.regex.construct/bad_backref.pass.cpp#L37
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:
https://github.com/llvm/llvm-project/blob/753295835544f16b4e180576aa020680231c4318/libcxx/test/std/re/re.regex/re.regex.construct/bad_backref.pass.cpp#L38
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:
https://github.com/llvm/llvm-project/blob/753295835544f16b4e180576aa020680231c4318/libcxx/test/std/re/re.regex/re.regex.construct/bad_backref.pass.cpp#L73
https://github.com/llvm/llvm-project/blob/753295835544f16b4e180576aa020680231c4318/libcxx/test/std/re/re.regex/re.regex.construct/bad_backref.pass.cpp#L77
https://github.com/llvm/llvm-project/blob/753295835544f16b4e180576aa020680231c4318/libcxx/test/std/re/re.regex/re.regex.construct/bad_backref.pass.cpp#L82
https://github.com/llvm/llvm-project/blob/753295835544f16b4e180576aa020680231c4318/libcxx/test/std/re/re.regex/re.regex.construct/bad_backref.pass.cpp#L88
(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.)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUVs2O2zYQfhr6MoggUZYlHXxY78ZA0BQtukHQ24KiRhITmlQ51Np--4K0vHYWzrY57sU2aHF-vp_RCCLVG8Q1KzaseFiIyQ_WrXcTao3uG180tj2utWok4xvGN0DTOFrnCRohvzvs0KGRSCAIBBhrPpAXphWuBTx4NKSsAW_hzz8eP_19OmqxBYf9pIUDPIwOKTxEwHhFiMCKzSNKH-7VSZFkYDvwA84RztFZ8cB4NXg_EsvvGN8yvh2nhhI7oumdncbEup7xrTVaGQx_Mb6tV3VdZ3VZ14xvG0HYYhfOv2ZPchBjWieD32nGcy_6p7R-SounNGO8Zvwe9oOSA9CIUnUKCfwgfCzM2-9ogHG-ubv_7a-PW8Y5KAIxjlpJ0ejwBDSClLzZtjX6yHidsPSOpXdfBgS2ShvRPs0AJ3Ic2SoFj-RBEE27mFzRz9AWBHvUmuV38MmHVCg9gTLwLJyyE8GohbxugK1SdM66c8aQLR6AtC2GXvzg7N6ANaC0xl7o1-x31l3IFaYF7B2Ot_pN4ONB7EaNgbbY8o8k9soPU5NIu2N8q_Xz-evD6Ow3lD4Qp23D-LYscl4XVV4Uy2WXrZolZlValCshUp6uqpTnmVzmWRUCqEYeDoxvA4iMb8m3jG8dxo_EYY-Hq5-JtIa8m07JrpgYBVGkg-ef8_KFMMJbve8CdiEfQSeUjhD9_vj1Hh6_fA56alCKiRCUh9ZiYNOfzfUaXWXedo4yIKS0rhVGIuyVH244JoF7awj_mdD4oLj7kHl0tp1OYsBrzl8kgSTFiEERypBH0QY73hDMdUd-QBdlYyxIayS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