[committed] libstdc++: Define std::numeric_limits<_FloatNN> before C++23

Stephan Bergmann sbergman@redhat.com
Wed Oct 4 15:54:38 GMT 2023


On 8/17/23 22:32, Jonathan Wakely via Libstdc++ wrote:
> Tested x86_64-linux. Pushed to trunk.
> 
> -- >8 --
> 
> The extended floating-point types such as _Float32 are supported by GCC
> prior to C++23, you just can't use the standard-conforming names from
> <stdfloat> to refer to them. This change defines the specializations of
> std::numeric_limits for those types for older dialects, not only for
> C++23.
> 
> libstdc++-v3/ChangeLog:
> 
> 	* include/bits/c++config (__gnu_cxx::__bfloat16_t): Define
> 	whenever __BFLT16_DIG__ is defined, not only for C++23.
> 	* include/std/limits (numeric_limits<bfloat16_t>): Likewise.
> 	(numeric_limits<_Float16>, numeric_limits<_Float32>)
> 	(numeric_limits<_Float64>): Likewise for other extended
> 	floating-point types.
> ---
>   libstdc++-v3/include/bits/c++config |   4 +-
>   libstdc++-v3/include/std/limits     | 194 +++++++++++++++-------------
>   2 files changed, 103 insertions(+), 95 deletions(-)
> 
[...]
> diff --git a/libstdc++-v3/include/std/limits b/libstdc++-v3/include/std/limits
> index 52b19ef8264..7a59e7520eb 100644
> --- a/libstdc++-v3/include/std/limits
> +++ b/libstdc++-v3/include/std/limits
> @@ -1890,189 +1890,197 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
[...]
>   __glibcxx_float_n(64)
>   #endif
> -#ifdef __STDCPP_FLOAT128_T__
> +#ifdef __FLT128_DIG__
>   __glibcxx_float_n(128)
>   #endif
>   #undef __glibcxx_float_n
[...]

The above change (from __STDCPP_FLOAT128_T__ to __FLT128_DIG__) now 
started to cause issues with Clang on Clang 18 trunk:

* Clang does not support a _Float128 type.

* Clang does not predefine __STDCPP_FLOAT128_T__.

* But since 
<https://github.com/llvm/llvm-project/commit/457f582ffe23e951380bc345c4c96ec053c09681> 
"[clang] Predefined macros for float128 support (#67196)", Clang 18 
trunk does predefine __FLT128_DIG__ now.  Which causes

> $ cat test.cc
> #include <limits>

> $ clang++ -fsyntax-only test.cc
> In file included from test.cc:1:
> /home/sbergman/gcc/trunk/inst/lib/gcc/x86_64-pc-linux-gnu/14.0.0/../../../../include/c++/14.0.0/limits:1995:1: error: use of undeclared identifier '_Float128'
>  1995 | __glibcxx_float_n(128)
>       | ^
> /home/sbergman/gcc/trunk/inst/lib/gcc/x86_64-pc-linux-gnu/14.0.0/../../../../include/c++/14.0.0/limits:1903:27: note: expanded from macro '__glibcxx_float_n'
>  1903 |     struct numeric_limits<_Float##BITSIZE>                              \
>       |                           ^
> <scratch space>:36:1: note: expanded from here
>    36 | _Float128
>       | ^
> 1 error generated.

(I don't know whether or not it is useful for Clang to predefine 
__FLT128_DIG__ when not providing a _Float128 type.  I assume 
<https://www.iso.org/standard/65615.html> "ISO/IEC TS 18661-3:2015", as 
referenced by the C++ standard, might be relevant here, but don't know 
that document.  I added Pranav, the author of the relevant Clang commit, 
in cc here.)



More information about the Libstdc++ mailing list