Patrick Palka e4c57e146a c++: non-empty constexpr constructor bodies in C++11 [PR123845]
This patch makes us support C++14 non-empty constexpr constructor bodies
in C++11, as an extension.  This will make it trivial to safely fix the
C++11 library regression PR114865 that requires us to do
__builtin_clear_padding after initializing _M_i in std::atomic's
single-parameter constructor, and that's not really possible with the
C++11 constexpr restrictions.

Since we lower member initializers to constructor body statements
internally, and so constructor bodies are already effectively non-empty
internally even in C++11, supporting non-empty bodies in user code is
mostly a matter of relaxing the parse-time error.

But constexpr-ex3.C revealed that by accepting the non-empty body of A's
constructor, build_data_member_initialization goes on to mistake the
'i = _i' assignment as a member initializer, and we incorrectly accept
the constructor in C++11 mode (even though omitting mem-inits is only
valid since C++20).  Turns out this is caused by that function
recognizing MODIFY_EXPR only in C++11 mode, logic that was last changed
by r5-5013 (presumably to limit impact of the patch at the time) but I
reckon could just be removed outright.  This should be safe because the
result of build_data_member_initialization is only used by
cx_check_missing_mem_inits for validation; evaluation is in terms of
the entire lowered constructor body.

	PR c++/123845
	PR libstdc++/114865

gcc/cp/ChangeLog:

	* constexpr.cc (build_data_member_initialization): Remove
	C++11-specific recognition of MODIFY_EXPR.
	(check_constexpr_ctor_body): Relax error diagnostic to a
	pedwarn and don't clear DECL_DECLARED_CONSTEXPR_P upon
	error.  Return true if complaining.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/constexpr-ex3.C: Adjust C++11 non-empty
	constexpr constructor dg-error to a dg-warning.  Expect
	a follow-up missing member initializer diagnostic in C++11 mode.
	* g++.dg/cpp2a/constexpr-try1.C: Expect a follow-up
	compound-statement in constexpr function diagnostic in C++11
	mode.
	* g++.dg/cpp2a/constexpr-try2.C: Likewise.  Adjust C++11
	non-empty constexpr constructor dg-error to a dg-warning.
	* g++.dg/cpp2a/constexpr-try3.C:  Adjust C++11 non-empty
	constexpr constructor dg-error to a dg-warning.
	* g++.dg/cpp0x/constexpr-ctor23.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2026-01-30 15:25:43 -05:00
2026-01-21 00:16:32 +00:00
2026-01-16 00:16:30 +00:00
2026-01-30 00:16:31 +00:00
2026-01-25 00:16:27 +00:00
2026-01-18 00:16:31 +00:00
2026-01-14 00:16:30 +00:00
2026-01-21 00:16:32 +00:00
2026-01-27 00:16:29 +00:00
2026-01-23 00:16:27 +00:00
2026-01-19 09:56:51 +01:00
2026-01-19 09:56:51 +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%