PR c++/89682 - wrong access error in default argument.
authorJason Merrill <jason@redhat.com>
Mon, 18 Mar 2019 15:58:24 +0000 (11:58 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 18 Mar 2019 15:58:24 +0000 (11:58 -0400)
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.

* pt.c (tsubst_default_argument): Don't defer access checks.

From-SVN: r269766

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/overload/defarg12.C [new file with mode: 0644]

index fa569bc..bc3850d 100644 (file)
@@ -1,3 +1,8 @@
+2019-03-18  Jason Merrill  <jason@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.carlini@oracle.com>
 
        PR c++/85014
index dc5c24c..7dc6e44 100644 (file)
@@ -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 (file)
index 0000000..4a2b7e5
--- /dev/null
@@ -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);
+}