public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] Use locations[ds_storage_class] in error messages about ill-formed uses of mutable
@ 2019-01-15 16:58 Paolo Carlini
  2019-01-15 20:42 ` Martin Sebor
  0 siblings, 1 reply; 4+ messages in thread
From: Paolo Carlini @ 2019-01-15 16:58 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

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

Hi,

something a little different from my last patches but nevertheless 
pretty straightforward (noticed while I was wondering whether we should 
immediately move the location_t grokdeclarator local even further up). 
Tested x86_64-linux, as usual.

Thanks, Paolo.

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


[-- Attachment #2: CL_locs_26 --]
[-- Type: text/plain, Size: 500 bytes --]

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

	* decl.c (grokdeclarator): Use locations[ds_storage_class] in
	error messages about ill-formed uses of mutable.

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

	* g++.dg/other/pr33558.C: Test location too.
	* g++.dg/other/pr33558-2.C: Likewise.
	* g++.dg/parse/crash4.C: Likewise.
	* g++.old-deja/g++.brendan/err-msg11.C: Likewise.
	* g++.old-deja/g++.mike/p7635.C: Likewise.
	* g++.old-deja/g++.other/decl6.C: Likewise.

[-- Attachment #3: patch_locs_26 --]
[-- Type: text/plain, Size: 6066 bytes --]

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 267932)
+++ cp/decl.c	(working copy)
@@ -11902,36 +11902,40 @@ grokdeclarator (const cp_declarator *declarator,
 
   if (storage_class == sc_mutable)
     {
+      location_t sloc = declspecs->locations[ds_storage_class];
       if (decl_context != FIELD || friendp)
 	{
-	  error ("non-member %qs cannot be declared %<mutable%>", name);
+	  error_at (sloc, "non-member %qs cannot be declared %<mutable%>",
+		    name);
 	  storage_class = sc_none;
 	}
       else if (decl_context == TYPENAME || typedef_p)
 	{
-	  error ("non-object member %qs cannot be declared %<mutable%>", name);
+	  error_at (sloc,
+		    "non-object member %qs cannot be declared %<mutable%>",
+		    name);
 	  storage_class = sc_none;
 	}
       else if (TREE_CODE (type) == FUNCTION_TYPE
 	       || TREE_CODE (type) == METHOD_TYPE)
 	{
-	  error ("function %qs cannot be declared %<mutable%>", name);
+	  error_at (sloc, "function %qs cannot be declared %<mutable%>", name);
 	  storage_class = sc_none;
 	}
       else if (staticp)
 	{
-	  error ("static %qs cannot be declared %<mutable%>", name);
+	  error_at (sloc, "static %qs cannot be declared %<mutable%>", name);
 	  storage_class = sc_none;
 	}
       else if (type_quals & TYPE_QUAL_CONST)
 	{
-	  error ("const %qs cannot be declared %<mutable%>", name);
+	  error_at (sloc, "const %qs cannot be declared %<mutable%>", name);
 	  storage_class = sc_none;
 	}
       else if (TYPE_REF_P (type))
 	{
-	  permerror (input_location, "reference %qs cannot be declared "
-	             "%<mutable%>", name);
+	  permerror (sloc, "reference %qs cannot be declared %<mutable%>",
+		     name);
 	  storage_class = sc_none;
 	}
     }
Index: testsuite/g++.dg/other/pr33558-2.C
===================================================================
--- testsuite/g++.dg/other/pr33558-2.C	(revision 267931)
+++ testsuite/g++.dg/other/pr33558-2.C	(working copy)
@@ -2,5 +2,5 @@
 /* { dg-options "-fpermissive" } */
 
 class X {
-  mutable int &q; /* { dg-warning "cannot be declared 'mutable'" } */
+  mutable int &q; /* { dg-warning "3:reference .q. cannot be declared .mutable." } */
 };
Index: testsuite/g++.dg/other/pr33558.C
===================================================================
--- testsuite/g++.dg/other/pr33558.C	(revision 267931)
+++ testsuite/g++.dg/other/pr33558.C	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
 
 class X {
-  mutable int &q; /* { dg-error "cannot be declared 'mutable'" } */
+  mutable int &q; /* { dg-error "3:reference .q. cannot be declared .mutable." } */
 };
Index: testsuite/g++.dg/parse/crash4.C
===================================================================
--- testsuite/g++.dg/parse/crash4.C	(revision 267931)
+++ testsuite/g++.dg/parse/crash4.C	(working copy)
@@ -7,6 +7,6 @@ struct Bar
  {
      void func(void)
      {
-       mutable Bar::type x; // { dg-error "" }
+       mutable Bar::type x; // { dg-error "8:non-member .x. cannot be declared .mutable." }
      }
  };
Index: testsuite/g++.old-deja/g++.brendan/err-msg11.C
===================================================================
--- testsuite/g++.old-deja/g++.brendan/err-msg11.C	(revision 267931)
+++ testsuite/g++.old-deja/g++.brendan/err-msg11.C	(working copy)
@@ -1,3 +1,3 @@
 // { dg-do assemble  }
 // GROUPS passed error-messages
-void foo (mutable int x);// { dg-error "" }  non-member `x' cannot be declared `mutable'.*
+void foo (mutable int x);// { dg-error "11:non-member .x. cannot be declared .mutable." }  non-member `x' cannot be declared `mutable'.*
Index: testsuite/g++.old-deja/g++.mike/p7635.C
===================================================================
--- testsuite/g++.old-deja/g++.mike/p7635.C	(revision 267931)
+++ testsuite/g++.old-deja/g++.mike/p7635.C	(working copy)
@@ -3,5 +3,5 @@
 
 class DaycountBasis {
   mutable const int * p;
-  mutable int * const q;	// { dg-error "" } 
+  mutable int * const q;	// { dg-error "3:const .q. cannot be declared .mutable." } 
 };
