float.h: Handle C2x __STDC_WANT_IEC_60559_EXT__

Joseph Myers joseph@codesourcery.com
Sat Nov 14 00:09:56 GMT 2020


TS 18661-1 and 18661-2 have various definitions conditional on
__STDC_WANT_IEC_60559_BFP_EXT__ and __STDC_WANT_IEC_60559_DFP_EXT__
macros.  When those TSes were integrated into C2x, most of the feature
test macro conditionals were removed (with declarations for decimal FP
becoming conditional only on whether decimal FP is supported by the
implementation and those for binary FP becoming unconditionally
required).

A few tests of those feature test macros remained for declarations
that appeared only in Annex F and not in the main part of the
standard.  A change accepted for C2x at the last WG14 meeting (but not
yet added to the working draft in git) was to replace both those
macros by __STDC_WANT_IEC_60559_EXT__; if __STDC_WANT_IEC_60559_EXT__
is defined, the specific declarations in the headers will then depend
on which features are supported by the implementation, as for
declarations not controlled by a feature test macro at all.

Thus, add a check of __STDC_WANT_IEC_60559_EXT__ for CR_DECIMAL_DIG in
float.h, the only case of this change relevant to GCC.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.  OK to commit?

gcc/
2020-11-14  Joseph Myers  <joseph@codesourcery.com>

	* ginclude/float.h (CR_DECIMAL_DIG): Also define for
	[__STDC_WANT_IEC_60559_EXT__].

gcc/testsuite/
2020-11-14  Joseph Myers  <joseph@codesourcery.com>

	* gcc.dg/cr-decimal-dig-3.c: New test.

diff --git a/gcc/ginclude/float.h b/gcc/ginclude/float.h
index 9c4b0385568..0442f26ec56 100644
--- a/gcc/ginclude/float.h
+++ b/gcc/ginclude/float.h
@@ -250,7 +250,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #endif /* C2X */
 
-#ifdef __STDC_WANT_IEC_60559_BFP_EXT__
+#if (defined __STDC_WANT_IEC_60559_BFP_EXT__ \
+     || defined __STDC_WANT_IEC_60559_EXT__)
 /* Number of decimal digits for which conversions between decimal
    character strings and binary formats, in both directions, are
    correctly rounded.  */
diff --git a/gcc/testsuite/gcc.dg/cr-decimal-dig-3.c b/gcc/testsuite/gcc.dg/cr-decimal-dig-3.c
new file mode 100644
index 00000000000..8e07b67dd52
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cr-decimal-dig-3.c
@@ -0,0 +1,14 @@
+/* Test C2x CR_DECIMAL_DIG: defined for __STDC_WANT_IEC_60559_EXT__.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x" } */
+
+#define __STDC_WANT_IEC_60559_EXT__
+#include <float.h>
+
+#ifndef CR_DECIMAL_DIG
+#error "CR_DECIMAL_DIG not defined"
+#endif
+
+#if CR_DECIMAL_DIG < DECIMAL_DIG + 3
+#error "CR_DECIMAL_DIG too small"
+#endif

-- 
Joseph S. Myers
joseph@codesourcery.com


More information about the Gcc-patches mailing list