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 1ee54cf..e1a889d 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 ae98705..102b08e 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 13b930d..6ecbfca 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 ec4bb86..d90c298 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 5255e71..2578890 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 5ee13b8..0eeea7b 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 2299ad1..a91c989 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 "" } */
+};