public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] some cleanups
@ 2018-04-27 12:52 Nathan Sidwell
  0 siblings, 0 replies; 2+ messages in thread
From: Nathan Sidwell @ 2018-04-27 12:52 UTC (permalink / raw)
  To: GCC Patches

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

A few cleanups from the modules branch.

* The TEMPLATE_INFO comments still described TREE_LIST contents.
* we didn't check we were looking at a TEMPLATE_INFO in one case
* we declared some (now?) non-existent dump functions
* we made a name-lookup internal dumping function extern
* we made a template (now?) internal creator function extern

committing to trunk.

nathan
-- 
Nathan Sidwell

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

2018-04-27  Nathan Sidwell  <nathan@acm.org>

	* cp-tree.h (TEMPLATE_INFO): Fix comments.
	(TI_PENDING_TEMPLATE_FLAG): Check TEMPLATE_INFO.
	(NON_DEFAULT_TEMPLATE_ARG_COUNT): Wrap line.
	(dump, print_other_binding_stacks): Remove declarations.
	* name-lookup.c (print_other_binding_stack): Make static.
	* pt.c (build_template_decl): Make static.

Index: cp-tree.h
===================================================================
--- cp-tree.h	(revision 259683)
+++ cp-tree.h	(working copy)
@@ -3273,11 +3273,11 @@ extern void decl_shadowed_for_var_insert
    DECL_USE_TEMPLATE is nonzero) or the abstract instance of the
    template itself.
 
-   In either case, DECL_TEMPLATE_INFO is a TREE_LIST, whose
-   TREE_PURPOSE is the TEMPLATE_DECL of which this entity is a
-   specialization or abstract instance.  The TREE_VALUE is the
+   In either case, DECL_TEMPLATE_INFO is a TEMPLATE_INFO, whose
+   TI_TEMPLATE is the TEMPLATE_DECL of which this entity is a
+   specialization or abstract instance.  The TI_ARGS is the
    template arguments used to specialize the template.
-   
+
    Consider:
 
       template <typename T> struct S { friend void f(T) {} };
@@ -3344,11 +3344,14 @@ extern void decl_shadowed_for_var_insert
 
 #define TI_TEMPLATE(NODE) TREE_TYPE (TEMPLATE_INFO_CHECK (NODE))
 #define TI_ARGS(NODE) TREE_CHAIN (TEMPLATE_INFO_CHECK (NODE))
-#define TI_PENDING_TEMPLATE_FLAG(NODE) TREE_LANG_FLAG_1 (NODE)
+#define TI_PENDING_TEMPLATE_FLAG(NODE) \
+  TREE_LANG_FLAG_1 (TEMPLATE_INFO_CHECK (NODE))
 /* For a given TREE_VEC containing a template argument list,
    this property contains the number of arguments that are not
    defaulted.  */
-#define NON_DEFAULT_TEMPLATE_ARGS_COUNT(NODE) TREE_CHAIN (TREE_VEC_CHECK (NODE))
+#define NON_DEFAULT_TEMPLATE_ARGS_COUNT(NODE) \
+  TREE_CHAIN (TREE_VEC_CHECK (NODE))
+
 /* Below are the setter and getter of the NON_DEFAULT_TEMPLATE_ARGS_COUNT
    property.  */
 #define SET_NON_DEFAULT_TEMPLATE_ARGS_COUNT(NODE, INT_VALUE) \
@@ -6229,9 +6232,6 @@ extern tree strip_fnptr_conv			(tree);
 extern void maybe_push_cleanup_level		(tree);
 extern tree make_anon_name			(void);
 extern tree check_for_out_of_scope_variable	(tree);
-extern void dump				(cp_binding_level &ref);
-extern void dump				(cp_binding_level *ptr);
-extern void print_other_binding_stack		(cp_binding_level *);
 extern tree maybe_push_decl			(tree);
 extern tree current_decl_namespace		(void);
 
Index: name-lookup.c
===================================================================
--- name-lookup.c	(revision 259683)
+++ name-lookup.c	(working copy)
@@ -3742,7 +3742,7 @@ debug (cp_binding_level *ptr)
 }
 
 
