[cfe-dev] [libc++] expected behavior for ECMAScript regex starting with '?'

Trevor Smigiel tsmigiel at yahoo.com
Tue Jul 21 21:54:49 PDT 2015


Hi,

When specifying an ECMAScript regex that starts with '?', like the test
case below,  I was expecting it to throw an error.  If I use the
resulting regex to match a string, it returns a match of length 0 at the
first position.

Looking at the regex grammar from the spec for ECMAScript, section
15.10, it seems a '?' should not be allowed as the first character, but
I did not read more than the grammar.
http://wayback.archive.org/web/20111103184035/http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262%20edition%205.1,%20June%202011.pdf

What is the expected behavior?

Thanks,
Trevor

// this test case is a modified version of the test from
https://llvm.org/bugs/show_bug.cgi?id=16023
#include <regex>
#include <cassert>

int main()
    // Failure: No exception thrown for invalid escape char in this
    case.
    try {
        std::regex escape("?a");
        assert(false);
    } catch (std::regex_error &ex) {
        assert(ex.code() == std::regex_constants::error_escape);
    }   
}   



More information about the cfe-dev mailing list