[PATCH 1/4] libstdc++: Avoid '-Wunused-parameter' for '__what' in function 'void std::__throw_format_error(const char*)'

Jonathan Wakely jwakely@redhat.com
Thu Feb 20 17:16:57 GMT 2025


On Thu, 20 Feb 2025 at 17:06, Thomas Schwinge <tschwinge@baylibre.com> wrote:
>
> In a '-fno-exceptions' configuration:
>
>     In file included from ../../../../../source-gcc/libstdc++-v3/src/c++20/format.cc:29:
>     [...]/build-gcc/[...]/libstdc++-v3/include/format: In function ‘void std::__throw_format_error(const char*)’:
>     [...]/build-gcc/[...]/libstdc++-v3/include/format:200:36: error: unused parameter ‘__what’ [-Werror=unused-parameter]
>       200 |   __throw_format_error(const char* __what)
>           |                        ~~~~~~~~~~~~^~~~~~
>
>         libstdc++-v3/
>         * include/bits/c++config [!__cpp_exceptions]
>         (_GLIBCXX_THROW_OR_ABORT): Reference '_EXC'.
> ---
>  libstdc++-v3/include/bits/c++config | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
> index b0ca6579cfb..e9782c03ee2 100644
> --- a/libstdc++-v3/include/bits/c++config
> +++ b/libstdc++-v3/include/bits/c++config
> @@ -253,7 +253,7 @@
>  # if __cpp_exceptions
>  #  define _GLIBCXX_THROW_OR_ABORT(_EXC) (throw (_EXC))
>  # else
> -#  define _GLIBCXX_THROW_OR_ABORT(_EXC) (__builtin_abort())
> +#  define _GLIBCXX_THROW_OR_ABORT(_EXC) ((void) (_EXC), __builtin_abort())

We don't want to evaluate _EXC before aborting. There's no reason to
e.g. concatenate strings and allocate memory to do so, or copy
filesystem::path objects into a filesystem::filesystem_error that will
never be thrown, or obtain a reference to an error_category.

I don't think we want/need this at all, but it could be done like this
if we need _EXC to be present but unused:

#  define _GLIBCXX_THROW_OR_ABORT(_EXC) (__builtin_abort(), (void)(_EXC))



More information about the Libstdc++ mailing list