public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] Fix location of grokdeclarator error message about static data member definition
@ 2018-12-12 14:56 Paolo Carlini
  2018-12-12 20:43 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Paolo Carlini @ 2018-12-12 14:56 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

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

Hi,

it seems we can easily improve the location of this - not so uncommon in 
novice code - error to point to the 'static' keyword.

Tested x86_64-linux.

Thanks, Paolo.

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


[-- Attachment #2: CL_static --]
[-- Type: text/plain, Size: 254 bytes --]

/cp
2018-12-12  Paolo Carlini  <paolo.carlini@oracle.com>

	* decl.c (grokdeclarator): Fix location of error message about
	static data member definition.

/testsuite
2018-12-12  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/other/static5.C: New.

[-- Attachment #3: patch_static --]
[-- Type: text/plain, Size: 1001 bytes --]

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 267051)
+++ cp/decl.c	(working copy)
@@ -12724,7 +12724,8 @@ grokdeclarator (const cp_declarator *declarator,
 	    DECL_CONTEXT (decl) = ctype;
 	    if (staticp == 1)
 	      {
-		permerror (input_location, "%<static%> may not be used when defining "
+		permerror (declspecs->locations[ds_storage_class],
+			   "%<static%> may not be used when defining "
 			   "(as opposed to declaring) a static data member");
 		staticp = 0;
 		storage_class = sc_none;
Index: testsuite/g++.dg/other/static5.C
===================================================================
--- testsuite/g++.dg/other/static5.C	(nonexistent)
+++ testsuite/g++.dg/other/static5.C	(working copy)
@@ -0,0 +1,8 @@
+struct S
+{
+  static int i;
+  const static double d;
+};
+
+static int S::i;  // { dg-error "1:.static. may not be used" }
+const static double S::d = 1.0;  // { dg-error "7:.static. may not be used" }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [C++ Patch] Fix location of grokdeclarator error message about static data member definition
  2018-12-12 14:56 [C++ Patch] Fix location of grokdeclarator error message about static data member definition Paolo Carlini
@ 2018-12-12 20:43 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2018-12-12 20:43 UTC (permalink / raw)
  To: Paolo Carlini, gcc-patches

On 12/12/18 9:56 AM, Paolo Carlini wrote:
> Hi,
> 
> it seems we can easily improve the location of this - not so uncommon in 
> novice code - error to point to the 'static' keyword.

OK.

Jason

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-12-12 20:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-12 14:56 [C++ Patch] Fix location of grokdeclarator error message about static data member definition Paolo Carlini
2018-12-12 20:43 ` Jason Merrill

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).