What is noexcept useful for?

The primary use of noexcept is for generic algorithms, e.g., when resizing a std::vector<T>: for an efficient algorithm moving elements it is necessary to know ahead of time that none of the moves will throw. If moving elements might throw, elements need to be copied instead. Using the noexcept(expr) operator the library implementation can determine … Read more

Why is std::unique_ptr::reset() always noexcept?

The requirements of the call to the function object Deleter are specific on this as listed in the requirements of the std::unique_ptr<T>::reset() member. From [unique.ptr.single.modifiers]/3, circa N4660 §23.11.1.2.5/3; unique_ptr modifiers void reset(pointer p = pointer()) noexcept; Requires: The expression get_deleter()(get()) shall be well formed, shall have well-defined behavior, and shall not throw exceptions. In general … Read more

Noexcept and copy, move constructors

This is a multi-faceted question, so bear with me while I go through the various aspects. The standard library expects all user types to always give the basic exception guarantee. This guarantee says that when an exception is thrown, the involved objects are still in a valid, if unknown, state, that no resources are leaked, … Read more

C++ ISO noexcept of noexcept

Having the noexcept(x) specifier in a function declaration means that the function is non-throwing if and only if x evaluates to true. noexcept(y) can also be used as an operator, evaluating to true if y is a non-throwing expression, and to false if y can potentially throw. Combined, this means void foo() noexcept(noexcept(y)); means: foo … Read more

std::function with noexcept in C++17

std::function‘s definition hasn’t changed in the current working draft: template<class T> class function; // not defined template<class R, class… ArgTypes> class function<R(ArgTypes…)> { /* … */ }; Since void() noexcept doesn’t match the partial specialization, std::function<void() noexcept> is an incomplete type. Both Clang and GCC trunk diagnose this accordingly.

Handling gcc’s noexcept-type warning

There’s several things you can do about the warning message. Disable it with -Wno-noexcept-type. In many projects the warning message is unhelpful because there’s no chance the resulting object will be linked with an another object that expects it to use GCC’s C++17 name mangling. If you’re not compiling with different -std= settings and you’re … Read more

Does adding `noexcept(false)` benefit the code in any way?

Having no exception-specifier and explicitly stating noexcept(false) are equivalent, see §15.4/12: A function with no exception-specification or with an exception-specification of the form noexcept(constant-expression) where the constant-expression yields false allows all exceptions. So the compiler should not distinguish between them when considering exceptions. More importantly, there’s no need for you to be tacking on noexcept(false) … Read more

Is there an automatic noexcept specifier?

Currently there is none. There is, however, a proposal on that topic, which proposes noexcept(auto) syntax: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4473 The status of this proposal is “needs further work”, according to Botond Ballo’s “Trip Report: C++ Standards Meeting in Lenexa, May 2015” https://botondballo.wordpress.com/2015/06/05/trip-report-c-standards-meeting-in-lenexa-may-2015/ Further Work. The proposal’s direction is promising, but it is either not fleshed out well … Read more

`static constexpr` function called in a constant expression is…an error?

As T.C. demonstrated with some links in a comment, the standard is not quite clear on this; a similar problem arises with trailing return types using decltype(memberfunction()). The central problem is that class members are generally not considered to be declared until after the class in which they’re declared is complete. Thus, regardless of the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)