public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] Use declspecs->locations more
@ 2015-06-03 14:42 Paolo Carlini
  2015-06-03 16:30 ` Jason Merrill
  2015-06-04  9:16 ` Andreas Schwab
  0 siblings, 2 replies; 4+ messages in thread
From: Paolo Carlini @ 2015-06-03 14:42 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

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

Hi,

this is a first follow up to c++/65598, where I noticed that we should 
probably use declspecs->locations more for more accurate locations. 
Tested x86_64-linux.

Thanks,
Paolo.

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

[-- Attachment #2: CL_decl_loc1 --]
[-- Type: text/plain, Size: 424 bytes --]

/cp
2015-06-03  Paolo Carlini  <paolo.carlini@oracle.com>

	* decl.c (check_tag_decl): Use declspecs->locations as locations in
	error_at and warning_at calls.

/testsuite
2015-06-03  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/cpp0x/decl-loc1.C: New.
	* g++.dg/cpp0x/constexpr-neg1.C: Adjust.
	* g++.dg/cpp0x/constexpr-object1.C: Likewise.
	* g++.dg/init/ctor8.C: Likewise.
	* g++.dg/parse/semicolon4.C: Likewise.

[-- Attachment #3: patch_decl_loc1 --]
[-- Type: text/plain, Size: 6258 bytes --]

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 224061)
+++ cp/decl.c	(working copy)
@@ -4488,30 +4488,46 @@ check_tag_decl (cp_decl_specifier_seq *declspecs,
 
   else
     {
-      if (decl_spec_seq_has_spec_p (declspecs, ds_inline)
-	  || decl_spec_seq_has_spec_p (declspecs, ds_virtual))
-	error ("%qs can only be specified for functions",
-	       decl_spec_seq_has_spec_p (declspecs, ds_inline)
-	       ? "inline" : "virtual");
+      if (decl_spec_seq_has_spec_p (declspecs, ds_inline))
+	error_at (declspecs->locations[ds_inline],
+		  "%<inline%> can only be specified for functions");
+      else if (decl_spec_seq_has_spec_p (declspecs, ds_virtual))
+	error_at (declspecs->locations[ds_virtual],
+		  "%<virtual%> can only be specified for functions");
       else if (saw_friend
 	       && (!current_class_type
 		   || current_scope () != current_class_type))
-	error ("%<friend%> can only be specified inside a class");
+	error_at (declspecs->locations[ds_friend],
+		  "%<friend%> can only be specified inside a class");
       else if (decl_spec_seq_has_spec_p (declspecs, ds_explicit))
-	error ("%<explicit%> can only be specified for constructors");
+	error_at (declspecs->locations[ds_explicit],
+		  "%<explicit%> can only be specified for constructors");
       else if (declspecs->storage_class)
-	error ("a storage class can only be specified for objects "
-	       "and functions");
-      else if (decl_spec_seq_has_spec_p (declspecs, ds_const)
-	       || decl_spec_seq_has_spec_p (declspecs, ds_volatile)
-	       || decl_spec_seq_has_spec_p (declspecs, ds_restrict)
-	       || decl_spec_seq_has_spec_p (declspecs, ds_thread))
-	error ("qualifiers can only be specified for objects "
-	       "and functions");
+	error_at (declspecs->locations[ds_storage_class],
+		  "a storage class can only be specified for objects "
+		  "and functions");
+      else if (decl_spec_seq_has_spec_p (declspecs, ds_const))
+	error_at (declspecs->locations[ds_const],
+		  "%<const%> can only be specified for objects and "
+		  "functions");
+      else if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
+	error_at (declspecs->locations[ds_volatile],
+		  "%<volatile%> can only be specified for objects and "
+		  "functions");
+      else if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
+	error_at (declspecs->locations[ds_restrict],
+		  "%<__restrict%> can only be specified for objects and "
+		  "functions");
+      else if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
+	error_at (declspecs->locations[ds_thread],
+		  "%<__thread%> can only be specified for objects "
+		  "and functions");
       else if (saw_typedef)
-	warning (0, "%<typedef%> was ignored in this declaration");
+	warning_at (declspecs->locations[ds_typedef], 0,
+		    "%<typedef%> was ignored in this declaration");
       else if (decl_spec_seq_has_spec_p (declspecs,  ds_constexpr))
-        error ("%<constexpr%> cannot be used for type declarations");
+        error_at (declspecs->locations[ds_constexpr],
+		  "%<constexpr%> cannot be used for type declarations");
     }
 
   if (declspecs->attributes && warn_attributes && declared_type)
Index: testsuite/g++.dg/cpp0x/constexpr-neg1.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-neg1.C	(revision 224061)
+++ testsuite/g++.dg/cpp0x/constexpr-neg1.C	(working copy)
@@ -5,12 +5,12 @@
 constexpr int square(int x);	// { dg-message "never defined" }
 
 // error: pixel is a type
-constexpr struct pixel {
+constexpr struct pixel {        // { dg-error "constexpr" }
   int x;
   int y;
   // OK: declaration
   constexpr pixel(int);
-};				// { dg-error "constexpr" }
+};
 constexpr pixel::pixel(int a)
 // OK: definition
   : x(square(a)), y(square(a))	// { dg-error "square" }
Index: testsuite/g++.dg/cpp0x/constexpr-object1.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-object1.C	(revision 224061)
+++ testsuite/g++.dg/cpp0x/constexpr-object1.C	(working copy)
@@ -22,8 +22,8 @@ const constexpr A1 a3 = A1();
 volatile constexpr A1 a4 = A1(); // { dg-bogus "both .volatile. and .constexpr. cannot" }
 
 // error: on type declaration
-constexpr struct pixel
+constexpr struct pixel // { dg-error "cannot be used for type declarations" }
 {
   int x;
   int y;
-};		     // { dg-error "cannot be used for type declarations" }
+};
Index: testsuite/g++.dg/cpp0x/decl-loc1.C
===================================================================
--- testsuite/g++.dg/cpp0x/decl-loc1.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/decl-loc1.C	(working copy)
@@ -0,0 +1,13 @@
+// { dg-do compile { target c++11 } }
+
+inline struct A;      // { dg-error "1:'inline'" }
+virtual struct B;     // { dg-error "1:'virtual'" }
+friend struct C;      // { dg-error "1:'friend'" }
+explicit struct D;    // { dg-error "1:'explicit'" }
+mutable struct E;     // { dg-error "1:a storage class" }
+const struct F;       // { dg-error "1:'const'" }
+volatile struct G;    // { dg-error "1:'volatile'" }
+__restrict struct H;  // { dg-error "1:'__restrict'" }
+__thread struct I;    // { dg-error "1:'__thread'" }
+typedef struct J;     // { dg-warning "1:'typedef'" }
+constexpr struct K;   // { dg-error "1:'constexpr'" }
Index: testsuite/g++.dg/init/ctor8.C
===================================================================
--- testsuite/g++.dg/init/ctor8.C	(revision 224061)
+++ testsuite/g++.dg/init/ctor8.C	(working copy)
@@ -2,7 +2,7 @@
 
 typedef struct S { // { dg-error "reference" "" { target c++11 } }
   int &r; 
-}; // { dg-warning "'typedef' was ignored" }
+}; // { dg-warning "1:'typedef' was ignored" "" { target *-*-* } 3 }
 
 
 S f () {
Index: testsuite/g++.dg/parse/semicolon4.C
===================================================================
--- testsuite/g++.dg/parse/semicolon4.C	(revision 224061)
+++ testsuite/g++.dg/parse/semicolon4.C	(working copy)
@@ -22,7 +22,7 @@ struct OK3
 struct E1
 {
   int i;
-} const;			// { dg-error "qualifiers can only be specified for objects and functions" }
+} const;			// { dg-error "'const' can only be specified for objects and functions" }
 
 void foo (
 struct E2

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

* Re: [C++ Patch] Use declspecs->locations more
  2015-06-03 14:42 [C++ Patch] Use declspecs->locations more Paolo Carlini
@ 2015-06-03 16:30 ` Jason Merrill
  2015-06-04  9:16 ` Andreas Schwab
  1 sibling, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2015-06-03 16:30 UTC (permalink / raw)
  To: Paolo Carlini, gcc-patches

OK, thanks.

Jason

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

* Re: [C++ Patch] Use declspecs->locations more
  2015-06-03 14:42 [C++ Patch] Use declspecs->locations more Paolo Carlini
  2015-06-03 16:30 ` Jason Merrill
@ 2015-06-04  9:16 ` Andreas Schwab
  2015-06-04 14:00   ` Paolo CARLINI
  1 sibling, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2015-06-04  9:16 UTC (permalink / raw)
  To: Paolo Carlini; +Cc: gcc-patches, Jason Merrill

/opt/gcc/gcc-20150604/gcc/testsuite/obj-c++.dg/tls/diag-5.mm:4:1: error: '__thr\
ead' can only be specified for objects and functions^M

FAIL: obj-c++.dg/tls/diag-5.mm -fgnu-runtime  (test for errors, line 4)
FAIL: obj-c++.dg/tls/diag-5.mm -fgnu-runtime (test for excess errors)
Excess errors:
/opt/gcc/gcc-20150604/gcc/testsuite/obj-c++.dg/tls/diag-5.mm:4:1: error: '__thr\
ead' can only be specified for objects and functions

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: [C++ Patch] Use declspecs->locations more
  2015-06-04  9:16 ` Andreas Schwab
@ 2015-06-04 14:00   ` Paolo CARLINI
  0 siblings, 0 replies; 4+ messages in thread
From: Paolo CARLINI @ 2015-06-04 14:00 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: gcc-patches, Jason Merrill



Hi,

Il 04 giugno 2015 11:15:33 CEST, Andreas Schwab <schwab@linux-m68k.org> ha scritto:
>/opt/gcc/gcc-20150604/gcc/testsuite/obj-c++.dg/tls/diag-5.mm:4:1:
>error: '__thr\
>ead' can only be specified for objects and functions^M

Thanks Andreas. Looks like I missed a trivial testcase adjustment in the obj-c++ testsuite. I guess you can do the change as obvious, or just wait a few hours and I will (I'm traveling).

Thanks again,
Paolo

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

end of thread, other threads:[~2015-06-04 13:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-03 14:42 [C++ Patch] Use declspecs->locations more Paolo Carlini
2015-06-03 16:30 ` Jason Merrill
2015-06-04  9:16 ` Andreas Schwab
2015-06-04 14:00   ` Paolo CARLINI

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