aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/method.cc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2024-02-14 10:20:31 -0500
committerPatrick Palka <ppalka@redhat.com>2024-02-14 10:20:31 -0500
commit9bc6b23d11697545e8a951ccd60691b1e58b98c2 (patch)
treeaedf2494919ef819fbb70afd9cf48fe10f3cd63c /gcc/cp/method.cc
parentad7a365aaccecd23ea287c7faaab9c7bd50b944a (diff)
downloadgcc-9bc6b23d11697545e8a951ccd60691b1e58b98c2.zip
gcc-9bc6b23d11697545e8a951ccd60691b1e58b98c2.tar.gz
gcc-9bc6b23d11697545e8a951ccd60691b1e58b98c2.tar.bz2
c++: synthesized_method_walk context independence [PR113908]
In the second testcase below, during ahead of time checking of the non-dependent new-expr we synthesize B's copy ctor, which we expect to get defined as deleted since A's copy ctor is inaccessible. But during access checking thereof, enforce_access incorrectly decides to defer it since we're in a template context according to current_template_parms (before r14-557 it checked processing_template_decl which got cleared from implicitly_declare_fn), which leads to the access check leaking out to the template context that triggered the synthesization, and B's copy ctor getting declared as non-deleted. This patch fixes this by using maybe_push_to_top_level to clear the context (including current_template_parms) before proceeding with the synthesization. We could do this from implicitly_declare_fn, but it's better to do it more generally from synthesized_method_walk for sake of its other callers. This turns out to fix PR113332 as well: there the lambda context triggering synthesization was causing maybe_dummy_object to misbehave, but now synthesization is sufficiently context-independent. PR c++/113908 PR c++/113332 gcc/cp/ChangeLog: * method.cc (synthesized_method_walk): Use maybe_push_to_top_level. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/lambda/lambda-nsdmi11.C: New test. * g++.dg/template/non-dependent31.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
Diffstat (limited to 'gcc/cp/method.cc')
-rw-r--r--gcc/cp/method.cc2
1 files changed, 2 insertions, 0 deletions
diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc
index 957496d..98c10e6 100644
--- a/gcc/cp/method.cc
+++ b/gcc/cp/method.cc
@@ -2760,6 +2760,7 @@ synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
return;
}
+ bool push_to_top = maybe_push_to_top_level (TYPE_NAME (ctype));
++cp_unevaluated_operand;
++c_inhibit_evaluation_warnings;
push_deferring_access_checks (dk_no_deferred);
@@ -2857,6 +2858,7 @@ synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
pop_deferring_access_checks ();
--cp_unevaluated_operand;
--c_inhibit_evaluation_warnings;
+ maybe_pop_from_top_level (push_to_top);
}
/* DECL is a defaulted function whose exception specification is now