Cygwin: Add 'fallthrough' pseudo keyword for switch/case use

This patch has been inspired by the Linux kernel patch

  294f69e662d1 compiler_attributes.h: Add 'fallthrough' pseudo keyword for switch/case use

written by Joe Perches <joe AT perches DOT com> based on an idea from
Dan Carpenter <dan DOT carpenter AT oracle DOT com>.  The following text
is from the original log message:

Reserve the pseudo keyword 'fallthrough' for the ability to convert the
various case block /* fallthrough */ style comments to appear to be an
actual reserved word with the same gcc case block missing fallthrough
warning capability.

All switch/case blocks now should end in one of:

	break;
	fallthrough;
	goto <label>;
	return [expression];
	continue;

In C mode, GCC supports the __fallthrough__ attribute since 7.1,
the same time the warning and the comment parsing were introduced.

Cygwin-only: add an explicit -Wimplicit-fallthrough=5 to the build
flags.
This commit is contained in:
Corinna Vinschen
2020-08-05 21:58:22 +02:00
parent 5898a044c3
commit 50ad198085
33 changed files with 67 additions and 63 deletions

View File

@@ -180,7 +180,7 @@ __small_vsprintf (char *dst, const char *fmt, va_list ap)
pad = '0';
continue;
}
/*FALLTHRU*/
fallthrough;
case '1' ... '9':
len = len * 10 + (c - '0');
continue;
@@ -254,7 +254,7 @@ __small_vsprintf (char *dst, const char *fmt, va_list ap)
case 'y':
*dst++ = '0';
*dst++ = 'x';
/*FALLTHRU*/
fallthrough;
case 'x':
base = 16;
addsign = 0;
@@ -279,7 +279,7 @@ gen_decimal:
case 'Y':
*dst++ = '0';
*dst++ = 'x';
/*FALLTHRU*/
fallthrough;
case 'X':
base = 16;
addsign = 0;
@@ -299,7 +299,7 @@ gen_decimalLL:
n = strtol (fmt, (char **) &fmt, 10);
if (*fmt++ != 's')
goto endfor;
/*FALLTHRU*/
fallthrough;
case 's':
s = va_arg (ap, char *);
if (s == NULL)
@@ -540,7 +540,7 @@ __small_vswprintf (PWCHAR dst, const WCHAR *fmt, va_list ap)
pad = L'0';
continue;
}
/*FALLTHRU*/
fallthrough;
case L'1' ... L'9':
len = len * 10 + (c - L'0');
continue;
@@ -597,7 +597,7 @@ __small_vswprintf (PWCHAR dst, const WCHAR *fmt, va_list ap)
case 'y':
*dst++ = '0';
*dst++ = 'x';
/*FALLTHRU*/
fallthrough;
case 'x':
base = 16;
addsign = 0;
@@ -622,7 +622,7 @@ gen_decimal:
case 'Y':
*dst++ = '0';
*dst++ = 'x';
/*FALLTHRU*/
fallthrough;
case 'X':
base = 16;
addsign = 0;
@@ -645,7 +645,7 @@ gen_decimalLL:
n = wcstoul (fmt, (wchar_t **) &fmt, 10);
if (*fmt++ != L's')
goto endfor;
/*FALLTHRU*/
fallthrough;
case L's':
s = va_arg (ap, char *);
if (s == NULL)