Hi. This helps the warning with --save-temps. Doing that one needs to preserve comments in preprocessed source file.
Ready for trunk? Martin gcc/ChangeLog: 2018-04-03 Martin Liska <mli...@suse.cz> PR preprocessor/78497 * gcc.c: Add -C when using -Wimplicit-fallthrough and --save-temps. gcc/testsuite/ChangeLog: 2018-04-03 Martin Liska <mli...@suse.cz> PR preprocessor/78497 * c-c++-common/Wimplicit-fallthrough-37.c: New test. --- gcc/gcc.c | 3 ++- .../c-c++-common/Wimplicit-fallthrough-37.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/c-c++-common/Wimplicit-fallthrough-37.c
diff --git a/gcc/gcc.c b/gcc/gcc.c index a716f708259..f641c249e27 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -1131,7 +1131,8 @@ static const char *cpp_options = "%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w}\ %{f*} %{g*:%{%:debug-level-gt(0):%{g*}\ %{!fno-working-directory:-fworking-directory}}} %{O*}\ - %{undef} %{save-temps*:-fpch-preprocess}"; + %{undef} %{save-temps*:-fpch-preprocess}\ + %{Wimplicit-fallthrough*|Werror=implicit-fallthrough*:%{save-temps*:-C}}"; /* This contains cpp options which are not passed when the preprocessor output will be used by another program. */ diff --git a/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-37.c b/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-37.c new file mode 100644 index 00000000000..ca9d21fc70e --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-37.c @@ -0,0 +1,22 @@ +/* PR preprocessor/78497 */ +/* { dg-do compile } */ +/* { dg-options "-Wimplicit-fallthrough --save-temps" } */ + +int main (int argc, char **argv) +{ + int a; + switch (argc) + { + case 1: + a = 1; + break; + case 2: + a = 2; + /* FALLTHROUGH */ + case 3: + a = 3; + break; + } + + return a; +}