Namespaces
Variants
Views
Actions

Talk:cpp/language/noexcept spec

From cppreference.com

Example doesn't explain much 1. int()==0 thus noexcept(int())=>noexcept(false) 2. main() will crash regardless as there is an unhandled exception.

int() appears inside the noexcept operator (not the noexcept specifier) which evaluates to true for the expression int(). You're correct that an unhandled exception will escape from main, but I'm not sure why that's a problem for this example. Feel free to add or propose an explanation that you think would work better. :) --Nate 14:37, 22 February 2013 (PST)

If you enable "<gadget-StandardRevisions>" on Gadgets tab of your Preferences, and then select "C++20" on this (noexcept) page, then third construct (throw()) is not hidden. Although its description is hidden. I'm not sure how to fix this. I looked at how it works on "std::copy" page: Template:dcl is used there but here Template:sdsc is used. Seems that sdsc should be enhanced in the same way as dcl. -- Valiko (talk) 22:53, 29 December 2019 (PST)

I do not understand the example with inheritance. As I understand it, the functions in D should be declared with e.g. override in order to be virtual. As written, D simply declares new non-virtual functions. Is that wrong? Pkl (talk) 03:02, 19 August 2021 (PDT)

It's actually not possible to declare a non-virtual function with the same name as a virtual function from a base class, override has no effect on whether a function is virtual or not, it just does a sanity check for you that there is indeed a virtual function in a base class to override. --Ybab321 (talk) 04:20, 19 August 2021 (PDT)

Shouldn't it be "3) Same as noexcept(false)" instead of "3) Same as noexcept(true)" the note to throw() ? --vettovaglie (talk) 12:59, 1 June 2022 (UTC)

no; noexcept(false) means "throws exceptions". noexcept(true), noexcept, and throw() all mean "does not throw exceptions" --Cubbi (talk) 06:28, 1 June 2022 (PDT)

In the Deprecates section it is written noexcept will not call std::unexpected and may or may not unwind the stack in the examples it is written that throws always lead to std::terminate call. Who is right? 185.220.101.34 01:13, 16 June 2022 (PDT)

Both are correct. std::unexcepted is not called, the stack may or may not unwind, and std::terminate is called --Ybab321 (talk) 04:13, 16 June 2022 (PDT)
Would be great to add a note in Deprecates section that std::terminate is called anyway to avoid a confusion that nothing is called and the condition is just a no-op. 185.247.226.37 05:51, 16 June 2022 (PDT)
Sounds good --Ybab321 (talk) 06:59, 16 June 2022 (PDT)