Index: testsuite/g++.old-deja/g++.other/decl6.C
===================================================================
--- testsuite/g++.old-deja/g++.other/decl6.C	(revision 267931)
+++ testsuite/g++.old-deja/g++.other/decl6.C	(working copy)
@@ -11,16 +11,16 @@ struct A
   friend explicit B::B ();    // { dg-error "" } only ctor decls can be explicit
   int f(const);               // { dg-error "" } ansi forbids no type
   const k;                    // { dg-error "" } ansi forbids no type
-  mutable friend int j1 ();   // { dg-error "" } non-member cannot be mutable
+  mutable friend int j1 ();   // { dg-error "3:storage class specifiers" } non-member cannot be mutable
   mutable typedef int d;      // { dg-error "" } non-object cannot be mutable
-  mutable int fn ();          // { dg-error "" } non-object cannot be mutable
-  void fn (mutable int);      // { dg-error "" } non-member cannot be mutable
+  mutable int fn ();          // { dg-error "3:function .fn. cannot be declared .mutable." } non-object cannot be mutable
+  void fn (mutable int);      // { dg-error "12:non-member .parameter. cannot be declared .mutable." } non-member cannot be mutable
   mutable static int s;       // { dg-error "" } static cannot be mutable
-  mutable const int s1;       // { dg-error "" } const cannot be mutable
+  mutable const int s1;       // { dg-error "3:const .s1. cannot be declared .mutable." } const cannot be mutable
   mutable const int *s2;      // ok
-  mutable int *const s3;      // { dg-error "" } const cannot be mutable
+  mutable int *const s3;      // { dg-error "3:const .s3. cannot be declared .mutable." } const cannot be mutable
   explicit A ();              // ok
 };
-mutable int g;                // { dg-error "" } non-member cannot be mutable
+mutable int g;                // { dg-error "1:non-member .g. cannot be declared .mutable." } non-member cannot be mutable
 explicit A::A () {}           // { dg-error "" } only ctor decls can be explicit
 

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

