r260639 - <float.h>: do not define DECIMAL_DIG in -std=c89 mode; this macro was added in C99.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 11 17:15:33 PST 2016


Author: rsmith
Date: Thu Feb 11 19:15:33 2016
New Revision: 260639

URL: http://llvm.org/viewvc/llvm-project?rev=260639&view=rev
Log:
<float.h>: do not define DECIMAL_DIG in -std=c89 mode; this macro was added in C99.

Patch by Jorge Teixeira!

Modified:
    cfe/trunk/lib/Headers/float.h
    cfe/trunk/test/Headers/float.c

Modified: cfe/trunk/lib/Headers/float.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/float.h?rev=260639&r1=260638&r2=260639&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/float.h (original)
+++ cfe/trunk/lib/Headers/float.h Thu Feb 11 19:15:33 2016
@@ -39,7 +39,9 @@
 #  undef FLT_MANT_DIG
 #  undef DBL_MANT_DIG
 #  undef LDBL_MANT_DIG
-#  undef DECIMAL_DIG
+#  if __STDC_VERSION__ >= 199901L || !defined(__STRICT_ANSI__)
+#    undef DECIMAL_DIG
+#  endif
 #  undef FLT_DIG
 #  undef DBL_DIG
 #  undef LDBL_DIG
@@ -84,7 +86,9 @@
 #define DBL_MANT_DIG __DBL_MANT_DIG__
 #define LDBL_MANT_DIG __LDBL_MANT_DIG__
 
-#define DECIMAL_DIG __DECIMAL_DIG__
+#if __STDC_VERSION__ >= 199901L || !defined(__STRICT_ANSI__)
+#  define DECIMAL_DIG __DECIMAL_DIG__
+#endif
 
 #define FLT_DIG __FLT_DIG__
 #define DBL_DIG __DBL_DIG__

Modified: cfe/trunk/test/Headers/float.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/float.c?rev=260639&r1=260638&r2=260639&view=diff
==============================================================================
--- cfe/trunk/test/Headers/float.c (original)
+++ cfe/trunk/test/Headers/float.c Thu Feb 11 19:15:33 2016
@@ -3,9 +3,15 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -ffreestanding %s
 // expected-no-diagnostics
 
-/* Basic conformance checks against the N1570 draft of C11 Std. */
+/* Basic floating point conformance checks against:
+    - N1570 draft of C11 Std.
+    - N1256 draft of C99 Std.
+    - http://port70.net/~nsz/c/c89/c89-draft.html draft of C89/C90 Std.
+*/
 /*
-    5.2.4.2.2p11, pp. 30
+    C11,    5.2.4.2.2p11,   pp. 30
+    C99,    5.2.4.2.2p9,    pp. 25
+    C89,    2.2.4.2 
 */
 #include <float.h>
 
@@ -68,10 +74,16 @@
 #endif
 
 
-#ifndef DECIMAL_DIG
-    #error "Mandatory macro DECIMAL_DIG is missing."
-#elif   DECIMAL_DIG < 10
-    #error "Mandatory macro DECIMAL_DIG is invalid."
+#if __STDC_VERSION__ >= 199901L || !defined(__STRICT_ANSI__)
+    #ifndef DECIMAL_DIG
+        #error "Mandatory macro DECIMAL_DIG is missing."
+    #elif   DECIMAL_DIG < 10
+        #error "Mandatory macro DECIMAL_DIG is invalid."
+    #endif
+#else
+    #ifdef DECIMAL_DIG
+        #error "Macro DECIMAL_DIG should not be defined."
+    #endif
 #endif
 
 
@@ -182,7 +194,9 @@ _Static_assert(DBL_DECIMAL_DIG == __DBL_
 _Static_assert(LDBL_DECIMAL_DIG == __LDBL_DECIMAL_DIG__, "");
 #endif
 
+#if __STDC_VERSION__ >= 199901L || !defined(__STRICT_ANSI__)
 _Static_assert(DECIMAL_DIG == __DECIMAL_DIG__, "");
+#endif
 
 _Static_assert(FLT_DIG == __FLT_DIG__, "");
 _Static_assert(DBL_DIG == __DBL_DIG__, "");




More information about the cfe-commits mailing list