re PR c/56724 (sub-optimal location in error)
authorMarek Polacek <polacek@redhat.com>
Thu, 5 Jun 2014 09:35:05 +0000 (09:35 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 5 Jun 2014 09:35:05 +0000 (09:35 +0000)
PR c/56724
* c-typeck.c (convert_for_assignment): Use expr_loc for ic_argpass.

* gcc.dg/pr56724-3.c: New test.

From-SVN: r211261

gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr56724-3.c [new file with mode: 0644]

index 732c9c1..85b0065 100644 (file)
@@ -1,5 +1,10 @@
 2014-06-05  Marek Polacek  <polacek@redhat.com>
 
+       PR c/56724
+       * c-typeck.c (convert_for_assignment): Use expr_loc for ic_argpass.
+
+2014-06-05  Marek Polacek  <polacek@redhat.com>
+
        PR c/49706
        * c-typeck.c (parser_build_binary_op): Warn when logical not is used
        on the left hand side operand of a comparison. 
index e0d3fde..f09f39e 100644 (file)
@@ -6025,8 +6025,9 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
 
         where NULL is typically defined in C to be '(void *) 0'.  */
       if (VOID_TYPE_P (ttr) && rhs != null_pointer_node && !VOID_TYPE_P (ttl))
-       warning_at (location, OPT_Wc___compat,
-                   "request for implicit conversion "
+       warning_at (errtype == ic_argpass ? expr_loc : location,
+                   OPT_Wc___compat,
+                   "request for implicit conversion "
                    "from %qT to %qT not permitted in C++", rhstype, type);
 
       /* See if the pointers point to incompatible address spaces.  */
@@ -6038,7 +6039,7 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
          switch (errtype)
            {
            case ic_argpass:
-             error_at (location, "passing argument %d of %qE from pointer to "
+             error_at (expr_loc, "passing argument %d of %qE from pointer to "
                        "non-enclosed address space", parmnum, rname);
              break;
            case ic_assign:
@@ -6067,7 +6068,7 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
          switch (errtype)
          {
          case ic_argpass:
-           warning_at (location, OPT_Wsuggest_attribute_format,
+           warning_at (expr_loc, OPT_Wsuggest_attribute_format,
                        "argument %d of %qE might be "
                        "a candidate for a format attribute",
                        parmnum, rname);
@@ -6246,9 +6247,10 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
   switch (errtype)
     {
     case ic_argpass:
-      error_at (location, "incompatible type for argument %d of %qE", parmnum, rname);
+      error_at (expr_loc, "incompatible type for argument %d of %qE", parmnum,
+               rname);
       inform ((fundecl && !DECL_IS_BUILTIN (fundecl))
-             ? DECL_SOURCE_LOCATION (fundecl) : input_location,
+             ? DECL_SOURCE_LOCATION (fundecl) : expr_loc,
              "expected %qT but argument is of type %qT", type, rhstype);
       break;
     case ic_assign:
@@ -6257,12 +6259,12 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
       break;
     case ic_init:
       error_at (location,
-               "incompatible types when initializing type %qT using type %qT",
+               "incompatible types when initializing type %qT using type %qT",
                type, rhstype);
       break;
     case ic_return:
       error_at (location,
-               "incompatible types when returning type %qT but %qT was "
+               "incompatible types when returning type %qT but %qT was "
                "expected", rhstype, type);
       break;
     default:
index 75e6db2..8ec6b5e 100644 (file)
@@ -1,3 +1,8 @@
+2014-06-05  Marek Polacek  <polacek@redhat.com>
+
+       PR c/56724
+       * gcc.dg/pr56724-3.c: New test.
+
 2014-06-05  Andreas Schwab  <schwab@suse.de>
 
        * g++.dg/cpp0x/initlist86.C (main): Initialize i.
diff --git a/gcc/testsuite/gcc.dg/pr56724-3.c b/gcc/testsuite/gcc.dg/pr56724-3.c
new file mode 100644 (file)
index 0000000..192d719
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR c/56724 */
+/* { dg-do compile } */
+/* { dg-options "-Wc++-compat" } */
+
+extern void xfer (int, int, unsigned char *);
+struct T { int a; } t;
+
+void
+call (int x, int y, void *arg)
+{
+  unsigned char *uc = arg; /* { dg-warning "23:request for implicit conversion" } */
+  xfer (x, y, arg); /* { dg-warning "15:request for implicit conversion" } */
+  xfer (x, y, t); /* { dg-error "15:incompatible type for" } */
+}