https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102447
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Actually, this might not be a bug.
We have this comment in regex_compiler.tcc
// POSIX doesn't allow '-' as a start-range char (say [a-z--0]),
// except when the '-' is the first or last character in the bracket
// expression ([--0]). ECMAScript treats all '-' after a range as a
// normal character. Also see above, where _M_expression_term gets
called.
//
// As a result, POSIX rejects [-----], but ECMAScript doesn't.
// Boost (1.57.0) always uses POSIX style even in its ECMAScript syntax.
// Clang (3.5) always uses ECMAScript style even in its POSIX syntax.
//
// It turns out that no one reads BNFs ;)
So [\w-a] is valid for the ECMAScript syntax and is equivalent to POSIX
[-_[:alnum:]].
You can confirm this using your browser's javascript console, where this will
print true:
RegExp('[\\w-a]').test('-')