-void
+static void
 print_other_binding_stack (cp_binding_level *stack)
 {
   cp_binding_level *level;
Index: pt.c
===================================================================
--- pt.c	(revision 259683)
+++ pt.c	(working copy)
@@ -4674,7 +4674,7 @@ maybe_update_decl_type (tree orig_type,
    template PARMS and constraints, CONSTR.  If MEMBER_TEMPLATE_P is true,
    the new  template is a member template. */
 
-tree
+static tree
 build_template_decl (tree decl, tree parms, bool member_template_p)
 {
   tree tmpl = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), NULL_TREE);

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

* [C++ PATCH] some cleanups
@ 2019-04-29 15:54 Nathan Sidwell
  0 siblings, 0 replies; 2+ messages in thread
From: Nathan Sidwell @ 2019-04-29 15:54 UTC (permalink / raw)
  To: GCC Patches

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

This patch fixes some formatting and code clarity issues I've tripped 
over in the past few months.

duplicate_decls has some function- and var- specific behaviour that was 
confusingly commented, and, for the var case mixed the checking for var 
with checking for the flag to copy.

process_outer_var_ref had some unnecessary line-breaks and block scopes.

explain_implicit_non_constexpr had some unnecessary repetitiveness.

Applying to trunk.

nathan

-- 
Nathan Sidwell

[-- Attachment #2: s1-1.diff --]
[-- Type: text/x-patch, Size: 6118 bytes --]

2019-04-29  Nathan Sidwell  <nathan@acm.org>

	* decl.c (duplicate_decls): Add whitespace, move comments into
	conditional blocks.
	* method.c (explain_implicit_non_constexpr): Refactor.
	* pt.c (check_explicit_specialization): Fix indentation.
	* semantics.c (process_outer_var_ref): Reformat.
	(finish_id_expression_1): Use STRIP_TEMPLATE.

Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 270651)
+++ gcc/cp/decl.c	(working copy)
@@ -1,4 +1,4 @@
-/* Process declarations and variables for C++ compiler.
+/* Process declarations and variables for -*- C++ -*- compiler.
    Copyright (C) 1988-2019 Free Software Foundation, Inc.
    Contributed by Michael Tiemann (tiemann@cygnus.com)
 
@@ -1476,7 +1476,7 @@ duplicate_decls (tree newdecl, tree oldd
 
 		  if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
 		    break;
-next_arg:;
+		next_arg:;
 		}
 
 	      warning_at (newdecl_loc,
@@ -2386,9 +2386,10 @@ next_arg:;
 	    }
 	  DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
 	}
-      /* Only functions have these fields.  */
+
       if (DECL_DECLARES_FUNCTION_P (newdecl))
 	{
+	  /* Only functions have these fields.  */
 	  DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
 	  DECL_BEFRIENDING_CLASSES (newdecl)
 	    = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
@@ -2398,10 +2399,12 @@ next_arg:;
 	  if (DECL_VIRTUAL_P (newdecl))
 	    SET_DECL_THUNKS (newdecl, DECL_THUNKS (olddecl));
 	}
-      /* Only variables have this field.  */
-      else if (VAR_P (newdecl)
-	       && VAR_HAD_UNKNOWN_BOUND (olddecl))
-	SET_VAR_HAD_UNKNOWN_BOUND (newdecl);
+      else if (VAR_P (newdecl))
+	{
+	  /* Only variables have this field.  */
+	  if (VAR_HAD_UNKNOWN_BOUND (olddecl))
+	    SET_VAR_HAD_UNKNOWN_BOUND (newdecl);
+	}
     }
 
   if (TREE_CODE (newdecl) == FUNCTION_DECL)
