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>
Subject: [C++ Patch] A few additional location improvements to grokdeclarator and check_tag_decl
Date: Sun, 23 Jun 2019 11:58:00 -0000	[thread overview]
Message-ID: <75c69855-965c-6c03-fe95-905af5d15cc0@oracle.com> (raw)

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

Hi,

here there are a couple of rather straightforward improvements in the 
second half of grokdeclarator plus a check_tag_decl change consistent 
with the other existing case of multiple_types_p diagnostic. Tested 
x86_64-linux.

Thanks, Paolo.

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


[-- Attachment #2: CL_locs_37_2 --]
[-- Type: text/plain, Size: 648 bytes --]

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

	* decl.c (get_type_quals): New.
	(check_tag_decl): Use smallest_type_location and the latter in
	error_at about multiple types in one declaration.
	(grokdeclarator): Use locations[ds_storage_class] in error_at
	about static cdtor; use id_loc in error_at about flexible
	array member in union; use get_type_quals.

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

	* g++.dg/diagnostic/static-cdtor-1.C: New.
	* g++.dg/cpp1z/has-unique-obj-representations2.C: Test location
	too.
	* g++.dg/other/anon-union3.C: Adjust expected location.
	* g++.dg/parse/error8.C: Likewise.

[-- Attachment #3: patch_locs_37_2 --]
[-- Type: text/plain, Size: 6111 bytes --]

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 272584)
+++ cp/decl.c	(working copy)
@@ -100,6 +100,7 @@ static tree build_cp_library_fn (tree, enum tree_c
 static void store_parm_decls (tree);
 static void initialize_local_var (tree, tree);
 static void expand_static_init (tree, tree);
+static location_t smallest_type_location (int, const location_t*);
 
 /* The following symbols are subsumed in the cp_global_trees array, and
    listed here individually for documentation purposes.
@@ -4802,6 +4803,24 @@ warn_misplaced_attr_for_class_type (location_t loc
 	    class_type, class_key_or_enum_as_string (class_type));
 }
 
+/* Returns the cv-qualifiers that apply to the type specified
+   by the DECLSPECS.  */
+
+static int
+get_type_quals (const cp_decl_specifier_seq *declspecs)
+{
+  int type_quals = TYPE_UNQUALIFIED;
+
+  if (decl_spec_seq_has_spec_p (declspecs, ds_const))
+    type_quals |= TYPE_QUAL_CONST;
+  if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
+    type_quals |= TYPE_QUAL_VOLATILE;
+  if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
+    type_quals |= TYPE_QUAL_RESTRICT;
+
+  return type_quals;
+}
+
 /* Make sure that a declaration with no declarator is well-formed, i.e.
    just declares a tagged type or anonymous union.
 
@@ -4821,7 +4840,9 @@ check_tag_decl (cp_decl_specifier_seq *declspecs,
   bool error_p = false;
 
   if (declspecs->multiple_types_p)
-    error ("multiple types in one declaration");
+    error_at (smallest_type_location (get_type_quals (declspecs),
+				      declspecs->locations),
+	      "multiple types in one declaration");
   else if (declspecs->redefined_builtin_type)
     {
       if (!in_system_header_at (input_location))
@@ -10403,7 +10424,7 @@ grokdeclarator (const cp_declarator *declarator,
      a member function.  */
   cp_ref_qualifier rqual = REF_QUAL_NONE;
   /* cv-qualifiers that apply to the type specified by the DECLSPECS.  */
-  int type_quals = TYPE_UNQUALIFIED;
+  int type_quals = get_type_quals (declspecs);
   tree raises = NULL_TREE;
   int template_count = 0;
   tree returned_attrs = NULL_TREE;
@@ -10449,13 +10470,6 @@ grokdeclarator (const cp_declarator *declarator,
   if (concept_p)
     constexpr_p = true;
 
-  if (decl_spec_seq_has_spec_p (declspecs, ds_const))
-    type_quals |= TYPE_QUAL_CONST;
-  if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
-    type_quals |= TYPE_QUAL_VOLATILE;
-  if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
-    type_quals |= TYPE_QUAL_RESTRICT;
-
   if (decl_context == FUNCDEF)
     funcdef_flag = true, decl_context = NORMAL;
   else if (decl_context == MEMFUNCDEF)
@@ -11571,9 +11585,12 @@ grokdeclarator (const cp_declarator *declarator,
 		   virtual.  A constructor may not be static.
 		   A constructor may not be declared with ref-qualifier. */
 		if (staticp == 2)
-		  error ((flags == DTOR_FLAG)
-			 ? G_("destructor cannot be static member function")
-			 : G_("constructor cannot be static member function"));
+		  error_at (declspecs->locations[ds_storage_class],
+			    (flags == DTOR_FLAG)
+			    ? G_("destructor cannot be static member "
+				 "function")
+			    : G_("constructor cannot be static member "
+				 "function"));
 		if (memfn_quals)
 		  {
 		    error ((flags == DTOR_FLAG)
@@ -12431,7 +12448,7 @@ grokdeclarator (const cp_declarator *declarator,
 		&& (TREE_CODE (ctype) == UNION_TYPE
 		    || TREE_CODE (ctype) == QUAL_UNION_TYPE))
 	      {
-		error ("flexible array member in union");
+		error_at (id_loc, "flexible array member in union");
 		type = error_mark_node;
 	      }
 	    else
Index: testsuite/g++.dg/cpp1z/has-unique-obj-representations2.C
===================================================================
--- testsuite/g++.dg/cpp1z/has-unique-obj-representations2.C	(revision 272583)
+++ testsuite/g++.dg/cpp1z/has-unique-obj-representations2.C	(working copy)
@@ -1,7 +1,7 @@
 struct S;
 struct T { S t; };					// { dg-error "incomplete type" }
 struct U { int u[sizeof (S)]; };			// { dg-error "incomplete type" }
-union V { char c; char d[]; };				// { dg-error "flexible array member in union" }
+union V { char c; char d[]; };				// { dg-error "24:flexible array member in union" }
 bool a = __has_unique_object_representations (S);	// { dg-error "incomplete type" }
 bool b = __has_unique_object_representations (T);
 bool c = __has_unique_object_representations (U);
Index: testsuite/g++.dg/diagnostic/static-cdtor-1.C
===================================================================
--- testsuite/g++.dg/diagnostic/static-cdtor-1.C	(nonexistent)
+++ testsuite/g++.dg/diagnostic/static-cdtor-1.C	(working copy)
@@ -0,0 +1,5 @@
+struct S
+{
+  static S();  // { dg-error "3:constructor" }
+  static ~S();  // { dg-error "3:destructor" }
+};
Index: testsuite/g++.dg/other/anon-union3.C
===================================================================
--- testsuite/g++.dg/other/anon-union3.C	(revision 272583)
+++ testsuite/g++.dg/other/anon-union3.C	(working copy)
@@ -3,9 +3,9 @@
 class C
 {
   auto union      // { dg-error "storage class" "" { target { ! c++11 } } }
-    {		  // { dg-error "auto" "" { target c++11 } .-1 }
+    {		  // { dg-error "auto|multiple types" "" { target c++11 } .-1 }
       int a;
-    };            // { dg-error "multiple types" "" { target c++11 } }
+    };
   register union  // { dg-error "storage class" }
     {
       int b;
Index: testsuite/g++.dg/parse/error8.C
===================================================================
--- testsuite/g++.dg/parse/error8.C	(revision 272583)
+++ testsuite/g++.dg/parse/error8.C	(working copy)
@@ -5,5 +5,5 @@ struct A { friend typename struct B; };
 
 
 // { dg-error "28:expected nested-name-specifier before 'struct'" "expected" { target *-*-* } 4 }
-// { dg-error "35:multiple types in one declaration" "multiple" { target *-*-* } 4 }
+// { dg-error "19:multiple types in one declaration" "multiple" { target *-*-* } 4 }
 // { dg-error "12:friend declaration does not name a class or function" "friend decl" { target *-*-* } 4 }

             reply	other threads:[~2019-06-23 11:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-23 11:58 Paolo Carlini [this message]
2019-07-05 19:48 ` [C++ Patch PING] " Paolo Carlini
2019-07-08 21:56 ` Jason Merrill
2019-07-09 10:17   ` Paolo Carlini
2019-07-09 21:14     ` 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=75c69855-965c-6c03-fe95-905af5d15cc0@oracle.com \
    --to=paolo.carlini@oracle.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).