[PATCH] c++: fix lookup into enclosing scope when instantiating nested class bases
Jason Merrill
jason@redhat.com
Wed Sep 2 13:20:28 GMT 2026
On 9/1/26 3:34 AM, imlunex2011@gmail.com wrote:
> From: Lunex <imlunex2011@gmail.com>
Thanks for the patch! I'm pushing it with some adjustments.
This patch is trivial enough not to worry about copyright, but if you
want to continue contributing under this pseudonym I encourage you to
file a copyright assignment with the FSF. See
https://gcc.gnu.org/contribute.html#legal for more information.
> PR c++/114804
For future reference, the PR number should go at the top of the
ChangeLog entries.
> r11-6815 (PR 82613) removed push_scope/pop_scope around base-clause
> substitution in instantiate_class_template. This broke lookup for
> using-declarations that bring enclosing-class members into scope
> during nested class instantiation.
>
> This restores the enclosing-class scope push/pop that was there before
> r11-6815.
>
> gcc/cp/ChangeLog:
> * pt.cc (instantiate_class_template): Push enclosing class scope
> before base substitution, pop after.
>
> gcc/testsuite/ChangeLog:
> * g++.dg/template/pr114804.C: New test.
And please name testcases by what they are testing, not just the PR;
I've renamed it to dependent-base7.C.
> @@ -13093,6 +13096,9 @@ instantiate_class_template (tree type)
> information. */
> xref_basetypes (type, base_list);
>
> + if (pushed_scope)
> + pop_scope (pushed_scope);
> +
> apply_late_template_attributes (&type, TYPE_ATTRIBUTES (pattern),
> (int) ATTR_FLAG_TYPE_IN_PLACE,
> args, tf_error, NULL_TREE);
It occurred to me that rather than pop all the way out and then almost
immediately push_nested_class again, we could stay in the enclosing
scope and only push one level into the class we're defining.
> +++ b/gcc/testsuite/g++.dg/template/pr114804.C
> @@ -0,0 +1,21 @@
> +// PR c++/114804
> +// { dg-do compile }
Also this needs { target c++11 } to avoid FAILing in C++98 mode. How
did you test the patch?
Here's what I'm pushing:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-c-lookup-in-enclosing-scope-when-instantiating-neste.patch
Type: text/x-patch
Size: 3130 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-bugs/attachments/20260902/106bb7f8/attachment.bin>
More information about the Gcc-bugs
mailing list