2017-05-18 Nathan Sidwell * cp-tree.h (OVL_ARG_DEPENDENT): Delete. (OVL_USED_P): New. (lookup_keep): Declare. * name-lookup.c (add_function): Don't set OVL_ARG_DEPENDENT. * pt.c (tsubst_copy): Assert lookup is persistent. * semantics.c (finish_call_expr): Use lkp_iterator, call lookup_keep. * tree.c (ovl_copy): New. (ovl_insert, ovl_iterator::remove_node): Copy immutable nodes. (lookup_keep): New. Index: cp-tree.h =================================================================== --- cp-tree.h (revision 248229) +++ cp-tree.h (working copy) @@ -323,7 +323,6 @@ extern GTY(()) tree cp_global_trees[CPTI IMPLICIT_CONV_EXPR_DIRECT_INIT (in IMPLICIT_CONV_EXPR) TRANSACTION_EXPR_IS_STMT (in TRANSACTION_EXPR) CONVERT_EXPR_VBASE_PATH (in CONVERT_EXPR) - OVL_ARG_DEPENDENT (in OVERLOAD) PACK_EXPANSION_LOCAL_P (in *_PACK_EXPANSION) TINFO_HAS_ACCESS_ERRORS (in TEMPLATE_INFO) SIZEOF_EXPR_TYPE_P (in SIZEOF_EXPR) @@ -641,9 +640,6 @@ typedef struct ptrmem_cst * ptrmem_cst_t ((TREE_CODE (NODE) == OVERLOAD) ? OVL_FUNCTION (NODE) : (NODE)) #define OVL_NEXT(NODE) \ ((TREE_CODE (NODE) == OVERLOAD) ? TREE_CHAIN (NODE) : NULL_TREE) -/* If set, this OVERLOAD was created for argument-dependent lookup - and can be freed afterward. */ -#define OVL_ARG_DEPENDENT(NODE) TREE_LANG_FLAG_0 (OVERLOAD_CHECK (NODE)) /* If set, this was imported in a using declaration. */ #define OVL_USING_P(NODE) TREE_LANG_FLAG_1 (OVERLOAD_CHECK (NODE)) @@ -651,6 +647,8 @@ typedef struct ptrmem_cst * ptrmem_cst_t #define OVL_NESTED_P(NODE) TREE_LANG_FLAG_3 (OVERLOAD_CHECK (NODE)) /* If set, this overload was constructed during lookup. */ #define OVL_LOOKUP_P(NODE) TREE_LANG_FLAG_4 (OVERLOAD_CHECK (NODE)) +/* If set, this is a persistant lookup. */ +#define OVL_USED_P(NODE) TREE_USED (OVERLOAD_CHECK (NODE)) /* The first decl of an overload. */ #define OVL_FIRST(NODE) ovl_first (NODE) @@ -6809,6 +6807,7 @@ extern tree ovl_make (tree fn, extern tree ovl_insert (tree fn, tree maybe_ovl, bool using_p = false); extern tree lookup_add (tree fns, tree lookup); +extern void lookup_keep (tree lookup, bool keep); extern int is_overloaded_fn (tree); extern tree dependent_name (tree); extern tree get_fns (tree) ATTRIBUTE_PURE; Index: name-lookup.c =================================================================== --- name-lookup.c (revision 248229) +++ name-lookup.c (working copy) @@ -159,11 +159,7 @@ add_function (struct arg_lookup *k, tree else if (fn == k->functions) ; else - { - k->functions = lookup_add (fn, k->functions); - if (TREE_CODE (k->functions) == OVERLOAD) - OVL_ARG_DEPENDENT (k->functions) = true; - } + k->functions = lookup_add (fn, k->functions); return false; } Index: pt.c =================================================================== --- pt.c (revision 248198) +++ pt.c (working copy) @@ -14565,6 +14565,8 @@ tsubst_copy (tree t, tree args, tsubst_f overload set from function scope will just be represented with an IDENTIFIER_NODE, and from class scope with a BASELINK. */ gcc_assert (!uses_template_parms (t)); + /* We must have marked any lookups as persistent. */ + gcc_assert (!OVL_LOOKUP_P (t) || OVL_USED_P (t)); return t; case BASELINK: Index: semantics.c =================================================================== --- semantics.c (revision 248166) +++ semantics.c (working copy) @@ -2304,18 +2304,28 @@ finish_call_expr (tree fn, vecf", "c.f", "C::f", and "f" will all be considered possibly