From: Lunex <[email protected]>

PR c++/114804

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.
---
 gcc/cp/pt.cc                             |  6 ++++++
 gcc/testsuite/g++.dg/template/pr114804.C | 21 +++++++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/template/pr114804.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index ef912d1a7..9ff8b2f5c 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -13025,6 +13025,9 @@ instantiate_class_template (tree type)
   /* Defer access checking while we substitute into the types named in
      the base-clause.  */
   push_deferring_access_checks (dk_deferred);
+
+  tree pushed_scope = push_scope (CP_TYPE_CONTEXT (type));
+
   if (BINFO_N_BASE_BINFOS (pbinfo))
     {
       tree pbase_binfo;
@@ -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);
diff --git a/gcc/testsuite/g++.dg/template/pr114804.C 
b/gcc/testsuite/g++.dg/template/pr114804.C
new file mode 100644
index 000000000..67d518756
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/pr114804.C
@@ -0,0 +1,21 @@
+// PR c++/114804
+// { dg-do compile }
+
+template <int D> struct blurb
+{
+  constexpr static int d = D;
+};
+
+template <int> struct pant
+{
+};
+
+template <typename Base> struct bug : Base
+{
+  using Base::d;
+  struct problem : pant<d>
+  {
+  };
+};
+
+template struct bug<blurb<2>>;
-- 
2.54.0

Reply via email to