]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/61162 (possibly bad error location with -Wc++-compat)
authorMarek Polacek <polacek@redhat.com>
Wed, 25 Jun 2014 12:43:05 +0000 (12:43 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 25 Jun 2014 12:43:05 +0000 (12:43 +0000)
PR c/61162
* c-parser.c (c_parser_statement_after_labels): Pass the location of
the return expression to c_finish_return.

* gcc.dg/pr61162.c: Adjust dg-warning.
* gcc.dg/pr61162-2.c: New test.

From-SVN: r211978

gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/c/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr61162-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr61162.c

index 955828c03d30c2e99e8f1309e12cd10daa94e056..d1837c26634332ec1900e93ad4cd770658ab1b33 100644 (file)
@@ -1,3 +1,9 @@
+2014-06-25  Marek Polacek  <polacek@redhat.com>
+
+       PR c/61162
+       * c-parser.c (c_parser_statement_after_labels): Pass the location of
+       the return expression to c_finish_return.
+
 2014-06-25  Jakub Jelinek  <jakub@redhat.com>
 
        * c-typeck.c (c_finish_omp_clauses): Make sure
index f83ccb07db4d6dfa94cb0533bc103f8b28ef9b31..5842320c540fcdb9b022f5ad7708dd709705af22 100644 (file)
@@ -4948,9 +4948,10 @@ c_parser_statement_after_labels (c_parser *parser)
            }
          else
            {
+             location_t xloc = c_parser_peek_token (parser)->location;
              struct c_expr expr = c_parser_expression_conv (parser);
              mark_exp_read (expr.value);
-             stmt = c_finish_return (loc, expr.value, expr.original_type);
+             stmt = c_finish_return (xloc, expr.value, expr.original_type);
              goto expect_semicolon;
            }
          break;
index 4deeae76a073257199a0068566ae9e5e1405cee4..b62e83012ee7f6c41a0f96371acf467f54448104 100644 (file)
@@ -9185,7 +9185,8 @@ c_finish_goto_ptr (location_t loc, tree expr)
 
 /* Generate a C `return' statement.  RETVAL is the expression for what
    to return, or a null pointer for `return;' with no value.  LOC is
-   the location of the return statement.  If ORIGTYPE is not NULL_TREE, it
+   the location of the return statement, or the location of the expression,
+   if the statement has any.  If ORIGTYPE is not NULL_TREE, it
    is the original type of RETVAL.  */
 
 tree
index c70169138941b4902094fad7031a7570b2ce51a8..ac32cce64d61d178bd078044920662d50f3649de 100644 (file)
@@ -1,3 +1,9 @@
+2014-06-25  Marek Polacek  <polacek@redhat.com>
+
+       PR c/61162
+       * gcc.dg/pr61162.c: Adjust dg-warning.
+       * gcc.dg/pr61162-2.c: New test.
+
 2014-06-25  Marc Glisse  <marc.glisse@inria.fr>
 
        PR tree-optimization/57742
diff --git a/gcc/testsuite/gcc.dg/pr61162-2.c b/gcc/testsuite/gcc.dg/pr61162-2.c
new file mode 100644 (file)
index 0000000..1045408
--- /dev/null
@@ -0,0 +1,48 @@
+/* PR c/61162 */
+/* { dg-do compile } */
+/* { dg-options "-Wc++-compat -Wpointer-sign -Wpedantic" } */
+
+enum e { A };
+struct s { int a; };
+
+enum e
+fn1 (void)
+{
+  return 0; /* { dg-warning "10:enum conversion in return" } */
+}
+
+int
+fn2 (struct s s)
+{
+  return s; /* { dg-error "10:incompatible types when returning" } */
+}
+
+void
+fn3 (void)
+{
+  return 3; /* { dg-warning "10:in function returning void" } */
+}
+
+int
+fn4 (int *a)
+{
+  return a; /* { dg-warning "10:return makes integer from pointer without a cast" } */
+}
+
+int *
+fn5 (int a)
+{
+  return a; /* { dg-warning "10:return makes pointer from integer without a cast" } */
+}
+
+unsigned int *
+fn6 (int *i)
+{
+  return i; /* { dg-warning "10:pointer targets in return differ" } */
+}
+
+void *
+fn7 (void (*fp) (void))
+{
+  return fp; /* { dg-warning "10:ISO C forbids return between function pointer" } */
+}
index 00e64b9d758e0c14550fc9b33659a29f6f2bdd7c..8dcb0c8ed402fec259a1f8d2c98d01aa5fc94c49 100644 (file)
@@ -8,5 +8,5 @@ fn1 (void)
 {
   enum e e, q = 0; /* { dg-warning "17:enum conversion in initialization is invalid" } */
   e = 0; /* { dg-warning "5:enum conversion in assignment is invalid" } */
-  1; return 0; /* { dg-warning "6:enum conversion in return is invalid" } */
+  1; return 0; /* { dg-warning "13:enum conversion in return is invalid" } */
 }