From: Nathan Sidwell Date: Tue, 20 Mar 2018 15:57:30 +0000 (+0000) Subject: [PR c++/84970] lookup marking X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5770bbac66da20acd60a488430dff494db6606b4;p=gcc.git [PR c++/84970] lookup marking https://gcc.gnu.org/ml/gcc-patches/2018-03/msg00973.html PR c++/84970 * cp-tree.h (lookup_list_keep): Declare. * tree.c (lookup_list_keep): New, broken out of ... (build_min): ... here. Call it. * decl.c (cp_finish_decl): Call lookup_list_keep. PR c++/84970 * g++.dg/lookup/pr84970.C: New. From-SVN: r258685 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index fd7329f0622..7ce79d3862b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2018-03-20 Nathan Sidwell + + PR c++/84970 + * cp-tree.h (lookup_list_keep): Declare. + * tree.c (lookup_list_keep): New, broken out of ... + (build_min): ... here. Call it. + * decl.c (cp_finish_decl): Call lookup_list_keep. + 2018-03-19 Jason Merrill PR c++/84937 - ICE with class deduction and auto. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 727822e36da..077ef2d13f9 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7012,6 +7012,7 @@ extern tree lookup_add (tree fns, tree lookup); extern tree lookup_maybe_add (tree fns, tree lookup, bool deduping); extern void lookup_keep (tree lookup, bool keep); +extern void lookup_list_keep (tree list, bool keep); extern int is_overloaded_fn (tree) ATTRIBUTE_PURE; extern bool really_overloaded_fn (tree) ATTRIBUTE_PURE; extern tree dependent_name (tree); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 546468bf79f..5f181a5da72 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7034,7 +7034,11 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, } if (init) - DECL_INITIAL (decl) = init; + { + if (TREE_CODE (init) == TREE_LIST) + lookup_list_keep (init, true); + DECL_INITIAL (decl) = init; + } if (dep_init) { retrofit_lang_decl (decl); diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 90fbe183b97..5993633cbe5 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -2436,6 +2436,20 @@ lookup_keep (tree lookup, bool keep) ovl_used (lookup); } +/* LIST is a TREE_LIST whose TREE_VALUEs may be OVERLOADS that need + keeping, or may be ignored. */ + +void +lookup_list_keep (tree list, bool keep) +{ + for (; list; list = TREE_CHAIN (list)) + { + tree v = TREE_VALUE (list); + if (TREE_CODE (v) == OVERLOAD) + lookup_keep (v, keep); + } +} + /* Returns nonzero if X is an expression for a (possibly overloaded) function. If "f" is a function or function template, "f", "c->f", "c.f", "C::f", and "f" will all be considered possibly @@ -3315,9 +3329,7 @@ build_min (enum tree_code code, tree tt, ...) if (code == CAST_EXPR) /* The single operand is a TREE_LIST, which we have to check. */ - for (tree v = TREE_OPERAND (t, 0); v; v = TREE_CHAIN (v)) - if (TREE_CODE (TREE_VALUE (v)) == OVERLOAD) - lookup_keep (TREE_VALUE (v), true); + lookup_list_keep (TREE_OPERAND (t, 0), true); return t; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f88a09842fa..14c775ba191 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-03-20 Nathan Sidwell + + PR c++/84970 + * g++.dg/lookup/pr84970.C: New. + 2018-03-20 Richard Biener PR target/84986 diff --git a/gcc/testsuite/g++.dg/lookup/pr84970.C b/gcc/testsuite/g++.dg/lookup/pr84970.C new file mode 100644 index 00000000000..ad02248d75f --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/pr84970.C @@ -0,0 +1,21 @@ +// PR c++/84970 ICE with deferred initializer + +namespace bob { + void a(); +} +using namespace bob; + +void a (int); + +template +void *x (b) +{ + void (*c)(b) (a); + + return (void *)c; +} + +void d () { + x (1); +} +