--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAAHOzFBVjGEnMZmz_jPNfJc_yVUGYF1hphM8QaC4r3fJ4ypk1g%40mail.gmail.com.
The compiler cannot automatically mark everything as noexcept for two reasons (although maybe only one is possible inside Chromium):
- if it did so, querying whether a function is noexcept could result in different behavior
- a noexcept function can still call a potentially throwing function (EG call into a static library which does throw)
But that's for "automatically". IIUC, it would be possible for a compiler flag to do this.
I feel strangely like I may have misinterpreted every single sentence below, since it seems as if we're talking past each other. Feel free to clarify if I did.On Tue, Jan 30, 2018 at 10:36 PM, Chris Blume <cbl...@google.com> wrote:The compiler cannot automatically mark everything as noexcept for two reasons (although maybe only one is possible inside Chromium):
- if it did so, querying whether a function is noexcept could result in different behavior
That's the entire reason to do this: so that when queried, all functions will be treated as if they were explicitly marked noexcept.
- a noexcept function can still call a potentially throwing function (EG call into a static library which does throw)
My mental model is that if exceptions are disabled, nothing can throw; if library code throws, it crashes the program. That's why this proposal could even make sense.
But that's for "automatically". IIUC, it would be possible for a compiler flag to do this.By "automatically" I mean "when the toolchain is set to build with exception support disabled" (which is flag-controlled).PK
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAAHOzFAvzHu0diqpP_H3Kkz2OiVBMta-GQo3HcOJsmaOCz5BcQ%40mail.gmail.com.
I feel strangely like I may have misinterpreted every single sentence below, since it seems as if we're talking past each other. Feel free to clarify if I did.On Tue, Jan 30, 2018 at 10:36 PM, Chris Blume <cbl...@google.com> wrote:The compiler cannot automatically mark everything as noexcept for two reasons (although maybe only one is possible inside Chromium):
- if it did so, querying whether a function is noexcept could result in different behavior
That's the entire reason to do this: so that when queried, all functions will be treated as if they were explicitly marked noexcept.
- a noexcept function can still call a potentially throwing function (EG call into a static library which does throw)
My mental model is that if exceptions are disabled, nothing can throw; if library code throws, it crashes the program. That's why this proposal could even make sense.
But that's for "automatically". IIUC, it would be possible for a compiler flag to do this.By "automatically" I mean "when the toolchain is set to build with exception support disabled" (which is flag-controlled).PK
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAAHOzFAvzHu0diqpP_H3Kkz2OiVBMta-GQo3HcOJsmaOCz5BcQ%40mail.gmail.com.
I understand the intent is to enable noexcept by default.
The -fno-exceptions flag doesn't work exactly the way it would be easy to imagine. It doesn't prevent exceptions from existing. It prevents you from throwing. The code still needs to add unwinding semantics and unspecified exception handlers. I was saying a second flag might be needed for what you want.
Additionally, I can't recall if this is part of the standard as of C++11 but in old C++ an exception not in the exception specifier list actually had to be caught. Technically, it wouldn't crash. It would call std::terminate (which called std::abort and effectively crash). So as strange as it seems, adding noexcept to a function likely mimics that behavior -- it likely adds unhandled exception catching.
On Wed, Jan 31, 2018 at 7:28 AM 'Peter Kasting' via cxx <c...@chromium.org> wrote:My mental model is that if exceptions are disabled, nothing can throw; if library code throws, it crashes the program. That's why this proposal could even make sense.
Bunch of things that come to my mind:1) libc++ and libunwind are built with exceptions enabled (I think just because they don't build otherwise). By forcing every function to be noexcept you might break paths libc++ -> code -> libc++.One case I'm thinking about is operator new(std::nothrow), which doesoperator new(size_t size, const std::nothrow_t&) _NOEXCEPT{void* p = 0;try{p = ::operator new(size);}catch (...){}return p;}So if you have a constructor (outside of libc++) that invokes a libc++ function that throws, I *think* that by forcefully making such ctor noexecpt you might change the semantic of new(noexcept).
2) A bunch of tools/test code build with exceptions (angle, gpu's decpp) so we should be careful somehow to not break them
3) It seems that there is one production library that currently builds with exceptions: unrar used by chrome/services/file_util/
If we built all the code with -fno-exceptions and knew that absolutely nowhere used 'throw', there wouldn't be any change in behavior.The compiler typically cannot know the other TUs were compiled with -fno-excpetions but I could imagine a flag to indicate "I promise no other TUs throw" or some metadata passed to the linker to let the linker know it can remove the exception handlers.
If a function in TU 1 is noexcept and -fno-exceptions, it has an unhandled exception handler.
This is because the standard forced it to, with the std::terminate call (note 5).
The only way this function in TU 1 can remove the unhandled exception handler is if it either 1.) isn't marked noexcept, 2.) knows it doesn't call out to any other TU's code, or 3.) knows all the TUs it calls into are also either noexcept or -fno-exceptions and recurse down (the TUs those call into don't either).
The point of this is you can specify your own function to get called instead when std::terminate is called.
I do like the idea of your reworded proposal. It would probably need to go deeper than just the given TU though.
TU1 -fno-exceptions has a function which calls into TU2 which enabled exceptions.
Even though TU1 itself cannot throw, an exception could still come from TU2.
If we forced an optimal code path (say vector's resizing) which assumed exceptions aren't thrown and then an exception is thrown, we defeat the whole purpose of having the optimized path. We assumed the strong exception guarantee and didn't get it.