https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89927

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2019-04-02
     Ever confirmed|0                           |1
           Severity|normal                      |enhancement

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Right, the program is using std::regex incorrectly, and has undefined
behaviour.

Compiling with -D_GLIBCXX_ASSERTIONS will cause the program to abort at
runtime:

/home/jwakely/gcc/8/include/c++/8.3.1/bits/regex_scanner.tcc:189: void
std::__detail::_Scanner<_CharT>::_M_scan_normal() [with _CharT = char]:
Assertion 'false' failed.
Aborted (core dumped)

It would be good if that assertion was more explanatory, or at least had a
comment saying it will only be reached when given bad input. I'm confirming
this bug as a reminder to improve that some time.


Adding this constructor to basic_regex turns the example into a compile-time
error:

      template<size_t _Num>
        basic_regex(const value_type*, const value_type(&)[_Num],
                    flag_type = ECMAScript) = delete;

I don't think that's a good idea though, as it would also cause us to reject
some valid (albeit useless) code like:

  const char s[] = ".*";
  std::regex r(s, s);

Reply via email to