https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97388
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jason Merrill <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:5afd90c5f36bf45291ca09ef3791f4a574e90d5d commit r11-4541-g5afd90c5f36bf45291ca09ef3791f4a574e90d5d Author: Jakub Jelinek <ja...@redhat.com> Date: Tue Oct 20 09:33:20 2020 +0200 c++: Fix constexpr dtors vs invisible ref [PR97388] For arguments passed by invisible reference, in the IL until genericization we have the source types on the callee side and while on the caller side we already pass references to the actual argument slot in the caller, we undo that in cxx_bind_parameters_in_call's if (TREE_ADDRESSABLE (type)) /* Undo convert_for_arg_passing work here. */ x = convert_from_reference (x); This works fine most of the time, except when the type also has constexpr destructor; in that case the destructor is invoked in the caller and thus the unsharing we do to make sure that the callee doesn't modify caller's values is in that case undesirable, it prevents the changes done in the callee propagating to the caller which should see them for the constexpr dtor evaluation. The following patch fixes that. While it could be perhaps done for all TREE_ADDRESSABLE types, I don't see the need to change the behavior if there is no constexpr non-trivial dtor. Jason: And we need to avoid memoizing the call, because a later equivalent call also needs to modify its argument. And we don't need to unshare constructors when we aren't memoizing the call, because we already unshared them when evaluating the TARGET_EXPR representing the copy-initialization of the argument. 2020-10-20 Jakub Jelinek <ja...@redhat.com> Jason Merrill <ja...@redhat.com> PR c++/97388 * constexpr.c (cxx_bind_parameters_in_call): Set non_constant_args if the parameter type has a non-trivial destructor. (cxx_eval_call_expression): Only unshare arguments if we're memoizing this evaluation. * g++.dg/cpp2a/constexpr-dtor5.C: New test. * g++.dg/cpp2a/constexpr-dtor6.C: New test. * g++.dg/cpp2a/constexpr-dtor7.C: New test.