public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Paolo Carlini <paolo.carlini@oracle.com>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Cc: Jason Merrill <jason@redhat.com>, David Malcolm <dmalcolm@redhat.com>
Subject: [C++ Patch] Fix a start_decl location
Date: Sun, 06 Jan 2019 09:47:00 -0000	[thread overview]
Message-ID: <b8ecf71b-22aa-cfe8-652a-f4cd56c6a8ed@oracle.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 793 bytes --]

Hi,

this was supposed to be very straightforward but required a little more. 
A first draft of the patch exploited DECL_SOURCE_LOCATION but that 
failed when I tested the case of a function already defined in class: at 
that point the location of the decl is that of the in class definition 
itself not that of the wrong redeclaration. Thus the use of 
declarator->id_loc. Tested x86_64-linux.

A final note, about a detail already noticed many other times: the 
location we store in such cases is that of K not that of f, and that 
seems suboptimal to me: in principle we should point to f and possibly 
have the wavy queue of the caret going back to K, at least that's what 
clang does... no idea id David has this kind of tweak in his todo list.

Thanks, Paolo.

////////////////////////


[-- Attachment #2: CL_locs_19 --]
[-- Type: text/plain, Size: 234 bytes --]

/cp
2019-01-06  Paolo Carlini  <paolo.carlini@oracle.com>

	* decl.c (start_decl): Improve permerror location.

/testsuite
2019-01-06  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/diagnostic/out-of-class-redeclaration.C: New.

[-- Attachment #3: patch_locs_19 --]
[-- Type: text/plain, Size: 1143 bytes --]

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 267600)
+++ cp/decl.c	(working copy)
@@ -5202,7 +5202,8 @@ start_decl (const cp_declarator *declarator,
       if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)
 	  /* Aliases are definitions. */
 	  && !alias)
-	permerror (input_location, "declaration of %q#D outside of class is not definition",
+	permerror (declarator->id_loc,
+		   "declaration of %q#D outside of class is not definition",
 		   decl);
     }
 
Index: testsuite/g++.dg/diagnostic/out-of-class-redeclaration.C
===================================================================
--- testsuite/g++.dg/diagnostic/out-of-class-redeclaration.C	(nonexistent)
+++ testsuite/g++.dg/diagnostic/out-of-class-redeclaration.C	(working copy)
@@ -0,0 +1,13 @@
+// Adapted from g++.old-deja/g++.law/arm8.C
+
+struct K {
+  void f(int);
+};
+
+void K::f(int);  // { dg-error "6:declaration of .void K::f\\(int\\). outside of class" }
+
+struct L {
+  void g(int) {}
+};
+
+void L::g(int);  // { dg-error "6:declaration of .void L::g\\(int\\). outside of class" }

             reply	other threads:[~2019-01-06  9:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-06  9:47 Paolo Carlini [this message]
2019-01-08  2:37 ` Jason Merrill

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=b8ecf71b-22aa-cfe8-652a-f4cd56c6a8ed@oracle.com \
    --to=paolo.carlini@oracle.com \
    --cc=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@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).