Nathaniel Shead 90bc2d09b5 c++: End lifetime of objects in constexpr after destructor call [PR71093]
This patch adds checks for using objects after they've been manually
destroyed via explicit destructor call. Currently this is only
implemented for 'top-level' objects; FIELD_DECLs and individual elements
of arrays will need a lot more work to track correctly and are left for
a future patch.

The other limitation is that destruction of parameter objects is checked
too 'early', happening at the end of the function call rather than the
end of the owning full-expression as they should be for consistency;
see cpp2a/constexpr-lifetime2.C. This is because I wasn't able to find a
good way to link the constructed parameter declarations with the
variable declarations that are actually destroyed later on to propagate
their lifetime status, so I'm leaving this for a later patch.

	PR c++/71093

gcc/cp/ChangeLog:

	* constexpr.cc (constexpr_global_ctx::get_value_ptr): Don't
	return NULL_TREE for objects we're initializing.
	(constexpr_global_ctx::destroy_value): Rename from remove_value.
	Only mark real variables as outside lifetime.
	(constexpr_global_ctx::clear_value): New function.
	(destroy_value_checked): New function.
	(cxx_eval_call_expression): Defer complaining about non-constant
	arg0 for operator delete. Use remove_value_safe.
	(cxx_fold_indirect_ref_1): Handle conversion to 'as base' type.
	(outside_lifetime_error): Include name of object we're
	accessing.
	(cxx_eval_store_expression): Handle clobbers. Improve error
	messages.
	(cxx_eval_constant_expression): Use remove_value_safe. Clear
	bind variables before entering body.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp1y/constexpr-lifetime1.C: Improve error message.
	* g++.dg/cpp1y/constexpr-lifetime2.C: Likewise.
	* g++.dg/cpp1y/constexpr-lifetime3.C: Likewise.
	* g++.dg/cpp1y/constexpr-lifetime4.C: Likewise.
	* g++.dg/cpp2a/bitfield2.C: Likewise.
	* g++.dg/cpp2a/constexpr-new3.C: Likewise. New check.
	* g++.dg/cpp1y/constexpr-lifetime7.C: New test.
	* g++.dg/cpp2a/constexpr-lifetime1.C: New test.
	* g++.dg/cpp2a/constexpr-lifetime2.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2023-12-13 11:25:20 -05:00
2023-12-11 00:17:32 +00:00
2023-12-12 00:17:22 +00:00
2023-12-12 00:17:22 +00:00
2023-12-13 00:17:49 +00:00
2023-12-12 00:17:22 +00:00
2023-12-13 00:17:49 +00:00
2023-12-13 00:17:49 +00:00
2023-12-12 09:37:21 +01:00

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.
Description
No description provided
Readme 4.2 GiB
Languages
C++ 30.7%
C 30.2%
Ada 14.4%
D 6.1%
Go 5.7%
Other 12.4%