c.opt (Wextra-semi): New C++ warning flag.
authorVolker Reichelt <v.reichelt@netcologne.de>
Thu, 20 Apr 2017 16:48:44 +0000 (16:48 +0000)
committerVolker Reichelt <reichelt@gcc.gnu.org>
Thu, 20 Apr 2017 16:48:44 +0000 (16:48 +0000)
        * 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

gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c.opt
gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wextra-semi.C [new file with mode: 0644]

index 1ee54cfe91d51ca5aa93c4bdc2e63d687106eae8..e1a889daea35852e7c4b0a3c3732cbfb077ef45c 100644 (file)
@@ -1,3 +1,7 @@
+2017-04-20  Volker Reichelt  <v.reichelt@netcologne.de>
+
+       * doc/invoke.texi (-Wextra-semi): Document new warning option.
+
 2017-04-20  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/57796
index ae98705736269103867d4d01121afa54497d2a60..102b08eede82cf6ecab649ddc5b57cb6203653a3 100644 (file)
@@ -1,3 +1,7 @@
+2017-04-20  Volker Reichelt  <v.reichelt@netcologne.de>
+
+       * c.opt (Wextra-semi): New C++ warning flag.
+
 2017-04-20  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/80423
index 13b930d75d4feef4ed8f16fcc486d6198bef510e..6ecbfca44137aefe71fe6315f40fe805c4f92b81 100644 (file)
@@ -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.
index ec4bb86044acc6efed3a597091872906a2dd3152..d90c2985f0495baebe788b1e2cf40ab16c2e3b99 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-20  Volker Reichelt  <v.reichelt@netcologne.de>
+
+       * parser.c (cp_parser_member_declaration): Add warning with fixit
+       information for extra semicolon after in-class function definition.
+
 2017-04-20  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/80423
index 5255e713a32495249985b3be94e6649964e722c5..25788902e1679375a915987a6451214cf7dbf691 100644 (file)
@@ -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
index 5ee13b8984a8626f2d2b57841b8aa93a4fba3553..0eeea7b3b877665678943f978955bf09f3e6e19a 100644 (file)
@@ -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
index 2299ad1f5df4675061ecec7853c54c97a5e7d61d..a91c9891da62e1e399949b9e37e5eaee9558575b 100644 (file)
@@ -1,3 +1,7 @@
+2017-04-20  Volker Reichelt  <v.reichelt@netcologne.de>
+
+       * g++.dg/warn/Wextra-semi.C: New test.
+
 2017-04-20  Jakub Jelinek  <jakub@redhat.com>
 
        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 (file)
index 0000000..8778582
--- /dev/null
@@ -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 "" } */
+};