From: Volker Reichelt Date: Thu, 20 Apr 2017 16:48:44 +0000 (+0000) Subject: c.opt (Wextra-semi): New C++ warning flag. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c3cbcd451736f5257446e927bb880ace569f4a45;p=gcc.git c.opt (Wextra-semi): New C++ warning flag. * c.opt (Wextra-semi): New C++ warning flag. * doc/invoke.texi (-Wextra-semi): Document new warning option. * parser.c (cp_parser_member_declaration): Add warning with fixit information for extra semicolon after in-class function definition. * g++.dg/warn/Wextra-semi.C: New test. From-SVN: r247028 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1ee54cfe91d..e1a889daea3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2017-04-20 Volker Reichelt + + * doc/invoke.texi (-Wextra-semi): Document new warning option. + 2017-04-20 Richard Biener PR tree-optimization/57796 diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index ae987057362..102b08eede8 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,7 @@ +2017-04-20 Volker Reichelt + + * c.opt (Wextra-semi): New C++ warning flag. + 2017-04-20 Jakub Jelinek PR middle-end/80423 diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 13b930d75d4..6ecbfca4413 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -504,6 +504,10 @@ Wextra C ObjC C++ ObjC++ Warning ; in common.opt +Wextra-semi +C++ ObjC++ Var(warn_extra_semi) Warning +Warn about semicolon after in-class function definition. + Wfloat-conversion C ObjC C++ ObjC++ Var(warn_float_conversion) Warning LangEnabledBy(C ObjC C++ ObjC++,Wconversion) Warn for implicit type conversions that cause loss of floating point precision. diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ec4bb86044a..d90c2985f04 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2017-04-20 Volker Reichelt + + * parser.c (cp_parser_member_declaration): Add warning with fixit + information for extra semicolon after in-class function definition. + 2017-04-20 Jakub Jelinek PR middle-end/80423 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 5255e713a32..25788902e16 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -23386,7 +23386,15 @@ cp_parser_member_declaration (cp_parser* parser) token = cp_lexer_peek_token (parser->lexer); /* If the next token is a semicolon, consume it. */ if (token->type == CPP_SEMICOLON) - cp_lexer_consume_token (parser->lexer); + { + location_t semicolon_loc + = cp_lexer_consume_token (parser->lexer)->location; + gcc_rich_location richloc (semicolon_loc); + richloc.add_fixit_remove (); + warning_at_rich_loc (&richloc, OPT_Wextra_semi, + "extra %<;%> after in-class " + "function definition"); + } goto out; } else diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 5ee13b8984a..0eeea7b3b87 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -274,7 +274,8 @@ Objective-C and Objective-C++ Dialects}. -Wno-discarded-qualifiers -Wno-discarded-array-qualifiers @gol -Wno-div-by-zero -Wdouble-promotion -Wduplicated-cond @gol -Wempty-body -Wenum-compare -Wno-endif-labels -Wexpansion-to-defined @gol --Werror -Werror=* -Wfatal-errors -Wfloat-equal -Wformat -Wformat=2 @gol +-Werror -Werror=* -Wextra-semi -Wfatal-errors @gol +-Wfloat-equal -Wformat -Wformat=2 @gol -Wno-format-contains-nul -Wno-format-extra-args @gol -Wformat-nonliteral -Wformat-overflow=@var{n} @gol -Wformat-security -Wformat-signedness -Wformat-truncation=@var{n} @gol @@ -5960,6 +5961,11 @@ In C++ enumerated type mismatches in conditional expressions are also diagnosed and the warning is enabled by default. In C this warning is enabled by @option{-Wall}. +@item -Wextra-semi @r{(C++, Objective-C++ only)} +@opindex Wextra-semi +@opindex Wno-extra-semi +Warn about redundant semicolon after in-class function definition. + @item -Wjump-misses-init @r{(C, Objective-C only)} @opindex Wjump-misses-init @opindex Wno-jump-misses-init diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2299ad1f5df..a91c9891da6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-04-20 Volker Reichelt + + * g++.dg/warn/Wextra-semi.C: New test. + 2017-04-20 Jakub Jelinek PR middle-end/80423 diff --git a/gcc/testsuite/g++.dg/warn/Wextra-semi.C b/gcc/testsuite/g++.dg/warn/Wextra-semi.C new file mode 100644 index 00000000000..8778582168b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wextra-semi.C @@ -0,0 +1,25 @@ +// { dg-options "-Wextra-semi -fdiagnostics-show-caret" } + +struct A +{ + A() {}; /* { dg-warning "after in-class function definition" } + { dg-begin-multiline-output "" } + A() {}; + ^ + - + { dg-end-multiline-output "" } */ + + void foo() {}; /* { dg-warning "after in-class function definition" } + { dg-begin-multiline-output "" } + void foo() {}; + ^ + - + { dg-end-multiline-output "" } */ + + friend void bar() {}; /* { dg-warning "after in-class function definition" } + { dg-begin-multiline-output "" } + friend void bar() {}; + ^ + - + { dg-end-multiline-output "" } */ +};