Skip to content
Snippets Groups Projects
Commit caf17f3a authored by Marek Polacek's avatar Marek Polacek
Browse files

c++: Fix wrong error with constexpr destructor [PR97427]

When I implemented the code to detect modifying const objects in
constexpr contexts, we couldn't have constexpr destructors, so I didn't
consider them.  But now we can and that caused a bogus error in this
testcase: [class.dtor]p5 says that "const and volatile semantics are not
applied on an object under destruction.  They stop being in effect when
the destructor for the most derived object starts." so we have to clear
the TREE_READONLY flag we set on the object after the constructors have
been called to mark it as no-longer-under-construction.  In the ~Foo
call it's now an object under destruction, so don't report those errors.

gcc/cp/ChangeLog:

	PR c++/97427
	* constexpr.c (cxx_set_object_constness): New function.
	(cxx_eval_call_expression): Set new_obj for destructors too.
	Call cxx_set_object_constness to set/unset TREE_READONLY of
	the object under construction/destruction.

gcc/testsuite/ChangeLog:

	PR c++/97427
	* g++.dg/cpp2a/constexpr-dtor10.C: New test.
parent 62d19588
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment