]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
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 732c9c1eb70f2aad9760b7c25a7588ddf0439470..85b00650fe9c85045cdafe70d747934c537892af 100644 (file)
@@ -1,3 +1,8 @@
+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
index e0d3fdea0f124a134204addb698d21568ea60d84..f09f39e811452532985c89ad1b6630708f87a405 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 75e6db2205e7a6a691befb6a462dfa2c276ce10b..8ec6b5ebf5304bec94c5a63fb4565d6ac7e495cf 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" } */
+}