From 4081596e852a3a1c2baaa5aa5bb539a8de1a78a3 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Fri, 6 Nov 2020 12:11:01 -0800 Subject: [PATCH] c++: Consistently expose singleton overloads This is a patch from my name-lookup overhaul. I noticed the parser and one path in name-lookup looked through an overload of a single known decl. It seems more consistent to do that in both paths through name-lookup, and not in the parser itself. gcc/cp/ * name-lookup.c (lookup_qualified_name): Expose an overload of a singleton with known type. (lookup_name_1): Just check the overload's type to expose it. * parser.c (cp_parser_lookup_name): Do not do that check here. --- gcc/cp/name-lookup.c | 14 +++++++++++--- gcc/cp/parser.c | 5 ----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 5bda4c2eea9..16efd161301 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -5885,7 +5885,14 @@ lookup_qualified_name (tree scope, tree name, LOOK_want want, bool complain) name_lookup lookup (name, want); if (qualified_namespace_lookup (scope, &lookup)) - t = lookup.value; + { + t = lookup.value; + + /* If we have a known type overload, pull it out. This can happen + for using decls. */ + if (TREE_CODE (t) == OVERLOAD && TREE_TYPE (t) != unknown_type_node) + t = OVL_FUNCTION (t); + } } else if (cxx_dialect != cxx98 && TREE_CODE (scope) == ENUMERAL_TYPE) t = lookup_enumerator (scope, name); @@ -6515,8 +6522,9 @@ lookup_name_1 (tree name, LOOK_where where, LOOK_want want) found:; - /* If we have a single function from a using decl, pull it out. */ - if (val && TREE_CODE (val) == OVERLOAD && !really_overloaded_fn (val)) + /* If we have a known type overload, pull it out. This can happen + for both using decls and unhidden functions. */ + if (val && TREE_CODE (val) == OVERLOAD && TREE_TYPE (val) != unknown_type_node) val = OVL_FUNCTION (val); return val; diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 323d7424a83..bbf157eb47f 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -28633,11 +28633,6 @@ cp_parser_lookup_name (cp_parser *parser, tree name, prefer_type_arg (tag_type), /*complain=*/true); - /* If we have a single function from a using decl, pull it out. */ - if (TREE_CODE (decl) == OVERLOAD - && !really_overloaded_fn (decl)) - decl = OVL_FUNCTION (decl); - if (pushed_scope) pop_scope (pushed_scope); } -- 2.30.2