From: Jason Merrill Date: Wed, 7 Apr 2021 18:55:48 +0000 (-0400) Subject: c++: using overloaded with local decl [PR92918] X-Git-Tag: basepoints/gcc-12~224 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a528594cf9a74e5a0fbac13ef673064ed73e1b89;p=thirdparty%2Fgcc.git c++: using overloaded with local decl [PR92918] The problem here was that the lookup for 'impl' when parsing the template only found the using-declaration, not the member function declaration. This happened because when trying to add the member function declaration, push_class_level_binding_1 saw that the current binding was a USING_DECL and the new value is an overload, and decided to just return success. That 'return true' dates back to r69921. In https://gcc.gnu.org/pipermail/gcc-patches/2003-July/110632.html Nathan mentions that we only push dependent USING_DECLs, which is no longer the case; now that we retain more USING_DECLs, handling this case like the other overloaded function cases seems like the obvious solution. gcc/cp/ChangeLog: PR c++/92918 * name-lookup.c (push_class_level_binding_1): Do overload a new function with a previous using-declaration. gcc/testsuite/ChangeLog: PR c++/92918 * g++.dg/lookup/using66.C: New test. --- diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 3bce3d597dcf..4e84e2f99874 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -5520,7 +5520,7 @@ push_class_level_binding_1 (tree name, tree x) old_decl = bval; else if (TREE_CODE (bval) == USING_DECL && OVL_P (target_decl)) - return true; + old_decl = bval; else if (OVL_P (target_decl) && OVL_P (target_bval)) old_decl = bval; diff --git a/gcc/testsuite/g++.dg/lookup/using66.C b/gcc/testsuite/g++.dg/lookup/using66.C new file mode 100644 index 000000000000..02383bbea3e0 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using66.C @@ -0,0 +1,23 @@ +// PR c++/92918 +// { dg-do compile { target c++11 } } + +struct Base03 +{ + static void impl(); +}; + +struct Problem : Base03 +{ + using Base03::impl; + static int impl(char const *); + + template + auto f(const T &t) const + -> decltype(impl(t)) + { + return impl(t); + } +}; + +Problem t; +int i = t.f("42");