From b1fe8605a12deddd1c5998ee6a78f1d17d507980 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Fri, 16 Nov 2018 15:01:55 +0000 Subject: [PATCH] [PR c++/87269] Mark string operator overload in template defn. https://gcc.gnu.org/ml/gcc-patches/2018-11/msg01458.html PR c++/87269 * parser.c (lookup_literal_operator): Mark overload for keeping when inside template. Refactor. * g++.dg/lookup/pr87269.C: New. From-SVN: r266210 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/parser.c | 22 ++++++++++++++-------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/lookup/pr87269.C | 15 +++++++++++++++ 4 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.dg/lookup/pr87269.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index deec822b924..6b167f33e06 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-11-16 Nathan Sidwell + + PR c++/87269 + * parser.c (lookup_literal_operator): Mark overload for keeping + when inside template. Refactor. + 2018-11-15 Nathan Sidwell PR c++/86246 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 8833e3db746..99bd4dc08fb 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -4259,20 +4259,21 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok, static tree lookup_literal_operator (tree name, vec *args) { - tree decl; - decl = lookup_name (name); + tree decl = lookup_name (name); if (!decl || !is_overloaded_fn (decl)) return error_mark_node; for (lkp_iterator iter (decl); iter; ++iter) { - unsigned int ix; - bool found = true; tree fn = *iter; - tree parmtypes = TYPE_ARG_TYPES (TREE_TYPE (fn)); - if (parmtypes != NULL_TREE) + + if (tree parmtypes = TYPE_ARG_TYPES (TREE_TYPE (fn))) { - for (ix = 0; ix < vec_safe_length (args) && parmtypes != NULL_TREE; + unsigned int ix; + bool found = true; + + for (ix = 0; + found && ix < vec_safe_length (args) && parmtypes != NULL_TREE; ++ix, parmtypes = TREE_CHAIN (parmtypes)) { tree tparm = TREE_VALUE (parmtypes); @@ -4285,6 +4286,7 @@ lookup_literal_operator (tree name, vec *args) TREE_TYPE (targ)))) found = false; } + if (found && ix == vec_safe_length (args) /* May be this should be sufficient_parms_p instead, @@ -4292,7 +4294,11 @@ lookup_literal_operator (tree name, vec *args) work in presence of default arguments on the literal operator parameters. */ && parmtypes == void_list_node) - return decl; + { + if (processing_template_decl) + lookup_keep (decl); + return decl; + } } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index abddcdf2e6d..b1b6ae4bc87 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-11-16 Nathan Sidwell + + PR c++/87269 + * g++.dg/lookup/pr87269.C: New. + 2018-11-16 Richard Biener PR testsuite/88053 diff --git a/gcc/testsuite/g++.dg/lookup/pr87269.C b/gcc/testsuite/g++.dg/lookup/pr87269.C new file mode 100644 index 00000000000..b0ceda23878 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/pr87269.C @@ -0,0 +1,15 @@ +// { dg-do compile { target c++11 } } +// PR c++/87269 ICE failing to keep a lookup + +namespace { + void operator"" _a (const char *, unsigned long) {} +} + +void operator"" _a (unsigned long long); + +template void f () { ""_a; } + +void frob () +{ + f (); +} -- 2.30.2