The current C++ standard enables compilers to look into the function body for information to complete a function's signature:
template <typename T>
inline auto dereference(T const& pointer) {
return *pointer;
}
And I wonder if the compiler could automatically declare whether a function is nothrow guaranteed if the definition can be seen, maybe with syntax like this:
void func() noexcept(auto) {
… // If all operations in the function are noexcept, the
// function can be automatically declared noexcept
}
If that is possible, it would saves much trouble in writing the noexcept declaration, especially when writing templates, where functions are usually followed by their definitions on their first appearence:
// The noexcept declaration can be even longer than the function body
template <typename T>
void func(T& value) noexcept(
noexcept(value.member_1()) &&
noexcept(value.member_2()) &&
noexcept(value.member_3())
) {
value.member_1();
value.member_2();
value.member_3();
}
// Things will become much easier if the C++ standard support this feature
template <typename T>
void func(T& value) noexcept(auto) {
value.member_1();
value.member_2();
value.member_3();
}
So, is this feature possible to enter a future version of ISO/IEC 14882?