Index: gcc/cp/method.c
===================================================================
--- gcc/cp/method.c	(revision 270651)
+++ gcc/cp/method.c	(working copy)
@@ -1884,15 +1884,14 @@ maybe_explain_implicit_delete (tree decl
 void
 explain_implicit_non_constexpr (tree decl)
 {
-  tree parm_type = TREE_VALUE (FUNCTION_FIRST_USER_PARMTYPE (decl));
-  bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
+  tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
+  bool const_p = CP_TYPE_CONST_P (non_reference (TREE_VALUE (parms)));
   tree inh = DECL_INHERITED_CTOR (decl);
   bool dummy;
   synthesized_method_walk (DECL_CLASS_CONTEXT (decl),
 			   special_function_p (decl), const_p,
 			   NULL, NULL, NULL, &dummy, true,
-			   &inh,
-			   FUNCTION_FIRST_USER_PARMTYPE (decl));
+			   &inh, parms);
 }
 
 /* DECL is an instantiation of an inheriting constructor template.  Deduce
Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c	(revision 270651)
+++ gcc/cp/pt.c	(working copy)
@@ -3026,7 +3026,7 @@ check_explicit_specialization (tree decl
 	     `operator T'.  Grab all the conversion operators, and
 	     then select from them.  */
 	  tree fns = get_class_binding (ctype, IDENTIFIER_CONV_OP_P (name)
-				      ? conv_op_identifier : name);
+					? conv_op_identifier : name);
 
 	  if (fns == NULL_TREE)
 	    {
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 270651)
+++ gcc/cp/semantics.c	(working copy)
@@ -3482,16 +3482,12 @@ process_outer_var_ref (tree decl, tsubst
 	/* A lambda in an NSDMI (c++/64496).  */
 	break;
 
-      if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr)
-	  == CPLD_NONE)
+      if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
 	break;
 
-      lambda_stack = tree_cons (NULL_TREE,
-				lambda_expr,
-				lambda_stack);
+      lambda_stack = tree_cons (NULL_TREE, lambda_expr, lambda_stack);
 
-      containing_function
-	= decl_function_context (containing_function);
+      containing_function = decl_function_context (containing_function);
     }
 
   /* In a lambda within a template, wait until instantiation time to implicitly
@@ -3502,8 +3498,7 @@ process_outer_var_ref (tree decl, tsubst
       && DECL_PACK_P (decl))
     return decl;
 
-  if (lambda_expr && VAR_P (decl)
-      && DECL_ANON_UNION_VAR_P (decl))
+  if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl))
     {
       if (complain & tf_error)
 	error ("cannot capture member %qD of anonymous union", decl);
@@ -3512,11 +3507,8 @@ process_outer_var_ref (tree decl, tsubst
   /* Do lambda capture when processing the id-expression, not when
      odr-using a variable.  */
   if (!odr_use && context == containing_function)
-    {
-      decl = add_default_capture (lambda_stack,
-				  /*id=*/DECL_NAME (decl),
-				  initializer);
-    }
+    decl = add_default_capture (lambda_stack,
+				/*id=*/DECL_NAME (decl), initializer);
   /* Only an odr-use of an outer automatic variable causes an
      error, and a constant variable can decay to a prvalue
      constant without odr-use.  So don't complain yet.  */
@@ -3528,8 +3520,7 @@ process_outer_var_ref (tree decl, tsubst
 	{
 	  error ("%qD is not captured", decl);
 	  tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr);
-	  if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr)
-	      == CPLD_NONE)
+	  if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr) == CPLD_NONE)
 	    inform (location_of (closure),
 		    "the lambda has no capture-default");
 	  else if (TYPE_CLASS_SCOPE_P (closure))
@@ -3844,10 +3835,11 @@ finish_id_expression_1 (tree id_expressi
 	}
       else if (is_overloaded_fn (decl))
 	{
+	  /* We only need to look at the first function,
+	     because all the fns share the attribute we're
+	     concerned with (all member fns or all non-members).  */
 	  tree first_fn = get_first_fn (decl);
-
-	  if (TREE_CODE (first_fn) == TEMPLATE_DECL)
-	    first_fn = DECL_TEMPLATE_RESULT (first_fn);
+	  first_fn = STRIP_TEMPLATE (first_fn);
 
 	  /* [basic.def.odr]: "A function whose name appears as a
 	     potentially-evaluated expression is odr-used if it is the unique

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

end of thread, other threads:[~2019-04-29 15:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-27 12:52 [C++ PATCH] some cleanups Nathan Sidwell
2019-04-29 15:54 Nathan Sidwell

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