From b6e45a40cde2c8e7a18b62cca23dcd2f6916afa1 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 18 Mar 2019 11:58:24 -0400 Subject: [PATCH] PR c++/89682 - wrong access error in default argument. 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 | 5 +++++ gcc/cp/pt.c | 2 ++ gcc/testsuite/g++.dg/overload/defarg12.C | 14 ++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 gcc/testsuite/g++.dg/overload/defarg12.C 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 + + PR c++/89682 - wrong access error in default argument. + * pt.c (tsubst_default_argument): Don't defer access checks. + 2019-03-18 Paolo Carlini PR c++/85014 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 +class C { + class TagType {}; +public: + C(int, TagType = makeTag()); +private: + static TagType makeTag(); +}; + +void test() { + C(1); +} -- 2.30.2