OSDN Git Service

Expose C99 features required by C++11; fix issue [#2335]
authorKeith Marshall <keithmarshall@users.sourceforge.net>
Sun, 29 Jan 2017 10:09:49 +0000 (10:09 +0000)
committerKeith Marshall <keithmarshall@users.sourceforge.net>
Sun, 29 Jan 2017 10:09:49 +0000 (10:09 +0000)
mingwrt/ChangeLog
mingwrt/include/_mingw.h.in
mingwrt/include/ctype.h
mingwrt/include/inttypes.h
mingwrt/include/wctype.h

index 59beea4..ebc7c4c 100644 (file)
@@ -1,3 +1,20 @@
+2017-01-29  Keith Marshall  <keithmarshall@users.sourceforge.net>
+
+       Expose C99 features required by C++11; fix issue [#2335]
+
+       * include/_mingw.h.in (_ISOC99_SOURCE): Ensure it is defined for...
+       [__cplusplus >= 201103L]: ...this conformance level, in addition to...
+       [__STDC_VERSION__>= 199901L || _POSIX_C_SOURCE >= 200112L]: ...these.
+       [_GLIBCXX_USE_C99]: Force it for -std=c++11, subject to...
+       [__GNUC__ < 6]: ...this.
+
+       * include/ctype.h (isblank): Declare it only if...
+       [_ISOC99_SOURCE]: ...this, thus simplifying declarative condition.
+       * include/wctype.h (iswblank) [_ISOC99_SOURCE]: Likewise.
+       * include/inttypes.h (SCNd8, SCNdLEAST8, SCNdFAST8, SCNi8, SCNiLEAST8)
+       (SCNiFAST8, SCNo8, SCNoLEAST8, SCNoFAST8, SCNx8, SCNxLEAST8, SCNxFAST8)
+       (SCNu8, SCNuLEAST8, SCNuFAST8) [_ISOC99_SOURCE]: Likewise.
+
 2017-01-28  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
        Make strnlen() and wcsnlen() declaratively consistent.
index 57fc0cc..fd99590 100644 (file)
@@ -8,7 +8,7 @@
  * $Id$
  *
  * Written by Mumit Khan  <khan@xraylith.wisc.edu>
- * Copyright (C) 1999, 2001-2011, 2014-2016, MinGW.org Project
+ * Copyright (C) 1999, 2001-2011, 2014-2017, MinGW.org Project
  *
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -451,18 +451,62 @@ allow GCC to optimize away some EH unwind code, at least in DW2 case.  */
  /* libmingwex.a provides free-standing implementations for many of the
   * functions which were introduced in C99; MinGW headers do not expose
   * prototypes for these, unless this feature test macro is defined, by
-  * the user, or implied by other standards...
+  * the user, or implied by other standards.  We will use a bit-mapped
+  * representation, comprising the bit-wise sum of:
+  *
+  *   0x08  user declared
+  *   0x04  required by C compiler, supporting ISO-C99
+  *   0x02  required by C++ compiler, supporting ISO-C++11
+  *   0x01  required to support recent POSIX.1 features
+  *
+  * to ensure that we can identify the reason for implicit declaration,
+  * (in the event that we may need to discriminate).
   */
-# if __STDC_VERSION__ >= 199901L || _POSIX_C_SOURCE >= 200112L
-#  define _ISOC99_SOURCE  1
+# if __STDC_VERSION__ >= 199901L
+  /* This represents a compiler supporting ISO-C99; enable all potential
+   * use of ISO-C99 features, (to the maximum extent supportable), which
+   * presumably also covers all C++11 and POSIX.1 usage.
+   */
+#  define _ISOC99_SOURCE  0x07
+
+# elif __cplusplus >= 201103L
+  /* C++11 also incorporates many (if not all) of the ISO-C99 features,
+   * which we have guarded by _ISOC99_SOURCE; enable such features, to
+   * the required extent, (which is likely also sufficient to support
+   * any POSIX.1 dependencies).
+   */
+#  define _ISOC99_SOURCE  0x03
+
+# elif _POSIX_C_SOURCE >= 200112L
+  /* This represents the minimum level of ISO-C99 support, which may be
+   * required by POSIX.1, (and which may be no less than full support).
+   */
+#  define _ISOC99_SOURCE  0x01
 # endif
+
+#else
+ /* The the user has explicitly declared a source level dependency on
+  * ISO-C99 features; regardless of how it was declared, redefine it to
+  * ensure that any plausible dependency is covered.
+  */
+# undef _ISOC99_SOURCE
+# define _ISOC99_SOURCE  0x0F
+
+#endif /* _ISOC99_SOURCE */
+
+#if _ISOC99_SOURCE && __cplusplus >= 201103L && __GNUC__ < 6
+ /* Due to a configuration defect in GCC versions prior to GCC-6, when
+  * compiling C++11 code, the ISO-C99 functions may not be incorporated
+  * into the appropriate namespace(s); we may be able to mitigate this,
+  * by ensuring that this GCC configuration macro is defined.
+  */
+# define _GLIBCXX_USE_C99  1
 #endif
 
 #if ! defined _MINGW32_SOURCE_EXTENDED && ! defined __STRICT_ANSI__
-/*
- * Enable mingw32 extensions by default, except when __STRICT_ANSI__
- * conformity mode has been enabled.
- */
+ /* Enable mingw32 extensions by default, except when __STRICT_ANSI__
+  * conformity mode has been enabled.
+  */
 # define _MINGW32_SOURCE_EXTENDED  1
 #endif
 
index 7ff41a0..58fb2fd 100644 (file)
@@ -80,7 +80,7 @@ _CRTIMP __cdecl __MINGW_NOTHROW  int isspace(int);
 _CRTIMP __cdecl __MINGW_NOTHROW  int isupper(int);
 _CRTIMP __cdecl __MINGW_NOTHROW  int isxdigit(int);
 
-#if __STDC_VERSION__ >= 199901L || !defined __STRICT_ANSI__
+#if _ISOC99_SOURCE
 __cdecl __MINGW_NOTHROW  int isblank (int);
 #endif
 
@@ -217,7 +217,7 @@ __CRT_INLINE __cdecl __MINGW_NOTHROW  int isupper (int c)
 __CRT_INLINE __cdecl __MINGW_NOTHROW  int isxdigit (int c)
 { return __ISCTYPE(c, _HEX); }
 
-#if __STDC_VERSION__ >= 199901L || !defined __STRICT_ANSI__
+#if _ISOC99_SOURCE
 __CRT_INLINE __cdecl __MINGW_NOTHROW  int isblank (int c)
 { return (__ISCTYPE(c, _BLANK) || c == '\t'); }
 #endif
index e5e5d5b..6da1d97 100644 (file)
@@ -222,10 +222,12 @@ typedef struct {
 #define SCNuMAX "I64u"
 #define SCNuPTR "u"
 
-#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-/*
- * no length modifier for char types prior to C9x
- * MS runtime  scanf appears to treat "hh" as "h"
+#if _ISOC99_SOURCE
+/* Defined by the user, or implicitly in <_mingw.h>, indicating that
+ * we are compiling for C99, C++11, or POSIX.1-2001 (or later); no char
+ * type length modifiers are supported prior to C99.  Further note that
+ * Microsoft's scanf() appears to treat the ISO-C99/POSIX.1 "hh" length
+ * modifier as if it were just "h".
  */
 
 /* signed char */
@@ -249,7 +251,7 @@ typedef struct {
 #define SCNu8 "hhu"
 #define SCNuLEAST8 "hhu"
 #define SCNuFAST8 "hhu"
-#endif /* __STDC_VERSION__ >= 199901 */
+#endif /* _ISOC99_SOURCE */
 
 #endif /* !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) */
 
index 492f2f0..7b7ed20 100644 (file)
@@ -6,7 +6,7 @@
  * $Id$
  *
  * Written by Mumit Khan <khan@xraylith.wisc.edu>
- * Copyright (C) 1999-2003, 2005-2007, 2016, MinGW.org Project
+ * Copyright (C) 1999-2003, 2005-2007, 2016, 2017, MinGW.org Project
  *
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -119,7 +119,7 @@ __MINGW_ATTRIB_DEPRECATED
  */
 _CRTIMP __cdecl __MINGW_NOTHROW  int is_wctype (wint_t, wctype_t);
 
-#if __STDC_VERSION__>=199901L || !defined __STRICT_ANSI__ || defined __cplusplus
+#if _ISOC99_SOURCE
 __cdecl __MINGW_NOTHROW  int iswblank (wint_t);
 #endif
 
@@ -173,7 +173,7 @@ __CRT_INLINE __cdecl __MINGW_NOTHROW  int iswupper (wint_t wc)
 __CRT_INLINE __cdecl __MINGW_NOTHROW  int iswxdigit (wint_t wc)
 { return (iswctype (wc, _HEX)); }
 
-#if __STDC_VERSION__>=199901L || !defined __STRICT_ANSI__ || defined __cplusplus
+#if _ISOC99_SOURCE
 __CRT_INLINE __cdecl __MINGW_NOTHROW  int iswblank (wint_t wc)
 { return (iswctype (wc, _BLANK) || wc == L'\t'); }
 #endif