http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58395

            Bug ID: 58395
           Summary: Undefined behavior vs. exception
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: frankhb1989 at gmail dot com

Several operations are undefined because they failed to meet required
behavior(ISO C++11 [defns.required.behavior]) at runtime. Currently libstdc++
throw exceptions for them. For example, when object of type std::string being
initialized using a null pointer value, an exception of type std::logic_error
is thrown by basic_string<char>::_S_construct. That's nothing wrong for
libstdc++ on conformance, because an implementation is free to do anything when
the behavior is undefined. However, this behavior is somewhat confusing for
users not so familiar with the standard. I suggest 2 options for future
releases of libstdc++:
1. Make the type of exceptions specific(i.e. as a documented feature),
distinguishable with other exceptions required to be thrown by the standard. It
can be a type derived from std::logic_error, as an extension.
2. Make the implementation-defined result of what() specific and
distinguishable, e.g. some prefix to indicate the exception is not mandated.
This is not only good for manually distinguishing UB, but also beneficial for
tests on conformance/portability of user programs.

Reply via email to