[Bug c++/91388] -Wreturn-type "no return statement" warning in function that is already ill-formed
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sun Mar 15 06:04:39 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91388
--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:681d834df5e06cf459adc352f72622fb0f7ef4e8
commit r14-12382-g681d834df5e06cf459adc352f72622fb0f7ef4e8
Author: Jakub Jelinek <jakub@redhat.com>
Date: Fri Dec 19 16:44:16 2025 +0100
c++: Suppress -Wreturn-type warnings for functions with failed assertions
[PR91388]
This is something Jonathan has asked for recently. E.g. in the recent
libstdc++ r16-6177 random.tcc changes, there was
if constexpr (__d <= 32)
return __generate_canonical_any<_RealT, uint64_t, __d>(__urng);
else
{
#if defined(__SIZEOF_INT128__)
static_assert(__d <= 64,
"irregular RNG with float precision >64 is not supported");
return __generate_canonical_any<
_RealT, unsigned __int128, __d>(__urng);
#else
static_assert(false, "irregular RNG with float precision"
" >32 requires __int128 support");
#endif
}
and when we hit there the static_assert, we don't get just an error about
that, but also a -Wreturn-type warning in the same function because that
path falls through to the end of function without returning a value.
But a function with a failed static_assert is erroneous and will never
fall through to the end. We could treat failed static_assert in functions
as __builtin_unreachable (), but I think it doesn't matter where exactly
in a function static_assert(false); appears, so this patch just suppresses
-Wreturn-type warning in that function instead.
2025-12-19 Jakub Jelinek <jakub@redhat.com>
PR c++/91388
* semantics.cc (finish_static_assert): Suppress -Wreturn-type
warnings
in functions with failed assertions.
* g++.dg/cpp1z/static_assert1.C: New test.
(cherry picked from commit a6687d123301287a26c09073d360bc2d93176666)
More information about the Gcc-bugs
mailing list