In case I missed it the first time.

-----Original Message-----
From: [email protected] <[email protected]> 
Sent: Thursday, April 19, 2018 2:39 PM
To: [email protected]
Subject: [Mingw-w64-public] Attempt to remove fallthrough warnings with GCC
7.2.0x

This is another attempt to remove the fallthrough warnings.  I decided to
redo the fallthrough maco.

 

The macro does look complex but I wanted something I could reuse something
in other work and I did not want to rely upon a "fall through" comment
because that is a hacky workaround and I prefer something that follows
syntax as much as possible.

 

The thing is that GCC 7.2.0 does tighten up on fallthrough by giving
warnings.  But some developers do the fallthrough deliberately and I suspect
that is the case her but please do review it in case it isn't.

 

 

----------------------------------------------------------------------------
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
diff --git a/mingw-w64-crt/crt/crtexe.c b/mingw-w64-crt/crt/crtexe.c
index e3900744..bbab40b5 100644
--- a/mingw-w64-crt/crt/crtexe.c
+++ b/mingw-w64-crt/crt/crtexe.c
@@ -113,6 +113,8 @@ extern int _MINGW_INSTALL_DEBUG_MATHERR;
 #else
 #define __UNUSED_PARAM_1       __UNUSED_PARAM
 #endif
+
+
 static void
 __mingw_invalidParameterHandler (const wchar_t * __UNUSED_PARAM_1(expression),
                                 const wchar_t * __UNUSED_PARAM_1(function),
diff --git a/mingw-w64-crt/gdtoa/dtoa.c b/mingw-w64-crt/gdtoa/dtoa.c
index 2906bd99..1f2d6189 100644
--- a/mingw-w64-crt/gdtoa/dtoa.c
+++ b/mingw-w64-crt/gdtoa/dtoa.c
@@ -282,7 +282,7 @@ char *__dtoa (double d0, int mode, int ndigits, int *decpt, 
int *sign, char **rv
                        break;
                case 2:
                        leftright = 0;
-                       /* no break */
+                       __FALLTHROUGH
                case 4:
                        if (ndigits <= 0)
                                ndigits = 1;
@@ -290,7 +290,7 @@ char *__dtoa (double d0, int mode, int ndigits, int *decpt, 
int *sign, char **rv
                        break;
                case 3:
                        leftright = 0;
-                       /* no break */
+                       __FALLTHROUGH
                case 5:
                        i = ndigits + k + 1;
                        ilim = i;
diff --git a/mingw-w64-crt/gdtoa/gdtoa.c b/mingw-w64-crt/gdtoa/gdtoa.c
index cf9c290f..a257d7fb 100644
--- a/mingw-w64-crt/gdtoa/gdtoa.c
+++ b/mingw-w64-crt/gdtoa/gdtoa.c
@@ -270,7 +270,7 @@ char *__gdtoa (FPI *fpi, int be, ULong *bits, int *kindp, 
int mode, int ndigits,
                        break;
                case 2:
                        leftright = 0;
-                       /* no break */
+                       __FALLTHROUGH
                case 4:
                        if (ndigits <= 0)
                                ndigits = 1;
@@ -278,7 +278,7 @@ char *__gdtoa (FPI *fpi, int be, ULong *bits, int *kindp, 
int mode, int ndigits,
                        break;
                case 3:
                        leftright = 0;
-                       /* no break */
+                       __FALLTHROUGH
                case 5:
                        i = ndigits + k + 1;
                        ilim = i;
diff --git a/mingw-w64-crt/gdtoa/gdtoaimp.h b/mingw-w64-crt/gdtoa/gdtoaimp.h
index 49b9ce05..3f579fff 100644
--- a/mingw-w64-crt/gdtoa/gdtoaimp.h
+++ b/mingw-w64-crt/gdtoa/gdtoaimp.h
@@ -194,6 +194,28 @@ THIS SOFTWARE.
 #include <stdlib.h>
 #include <string.h>
 
+#ifdef __cplusplus
+#  if defined(__has_cpp_attribute)
+#    if __has_cpp_attribute(fallthrough)
+#       define __FALLTHROUGH [[fallthrough]]; /* C++17 and above */
+#    elif __has_cpp_attribute(clang::fallthrough)
+#       define __FALLTHROUGH [[clang::fallthrough]]; /* C++11 and C++14 */
+#    elif __has_cpp_attribute(gnu::fallthrough)
+#       define __FALLTHROUGH [[gnu::fallthrough]]; /* C++11 and C++14 */
+#    endif
+#  endif
+#else
+#  if __GNUC__ > 6
+#    define __FALLTHROUGH __attribute__ ((fallthrough)); /* C and C++03 */
+#  elif defined( _MSC_VER)
+#    include <sal.h>
+#    define __FALLTHROUGH __attribute__;
+#  else
+#    define __FALLTHROUGH /* Falls through. */
+#  endif
+#endif
+
+
 #ifdef MALLOC
 extern void *MALLOC (size_t);
 #else
diff --git a/mingw-w64-crt/gdtoa/gethex.c b/mingw-w64-crt/gdtoa/gethex.c
index 27617545..6dadfb13 100644
--- a/mingw-w64-crt/gdtoa/gethex.c
+++ b/mingw-w64-crt/gdtoa/gethex.c
@@ -125,7 +125,7 @@ int gethex (const char **sp, FPI *fpi, Long *expo, Bigint 
**bp, int sign)
                switch(*++s) {
                  case '-':
                        esign = 1;
-                       /* no break */
+                       __FALLTHROUGH
                  case '+':
                        s++;
                }
diff --git a/mingw-w64-crt/gdtoa/strtodg.c b/mingw-w64-crt/gdtoa/strtodg.c
index 42ab9df3..27d2f2e4 100644
--- a/mingw-w64-crt/gdtoa/strtodg.c
+++ b/mingw-w64-crt/gdtoa/strtodg.c
@@ -309,11 +309,11 @@ int __strtodg (const char *s00, char **se, FPI *fpi, Long 
*expo, ULong *bits)
        for(s = s00;;s++) switch(*s) {
                case '-':
                        sign = 1;
-                       /* no break */
+                       __FALLTHROUGH
                case '+':
                        if (*++s)
                                goto break2;
-                       /* no break */
+                       __FALLTHROUGH
                case 0:
                        sign = 0;
                        irv = STRTOG_NoNumber;
@@ -411,6 +411,7 @@ int __strtodg (const char *s00, char **se, FPI *fpi, Long 
*expo, ULong *bits)
                switch(c = *++s) {
                        case '-':
                                esign = 1;
+                                __FALLTHROUGH
                        case '+':
                                c = *++s;
                }
diff --git a/mingw-w64-crt/stdio/mingw_pformat.c 
b/mingw-w64-crt/stdio/mingw_pformat.c
index 350c6638..800ab593 100644
--- a/mingw-w64-crt/stdio/mingw_pformat.c
+++ b/mingw-w64-crt/stdio/mingw_pformat.c
@@ -88,6 +88,28 @@
 #else
 #define ATTRIB_GCC_STRUCT
 #endif
+
+#ifdef __cplusplus
+#  if defined(__has_cpp_attribute)
+#    if __has_cpp_attribute(fallthrough)
+#       define __FALLTHROUGH [[fallthrough]]; /* C++17 and above */
+#    elif __has_cpp_attribute(clang::fallthrough)
+#       define __FALLTHROUGH [[clang::fallthrough]]; /* C++11 and C++14 */
+#    elif __has_cpp_attribute(gnu::fallthrough)
+#       define __FALLTHROUGH [[gnu::fallthrough]]; /* C++11 and C++14 */
+#    endif
+#  endif
+#else
+#  if __GNUC__ > 6
+#    define __FALLTHROUGH __attribute__ ((fallthrough)); /* C and C++03 */
+#  elif defined( _MSC_VER)
+#    include <sal.h>
+#    define __FALLTHROUGH __attribute__;
+#  else
+#    define __FALLTHROUGH /* Falls through. */
+#  endif
+#endif
+
 typedef struct ATTRIB_GCC_STRUCT __tI128 {
   int64_t digits[2];
 } __tI128;
@@ -2472,6 +2494,7 @@ __pformat (int flags, void *dest, int max, const APICHAR 
*fmt, va_list argv)
             * and simply fall through.
             */
            length = PFORMAT_LENGTH_LONG;
+            __FALLTHROUGH
 
          case 'c':
            /*
@@ -2516,6 +2539,7 @@ __pformat (int flags, void *dest, int max, const APICHAR 
*fmt, va_list argv)
             * and simply fall through.
             */
            length = PFORMAT_LENGTH_LONG;
+            __FALLTHROUGH
 
          case 's':
            if( (length == PFORMAT_LENGTH_LONG)
@@ -2679,6 +2703,7 @@ __pformat (int flags, void *dest, int max, const APICHAR 
*fmt, va_list argv)
             * select lower case mode, and simply fall through...
             */
            stream.flags |= PFORMAT_XCASE;
+            __FALLTHROUGH
 
          case 'E':
            /*
@@ -2724,6 +2749,7 @@ __pformat (int flags, void *dest, int max, const APICHAR 
*fmt, va_list argv)
             * simply fall through...
             */
            stream.flags |= PFORMAT_XCASE;
+            __FALLTHROUGH
 
          case 'F':
            /*
@@ -2767,6 +2793,7 @@ __pformat (int flags, void *dest, int max, const APICHAR 
*fmt, va_list argv)
             * mode, and simply fall through...
             */
            stream.flags |= PFORMAT_XCASE;
+            __FALLTHROUGH
 
          case 'G':
            /*
@@ -2811,6 +2838,7 @@ __pformat (int flags, void *dest, int max, const APICHAR 
*fmt, va_list argv)
             * fall through...
             */
            stream.flags |= PFORMAT_XCASE;
+            __FALLTHROUGH
 
          case 'A':
            /*
@@ -3168,6 +3196,7 @@ __pformat (int flags, void *dest, int max, const APICHAR 
*fmt, va_list argv)
              stream.flags |= PFORMAT_ZEROFILL;
              break;
            }
+            __FALLTHROUGH
 
          default:
            /*
diff --git a/mingw-w64-headers/crt/_mingw.h.in 
b/mingw-w64-headers/crt/_mingw.h.in
index 4c40da0c..235ed1f8 100644
--- a/mingw-w64-headers/crt/_mingw.h.in
+++ b/mingw-w64-headers/crt/_mingw.h.in
@@ -117,6 +117,27 @@ limitations in handling dllimport attribute.  */
 # endif
 #endif
 
+#ifdef __cplusplus
+#  if defined(__has_cpp_attribute)
+#    if __has_cpp_attribute(fallthrough)
+#       define __FALLTHROUGH [[fallthrough]]; /* C++17 and above */
+#    elif __has_cpp_attribute(clang::fallthrough)
+#       define __FALLTHROUGH [[clang::fallthrough]]; /* C++11 and C++14 */
+#    elif __has_cpp_attribute(gnu::fallthrough)
+#       define __FALLTHROUGH [[gnu::fallthrough]]; /* C++11 and C++14 */
+#    endif
+#  endif
+#else
+#  if __GNUC__ > 6
+#    define __FALLTHROUGH __attribute__ ((fallthrough)); /* C and C++03 */
+#  elif defined( _MSC_VER)
+#    include <sal.h>
+#    define __FALLTHROUGH __attribute__;
+#  else
+#    define __FALLTHROUGH /* Falls through. */
+#  endif
+#endif
+
 #ifndef __GNUC__
 # ifdef _MSC_VER
 #  define __restrict__  __restrict
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to