* Re: [C++ Patch] Use locations[ds_storage_class] in error messages about ill-formed uses of mutable
  2019-01-15 16:58 [C++ Patch] Use locations[ds_storage_class] in error messages about ill-formed uses of mutable Paolo Carlini
@ 2019-01-15 20:42 ` Martin Sebor
  2019-01-15 22:27   ` Paolo Carlini
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Sebor @ 2019-01-15 20:42 UTC (permalink / raw)
  To: Paolo Carlini, gcc-patches; +Cc: Jason Merrill

On 1/15/19 9:58 AM, Paolo Carlini wrote:
> Hi,
> 
> something a little different from my last patches but nevertheless 
> pretty straightforward (noticed while I was wondering whether we should 
> immediately move the location_t grokdeclarator local even further up). 
> Tested x86_64-linux, as usual.

Since you're already making changes to the tests, would be too much
more work to also add quoting around static and const in the error
messages below where mutable is already quoted:

-	  error ("static %qs cannot be declared %<mutable%>", name);
+	  error_at (sloc, "static %qs cannot be declared %<mutable%>", name);
  	  storage_class = sc_none;
  	}
        else if (type_quals & TYPE_QUAL_CONST)
  	{
-	  error ("const %qs cannot be declared %<mutable%>", name);
+	  error_at (sloc, "const %qs cannot be declared %<mutable%>", name);

(I can see it being a hassle if there were many other tests where
the messages expect to find static and const with no quotes.)

Martin

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

* Re: [C++ Patch] Use locations[ds_storage_class] in error messages about ill-formed uses of mutable
  2019-01-15 20:42 ` Martin Sebor
@ 2019-01-15 22:27   ` Paolo Carlini
  2019-01-16 15:57     ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Paolo Carlini @ 2019-01-15 22:27 UTC (permalink / raw)
  To: Martin Sebor, gcc-patches; +Cc: Jason Merrill

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

Hi Martin,

On 15/01/19 21:42, Martin Sebor wrote:
> On 1/15/19 9:58 AM, Paolo Carlini wrote:
>> Hi,
>>
>> something a little different from my last patches but nevertheless 
>> pretty straightforward (noticed while I was wondering whether we 
>> should immediately move the location_t grokdeclarator local even 
>> further up). Tested x86_64-linux, as usual.
>
> Since you're already making changes to the tests, would be too much
> more work to also add quoting around static and const in the error
> messages below where mutable is already quoted:
>
> -      error ("static %qs cannot be declared %<mutable%>", name);
> +      error_at (sloc, "static %qs cannot be declared %<mutable%>", 
> name);
>        storage_class = sc_none;
>      }
>        else if (type_quals & TYPE_QUAL_CONST)
>      {
> -      error ("const %qs cannot be declared %<mutable%>", name);
> +      error_at (sloc, "const %qs cannot be declared %<mutable%>", name);
>
> (I can see it being a hassle if there were many other tests where
> the messages expect to find static and const with no quotes.)

No problem, that's not the case. I'm finishing testing the below, then.

Thanks, Paolo.

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


[-- Attachment #2: patch_locs_26b --]
[-- Type: text/plain, Size: 6101 bytes --]

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 267932)
+++ cp/decl.c	(working copy)
@@ -11902,36 +11902,43 @@ grokdeclarator (const cp_declarator *declarator,
 
   if (storage_class == sc_mutable)
     {
+      location_t sloc = declspecs->locations[ds_storage_class];
       if (decl_context != FIELD || friendp)
 	{
-	  error ("non-member %qs cannot be declared %<mutable%>", name);
+	  error_at (sloc, "non-member %qs cannot be declared %<mutable%>",
+		    name);
 	  storage_class = sc_none;
 	}
       else if (decl_context == TYPENAME || typedef_p)
 	{
-	  error ("non-object member %qs cannot be declared %<mutable%>", name);
+	  error_at (sloc,
+		    "non-object member %qs cannot be declared %<mutable%>",
+		    name);
 	  storage_class = sc_none;
 	}
       else if (TREE_CODE (type) == FUNCTION_TYPE
 	       || TREE_CODE (type) == METHOD_TYPE)
 	{
-	  error ("function %qs cannot be declared %<mutable%>", name);
+	  error_at (sloc, "function %qs cannot be declared %<mutable%>",
+		    name);
 	  storage_class = sc_none;
 	}
       else if (staticp)
 	{
-	  error ("static %qs cannot be declared %<mutable%>", name);
+	  error_at (sloc, "%<static%> %qs cannot be declared %<mutable%>",
+		    name);
 	  storage_class = sc_none;
 	}
       else if (type_quals & TYPE_QUAL_CONST)
 	{
-	  error ("const %qs cannot be declared %<mutable%>", name);
+	  error_at (sloc, "%<const%> %qs cannot be declared %<mutable%>",
+		    name);
 	  storage_class = sc_none;
 	}
       else if (TYPE_REF_P (type))
 	{
-	  permerror (input_location, "reference %qs cannot be declared "
-	             "%<mutable%>", name);
+	  permerror (sloc, "reference %qs cannot be declared %<mutable%>",
+		     name);
 	  storage_class = sc_none;
 	}
     }
Index: testsuite/g++.dg/other/pr33558-2.C
===================================================================
--- testsuite/g++.dg/other/pr33558-2.C	(revision 267931)
+++ testsuite/g++.dg/other/pr33558-2.C	(working copy)
@@ -2,5 +2,5 @@
 /* { dg-options "-fpermissive" } */
 
 class X {
-  mutable int &q; /* { dg-warning "cannot be declared 'mutable'" } */
+  mutable int &q; /* { dg-warning "3:reference .q. cannot be declared .mutable." } */
 };
Index: testsuite/g++.dg/other/pr33558.C
===================================================================
--- testsuite/g++.dg/other/pr33558.C	(revision 267931)
+++ testsuite/g++.dg/other/pr33558.C	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
 
 class X {
-  mutable int &q; /* { dg-error "cannot be declared 'mutable'" } */
+  mutable int &q; /* { dg-error "3:reference .q. cannot be declared .mutable." } */
 };
Index: testsuite/g++.dg/parse/crash4.C
===================================================================
--- testsuite/g++.dg/parse/crash4.C	(revision 267931)
+++ testsuite/g++.dg/parse/crash4.C	(working copy)
@@ -7,6 +7,6 @@ struct Bar
  {
      void func(void)
      {
-       mutable Bar::type x; // { dg-error "" }
+       mutable Bar::type x; // { dg-error "8:non-member .x. cannot be declared .mutable." }
      }
  };
Index: testsuite/g++.old-deja/g++.brendan/err-msg11.C
===================================================================
--- testsuite/g++.old-deja/g++.brendan/err-msg11.C	(revision 267931)
+++ testsuite/g++.old-deja/g++.brendan/err-msg11.C	(working copy)
@@ -1,3 +1,3 @@
 // { dg-do assemble  }
 // GROUPS passed error-messages
-void foo (mutable int x);// { dg-error "" }  non-member `x' cannot be declared `mutable'.*
+void foo (mutable int x);// { dg-error "11:non-member .x. cannot be declared .mutable." }  non-member `x' cannot be declared `mutable'.*
Index: testsuite/g++.old-deja/g++.mike/p7635.C
===================================================================
--- testsuite/g++.old-deja/g++.mike/p7635.C	(revision 267931)
+++ testsuite/g++.old-deja/g++.mike/p7635.C	(working copy)
@@ -3,5 +3,5 @@
 
 class DaycountBasis {
   mutable const int * p;
-  mutable int * const q;	// { dg-error "" } 
+  mutable int * const q;	// { dg-error "3:.const. .q. cannot be declared .mutable." } 
 };
Index: testsuite/g++.old-deja/g++.other/decl6.C
===================================================================
--- testsuite/g++.old-deja/g++.other/decl6.C	(revision 267931)
+++ testsuite/g++.old-deja/g++.other/decl6.C	(working copy)
@@ -11,16 +11,16 @@ struct A
   friend explicit B::B ();    // { dg-error "" } only ctor decls can be explicit
   int f(const);               // { dg-error "" } ansi forbids no type
   const k;                    // { dg-error "" } ansi forbids no type
-  mutable friend int j1 ();   // { dg-error "" } non-member cannot be mutable
+  mutable friend int j1 ();   // { dg-error "3:storage class specifiers" } non-member cannot be mutable
   mutable typedef int d;      // { dg-error "" } non-object cannot be mutable
-  mutable int fn ();          // { dg-error "" } non-object cannot be mutable
-  void fn (mutable int);      // { dg-error "" } non-member cannot be mutable
+  mutable int fn ();          // { dg-error "3:function .fn. cannot be declared .mutable." } non-object cannot be mutable
+  void fn (mutable int);      // { dg-error "12:non-member .parameter. cannot be declared .mutable." } non-member cannot be mutable
   mutable static int s;       // { dg-error "" } static cannot be mutable
-  mutable const int s1;       // { dg-error "" } const cannot be mutable
+  mutable const int s1;       // { dg-error "3:.const. .s1. cannot be declared .mutable." } const cannot be mutable
   mutable const int *s2;      // ok
-  mutable int *const s3;      // { dg-error "" } const cannot be mutable
+  mutable int *const s3;      // { dg-error "3:.const. .s3. cannot be declared .mutable." } const cannot be mutable
   explicit A ();              // ok
 };
-mutable int g;                // { dg-error "" } non-member cannot be mutable
+mutable int g;                // { dg-error "1:non-member .g. cannot be declared .mutable." } non-member cannot be mutable
 explicit A::A () {}           // { dg-error "" } only ctor decls can be explicit
 

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

* Re: [C++ Patch] Use locations[ds_storage_class] in error messages about ill-formed uses of mutable
  2019-01-15 22:27   ` Paolo Carlini
@ 2019-01-16 15:57     ` Jason Merrill
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2019-01-16 15:57 UTC (permalink / raw)
  To: Paolo Carlini, Martin Sebor, gcc-patches

On 1/15/19 5:27 PM, Paolo Carlini wrote:
> Hi Martin,
> 
> On 15/01/19 21:42, Martin Sebor wrote:
>> On 1/15/19 9:58 AM, Paolo Carlini wrote:
>>> Hi,
>>>
>>> something a little different from my last patches but nevertheless 
>>> pretty straightforward (noticed while I was wondering whether we 
>>> should immediately move the location_t grokdeclarator local even 
>>> further up). Tested x86_64-linux, as usual.
>>
>> Since you're already making changes to the tests, would be too much
>> more work to also add quoting around static and const in the error
>> messages below where mutable is already quoted:
>>
>> -      error ("static %qs cannot be declared %<mutable%>", name);
>> +      error_at (sloc, "static %qs cannot be declared %<mutable%>", 
>> name);
>>        storage_class = sc_none;
>>      }
>>        else if (type_quals & TYPE_QUAL_CONST)
>>      {
>> -      error ("const %qs cannot be declared %<mutable%>", name);
>> +      error_at (sloc, "const %qs cannot be declared %<mutable%>", name);
>>
>> (I can see it being a hassle if there were many other tests where
>> the messages expect to find static and const with no quotes.)
> 
> No problem, that's not the case. I'm finishing testing the below, then.

OK.

Jason

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

end of thread, other threads:[~2019-01-16 15:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-15 16:58 [C++ Patch] Use locations[ds_storage_class] in error messages about ill-formed uses of mutable Paolo Carlini
2019-01-15 20:42 ` Martin Sebor
2019-01-15 22:27   ` Paolo Carlini
2019-01-16 15:57     ` 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).