In the book The C++ Programming Language it is written that you can declare a function to be conditionally noexcept. For example:
template<typename T>
void my_fct(T& x) noexcept(std::is_pod<T>::value);
noexcept takes a predicate that must be a constant expression (in the example std::is_pod<T>::value).
However, in the book it is also written:
The
noexcept()operator takes an expression as its argument and returnstrueif the compiler knows that it cannot throw andfalseotherwise.
Taking this into account, consider:
constexpr bool f() { return true; }
void g() noexcept(f())
{
    f();
}
Is g() marked as noexcept or not? I see two possibilities:
- The call 
f()is evaluated at compile-time because it is markedconstexpr, it returnstrueand as a resultg()is markednoexcept. - The compiler cannot determine that 
f()cannot throw an exception becausef()is not markednoexcept. As a resultg()is not markednoexcept. 
Which one does happen? How can I select one or other behavior for noexcept?
Aucun commentaire:
Enregistrer un commentaire