Patchwork [C] More locus tweaks (PR c/56724)

login
register
mail settings
Submitter Marek Polacek
Date June 5, 2014, 9:17 a.m.
Message ID <20140605091737.GA24532@redhat.com>
Download mbox | patch
Permalink /patch/356243/
State New
Headers show

Comments

Marek Polacek - June 5, 2014, 9:17 a.m.
My previous patch for 56724 didn't handle all cases of this.
So let's fix this now by using expr_loc for ic_argpass.

Tested x86_64-unknown-linux-gnu, applying to trunk.

2014-06-05  Marek Polacek  <polacek@redhat.com>

	PR c/56724
	* c-typeck.c (convert_for_assignment): Use expr_loc for ic_argpass.

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


	Marek

Patch

diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index e0d3fde..f09f39e 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -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:
diff --git gcc/testsuite/gcc.dg/pr56724-3.c gcc/testsuite/gcc.dg/pr56724-3.c
index e69de29..192d719 100644
--- gcc/testsuite/gcc.dg/pr56724-3.c
+++ gcc/testsuite/gcc.dg/pr56724-3.c
@@ -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" } */
+}