public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: "Joseph S. Myers" <joseph@codesourcery.com>,
	       Marek Polacek <polacek@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [C PATCH] Fix up location used in get_parm_info diagnostics (PR c/68533)
Date: Tue, 01 Dec 2015 20:35:00 -0000	[thread overview]
Message-ID: <20151201203458.GZ5675@tucnak.redhat.com> (raw)

Hi!

get_parm_info right now uses input_location as the diagnostics locus, but as
can be seen on the testcase, that is pretty random location at that point,
often the type of the last parameter.

This patch changes it to use the locus from the binding info.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2015-12-01  Jakub Jelinek  <jakub@redhat.com>

	PR c/68533
	* c-decl.c (get_parm_info): Use b->locus instead of input_location
	for diagnostics.

	* gcc.dg/pr68533.c: New test.

--- gcc/c/c-decl.c.jj	2015-11-30 13:40:35.000000000 +0100
+++ gcc/c/c-decl.c	2015-12-01 16:14:40.466462666 +0100
@@ -6913,11 +6913,11 @@ get_parm_info (bool ellipsis, tree expr)
     {
       if (TYPE_QUALS (TREE_TYPE (b->decl)) != TYPE_UNQUALIFIED
 	  || C_DECL_REGISTER (b->decl))
-	error ("%<void%> as only parameter may not be qualified");
+	error_at (b->locus, "%<void%> as only parameter may not be qualified");
 
       /* There cannot be an ellipsis.  */
       if (ellipsis)
-	error ("%<void%> must be the only parameter");
+	error_at (b->locus, "%<void%> must be the only parameter");
 
       arg_info->types = void_list_node;
       return arg_info;
@@ -6946,13 +6946,14 @@ get_parm_info (bool ellipsis, tree expr)
 
 	  /* Check for forward decls that never got their actual decl.  */
 	  if (TREE_ASM_WRITTEN (decl))
-	    error ("parameter %q+D has just a forward declaration", decl);
+	    error_at (b->locus,
+		      "parameter %q+D has just a forward declaration", decl);
 	  /* Check for (..., void, ...) and issue an error.  */
 	  else if (VOID_TYPE_P (type) && !DECL_NAME (decl))
 	    {
 	      if (!gave_void_only_once_err)
 		{
-		  error ("%<void%> must be the only parameter");
+		  error_at (b->locus, "%<void%> must be the only parameter");
 		  gave_void_only_once_err = true;
 		}
 	    }
@@ -6991,13 +6992,13 @@ get_parm_info (bool ellipsis, tree expr)
 	    {
 	      if (b->id)
 		/* The %s will be one of 'struct', 'union', or 'enum'.  */
-		warning_at (input_location, 0,
+		warning_at (b->locus, 0,
 			    "%<%s %E%> declared inside parameter list"
 			    " will not be visible outside of this definition or"
 			    " declaration", keyword, b->id);
 	      else
 		/* The %s will be one of 'struct', 'union', or 'enum'.  */
-		warning_at (input_location, 0,
+		warning_at (b->locus, 0,
 			    "anonymous %s declared inside parameter list"
 			    " will not be visible outside of this definition or"
 			    " declaration", keyword);
--- gcc/testsuite/gcc.dg/pr68533.c.jj	2015-12-01 18:47:55.864178841 +0100
+++ gcc/testsuite/gcc.dg/pr68533.c	2015-12-01 18:48:56.000000000 +0100
@@ -0,0 +1,68 @@
+/* PR c/68533 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct T { int t; };
+
+void
+f1 (
+  struct S *	/* { dg-warning "declared inside parameter list will not be visible outside of this definition or declaration" } */
+  x,
+  struct T *
+  y
+   )
+{
+  y->t = 4;
+}
+
+void
+f2 (
+  struct {int s;} * /* { dg-warning "anonymous struct declared inside parameter list will not be visible outside of this definition or declaration" } */
+  x,
+  struct T *
+  y
+   )
+{
+  y->t = 5;
+}
+
+void
+f3 (
+  const void
+   )		/* { dg-error "'void' as only parameter may not be qualified" } */
+{
+}
+
+void
+f4 (
+   void,	/* { dg-error "'void' must be the only parameter" } */
+   ...
+   )
+{
+}
+
+void
+f5 (
+   int
+   x;		/* { dg-error "parameter 'x' has just a forward declaration" } */
+   int y
+   )
+{
+}
+
+void
+f6 (
+   int
+   x,
+   void
+   )		/* { dg-error "'void' must be the only parameter" } */
+{
+}
+
+void
+f7 (
+   void,	/* { dg-error "'void' must be the only parameter" } */
+   int y
+   )
+{
+}

	Jakub

             reply	other threads:[~2015-12-01 20:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-01 20:35 Jakub Jelinek [this message]
2015-12-02  3:57 ` Jeff Law
2015-12-02  7:16   ` Jakub Jelinek
2015-12-02  7:17     ` Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151201203458.GZ5675@tucnak.redhat.com \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    --cc=polacek@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).