public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] constructor_name
@ 2017-06-29 14:43 Nathan Sidwell
  2017-06-29 20:56 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Nathan Sidwell @ 2017-06-29 14:43 UTC (permalink / raw)
  To: GCC Patches

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

This cleans up constructor_name use.  I use constructor_name when 
checking for ctor/dtor type things and DECL_NAME (TYPE_NAME (X)) when 
dealing with a class's self reference.  IMHO these are conceptually 
different, even if we might end up with the same identifier in the end.

1) check_dtor_name can use constructor_name for enums too.

2) build_new_method_call_1 should do so for cdtors, and also print a ~ 
for the destructor use[*]

3) build_self_reference and push_clas_level_binding_1 should use 
DECL_NAME ...

4) constructor_name can grab DECL_NAME (TYPE_NAME (X)) to get the name. 
And constructor_name_p doesn't need to be so complex

applied to trunk.

[*] perhaps `&"~"[!twiddle]' is too cute a trick?

nathan
-- 
Nathan Sidwell

[-- Attachment #2: cname.diff --]
[-- Type: text/x-patch, Size: 4185 bytes --]

2017-06-29  Nathan Sidwell  <nathan@acm.org>

	* call.c (check_dtor_name): Use constructor_name for enums too.
	(build_new_method_call_1): Use constructor_name for cdtors and
	show ~ for dtor.
	* class.c (build_self_reference): Use TYPE_NAME to get name of
	self reference.
	* name-lookup (constructor_name): Use DECL_NAME directly.
	(constructor_name_p): Reimplement.
	(push_class_level_binding_1): Use TYPE_NAME directly.

Index: call.c
===================================================================
--- call.c	(revision 249786)
+++ call.c	(working copy)
@@ -231,9 +231,8 @@ check_dtor_name (tree basetype, tree nam
   else if (identifier_p (name))
     {
       if ((MAYBE_CLASS_TYPE_P (basetype)
-	   && name == constructor_name (basetype))
-	  || (TREE_CODE (basetype) == ENUMERAL_TYPE
-	      && name == TYPE_IDENTIFIER (basetype)))
+	   || TREE_CODE (basetype) == ENUMERAL_TYPE)
+	  && name == constructor_name (basetype))
 	return true;
       else
 	name = get_type_value (name);
@@ -9139,17 +9138,18 @@ build_new_method_call_1 (tree instance,
 	    {
 	      tree arglist = build_tree_list_vec (user_args);
 	      tree errname = name;
+	      bool twiddle = false;
 	      if (IDENTIFIER_CDTOR_P (errname))
 		{
-		  tree fn = DECL_ORIGIN (OVL_FIRST (fns));
-		  errname = DECL_NAME (fn);
+		  twiddle = IDENTIFIER_DTOR_P (errname);
+		  errname = constructor_name (basetype);
 		}
 	      if (explicit_targs)
 		errname = lookup_template_function (errname, explicit_targs);
 	      if (skip_first_for_error)
 		arglist = TREE_CHAIN (arglist);
-	      error ("no matching function for call to %<%T::%E(%A)%#V%>",
-		     basetype, errname, arglist,
+	      error ("no matching function for call to %<%T::%s%E(%A)%#V%>",
+		     basetype, &"~"[!twiddle], errname, arglist,
 		     TREE_TYPE (instance));
 	    }
 	  print_z_candidates (location_of (name), candidates);
Index: class.c
===================================================================
--- class.c	(revision 249788)
+++ class.c	(working copy)
@@ -8550,9 +8550,8 @@ print_class_statistics (void)
 void
 build_self_reference (void)
 {
-  tree name = constructor_name (current_class_type);
+  tree name = DECL_NAME (TYPE_NAME (current_class_type));
   tree value = build_lang_decl (TYPE_DECL, name, current_class_type);
-  tree saved_cas;
 
   DECL_NONLOCAL (value) = 1;
   DECL_CONTEXT (value) = current_class_type;
@@ -8563,7 +8562,7 @@ build_self_reference (void)
   if (processing_template_decl)
     value = push_template_decl (value);
 
-  saved_cas = current_access_specifier;
+  tree saved_cas = current_access_specifier;
   current_access_specifier = access_public_node;
   finish_member_declaration (value);
   current_access_specifier = saved_cas;
Index: name-lookup.c
===================================================================
--- name-lookup.c	(revision 249779)
+++ name-lookup.c	(working copy)
@@ -3188,7 +3188,9 @@ set_identifier_type_value (tree id, tree
 tree
 constructor_name (tree type)
 {
-  return TYPE_IDENTIFIER (TYPE_MAIN_VARIANT (type));
+  tree decl = TYPE_NAME (TYPE_MAIN_VARIANT (type));
+
+  return decl ? DECL_NAME (decl) : NULL_TREE;
 }
 
 /* Returns TRUE if NAME is the name for the constructor for TYPE,
@@ -3199,19 +3201,12 @@ constructor_name_p (tree name, tree type
 {
   gcc_assert (MAYBE_CLASS_TYPE_P (type));
 
-  if (!name)
-    return false;
-
-  if (!identifier_p (name))
-    return false;
-
   /* These don't have names.  */
   if (TREE_CODE (type) == DECLTYPE_TYPE
       || TREE_CODE (type) == TYPEOF_TYPE)
     return false;
 
-  tree ctor_name = constructor_name (type);
-  if (name == ctor_name)
+  if (name && name == constructor_name (type))
     return true;
 
   return false;
@@ -3962,7 +3957,7 @@ push_class_level_binding_1 (tree name, t
        /* A data member of an anonymous union.  */
        || (TREE_CODE (x) == FIELD_DECL
 	   && DECL_CONTEXT (x) != current_class_type))
-      && DECL_NAME (x) == constructor_name (current_class_type))
+      && DECL_NAME (x) == DECL_NAME (TYPE_NAME (current_class_type)))
     {
       tree scope = context_for_name_lookup (x);
       if (TYPE_P (scope) && same_type_p (scope, current_class_type))

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

* Re: [C++ PATCH] constructor_name
  2017-06-29 14:43 [C++ PATCH] constructor_name Nathan Sidwell
@ 2017-06-29 20:56 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2017-06-29 20:56 UTC (permalink / raw)
  To: Nathan Sidwell; +Cc: GCC Patches

On Thu, Jun 29, 2017 at 10:43 AM, Nathan Sidwell <nathan@acm.org> wrote:
> [*] perhaps `&"~"[!twiddle]' is too cute a trick?

It's very localized, so I think it's appropriately cute.

Jason

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

end of thread, other threads:[~2017-06-29 20:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-29 14:43 [C++ PATCH] constructor_name Nathan Sidwell
2017-06-29 20:56 ` 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).