You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"missing return statement" warning when a template ends in a dependent call to a [[noreturn]] function #255
Severity: warning noise (no build failure). Component:check_void_return_okay in src/statements.c
(ec_implicit_return_from_non_void_function).
Reproducer
//options_all:--gnu_version=150000 --diag_error=implicit_return_from_non_void_function[[noreturn]]voidfail(int);
template <classT> structR {
T v; bool ok;
T &get() { if (ok) return v; elsefail(v); }
};
int &use(R<int> &r) { return r.get(); }
Actual (without --diag_error):
"v2.cpp", line 5: warning: missing return statement at end of non-void function "R<T>::get"
Expected: no diagnostic. g++ 15 (-Wall -Wextra) is silent: GCC checks -Wreturn-type on the instantiation, where fail(v) is known to be [[noreturn]].
Analysis
The warning is issued when the template definition is parsed. At that point fail(v) is a dependent call whose target isn't known, so the end of the
function looks reachable. It is not reconsidered when R<int>::get is
instantiated, where the call resolves to the [[noreturn]]fail(int).
Variants tried (all with --gnu_version=150301 --c++17):
Variant
EDG
g++ 15
non-dependent call fail(0) in a template
silent
silent
dependent call fail(v)
warns
silent
dependent call to __attribute__((__noreturn__)) __attribute__((__noinline__)) inline (Boost's spelling)
warns
silent
dependent call to a template <class E> [[noreturn]] void fail(E const&)
warns
silent
same pattern in a non-template function
silent
silent
A possible fix: when the function is a template (prototype instantiation)
and the trailing statement on the reachable path is a call that is still
dependent, defer the implicit-return check to instantiation (or suppress it),
much as the constexpr case above it already defers to instantiation.
Impact on Boost
boost/system/result.hpp, result<T, E>::value() (and its const&, &&
overloads):
throw_exception_from_error is overloaded and BOOST_NORETURN (lines 38-68).
Every translation unit that includes boost/system/result.hpp gets these
warnings. That covers all of Boost.URL and Boost.JSON, plus anything else that
uses boost::system::result. See the README for counts from the full build.
Activity