Here we were pushing into the right access context, but we were called from
a deferred checking context, so didn't end up doing the checks until after
we left the access context.

Tested x86_64-pc-linux-gnu, applying to trunk.

        * pt.c (tsubst_default_argument): Don't defer access checks.
---
 gcc/cp/pt.c                              |  2 ++
 gcc/testsuite/g++.dg/overload/defarg12.C | 14 ++++++++++++++
 gcc/cp/ChangeLog                         |  5 +++++
 3 files changed, 21 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/overload/defarg12.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index dc5c24c47a7..7dc6e44cf7b 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -12776,6 +12776,7 @@ tsubst_default_argument (tree fn, int parmnum, tree 
type, tree arg,
      rather than in the current class.  */
   push_to_top_level ();
   push_access_scope (fn);
+  push_deferring_access_checks (dk_no_deferred);
   start_lambda_scope (parm);
 
   /* The default argument expression may cause implicitly defined
@@ -12799,6 +12800,7 @@ tsubst_default_argument (tree fn, int parmnum, tree 
type, tree arg,
     inform (input_location,
            "  when instantiating default argument for call to %qD", fn);
 
+  pop_deferring_access_checks ();
   pop_access_scope (fn);
   pop_from_top_level ();
 
diff --git a/gcc/testsuite/g++.dg/overload/defarg12.C 
b/gcc/testsuite/g++.dg/overload/defarg12.C
new file mode 100644
index 00000000000..4a2b7e5b1af
--- /dev/null
+++ b/gcc/testsuite/g++.dg/overload/defarg12.C
@@ -0,0 +1,14 @@
+// PR c++/89682
+
+template <typename T>
+class C {
+    class TagType {};
+public:
+    C(int, TagType = makeTag());
+private:
+    static TagType makeTag();
+};
+
+void test() {
+    C<int>(1);
+}
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index fa569bc1a61..bc3850d3aff 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2019-03-18  Jason Merrill  <ja...@redhat.com>
+
+       PR c++/89682 - wrong access error in default argument.
+       * pt.c (tsubst_default_argument): Don't defer access checks.
+
 2019-03-18  Paolo Carlini  <paolo.carl...@oracle.com>
 
        PR c++/85014

base-commit: 92bb50f3c7ed732e5734c57da7c6da6f7a5892a9
-- 
2.20.1

Reply via email to