Find a file
Marek Polacek 772d532e0b c++: Implement C++23 P2266R1, Simpler implicit move [PR101165]
This patch implements https://wg21.link/p2266, which, once again,
changes the implicit move rules.  Here's a brief summary of various
changes in this area:

r125211: Introduced moving from certain lvalues when returning them
r171071: CWG 1148, enable move from value parameter on return
r212099: CWG 1579, it's OK to call a converting ctor taking an rvalue
r251035: CWG 1579, do maybe-rvalue overload resolution twice
r11-2411: Avoid calling const copy ctor on implicit move
r11-2412: C++20 implicit move changes, remove the fallback overload
          resolution, allow move on throw of parameters and implicit
	  move of rvalue references

P2266 enables the implicit move even for functions that return references.
That is, we will now perform a move in

  X&& foo (X&& x) {
    return x;
  }

P2266 also removes the fallback overload resolution, but this was
resolved by r11-2412: we only do convert_for_initialization with
LOOKUP_PREFER_RVALUE in C++17 and older.
P2266 also says that a returned move-eligible id-expression is always an
xvalue.  This required some further short, but nontrivial changes,
especially when it comes to deduction, because we have to pay attention
to whether we have auto, auto&& (which is like T&&), or decltype(auto)
with (un)parenthesized argument.  In C++23,

  decltype(auto) f(int&& x) { return (x); }
  auto&& f(int x) { return x; }

both should deduce to 'int&&' but

  decltype(auto) f(int x) { return x; }

should deduce to 'int'.  A cornucopia of tests attached.  I've also
verified that we behave like clang++.

xvalue_p seemed to be broken: since the introduction of clk_implicit_rval,
it cannot use '==' when checking for clk_rvalueref.

Since this change breaks code, it's only enabled in C++23.  In
particular, this code will not compile in C++23:

  int& g(int&& x) { return x; }

because x is now treated as an rvalue, and you can't bind a non-const lvalue
reference to an rvalue.

This patch also fixes PR106882 (the check_return_expr changes).

	PR c++/101165
	PR c++/106882

gcc/c-family/ChangeLog:

	* c-cppbuiltin.cc (c_cpp_builtins): Define __cpp_implicit_move.

gcc/cp/ChangeLog:

	* call.cc (reference_binding): Check clk_implicit_rval in C++20 only.
	* cp-tree.h (unparenthesized_id_or_class_member_access_p): Declare.
	* pt.cc (unparenthesized_id_or_class_member_access_p): New function,
	broken out of...
	(do_auto_deduction): ...here.  Use it.  In C++23, maybe call
	treat_lvalue_as_rvalue_p.
	* tree.cc (xvalue_p): Check & clk_rvalueref, not == clk_rvalueref.
	* typeck.cc (check_return_expr): Allow implicit move for functions
	returning a reference as well, or when the return value type is not
	a scalar type.

gcc/testsuite/ChangeLog:

	* g++.dg/conversion/pr41426.C: Add dg-error for C++23.
	* g++.dg/cpp0x/elision_weak.C: Likewise.
	* g++.dg/cpp0x/move-return3.C: Only link in c++20_down.
	* g++.dg/cpp1y/decltype-auto2.C: Add dg-error for C++23.
	* g++.dg/cpp1y/lambda-generic-89419.C: Likewise.
	* g++.dg/cpp23/feat-cxx2b.C: Test __cpp_implicit_move.
	* g++.dg/gomp/pr56217.C: Only compile in c++20_down.
	* g++.dg/warn/Wno-return-local-addr.C: Add dg-error for C++23.
	* g++.dg/warn/Wreturn-local-addr.C: Adjust dg-error.
	* g++.old-deja/g++.brendan/crash55.C: Add dg-error for C++23.
	* g++.old-deja/g++.jason/temporary2.C: Likewise.
	* g++.old-deja/g++.mike/p2846b.C: Adjust.
	* g++.dg/cpp1y/decltype-auto6.C: New test.
	* g++.dg/cpp23/decltype1.C: New test.
	* g++.dg/cpp23/decltype2.C: New test.
	* g++.dg/cpp23/elision1.C: New test.
	* g++.dg/cpp23/elision2.C: New test.
	* g++.dg/cpp23/elision3.C: New test.
	* g++.dg/cpp23/elision4.C: New test.
	* g++.dg/cpp23/elision5.C: New test.
	* g++.dg/cpp23/elision6.C: New test.
	* g++.dg/cpp23/elision7.C: New test.
2022-09-27 18:49:25 -04:00
c++tools Daily bump. 2022-03-19 00:16:22 +00:00
config Daily bump. 2022-09-01 00:17:39 +00:00
contrib Daily bump. 2022-09-21 00:19:14 +00:00
fixincludes fixincludes: FIx up for Debian/Ubuntu includes 2022-09-27 12:33:23 +02:00
gcc c++: Implement C++23 P2266R1, Simpler implicit move [PR101165] 2022-09-27 18:49:25 -04:00
gnattools Daily bump. 2022-09-01 00:17:39 +00:00
gotools Daily bump. 2022-08-31 00:16:45 +00:00
include c++: Implement P1467R9 - Extended floating-point types and standard names compiler part except for bfloat16 [PR106652] 2022-09-27 08:18:00 +02:00
INSTALL
intl Daily bump. 2021-11-30 00:16:44 +00:00
libada Daily bump. 2022-08-26 00:16:21 +00:00
libatomic Daily bump. 2022-08-31 00:16:45 +00:00
libbacktrace Daily bump. 2022-07-09 00:16:54 +00:00
libcc1 Daily bump. 2022-06-28 00:16:58 +00:00
libcody Daily bump. 2022-06-04 00:16:27 +00:00
libcpp c++: Implement P1467R9 - Extended floating-point types and standard names compiler part except for bfloat16 [PR106652] 2022-09-27 08:18:00 +02:00
libdecnumber Daily bump. 2022-05-21 00:16:32 +00:00
libffi Daily bump. 2021-11-16 00:16:31 +00:00
libgcc Daily bump. 2022-09-27 00:17:52 +00:00
libgfortran Daily bump. 2022-09-22 00:19:09 +00:00
libgo runtime: portable access to sigev_notify_thread_id 2022-09-27 09:30:23 -07:00
libgomp Daily bump. 2022-09-25 00:18:01 +00:00
libiberty c++: Implement P1467R9 - Extended floating-point types and standard names compiler part except for bfloat16 [PR106652] 2022-09-27 08:18:00 +02:00
libitm Daily bump. 2022-09-01 00:17:39 +00:00
libobjc Daily bump. 2022-08-26 00:16:21 +00:00
liboffloadmic Daily bump. 2022-09-10 00:17:21 +00:00
libphobos d: Merge upstream dmd d579c467c1, phobos 88aa69b14. 2022-09-27 10:50:18 +02:00
libquadmath Daily bump. 2022-08-26 00:16:21 +00:00
libsanitizer Daily bump. 2022-09-05 00:16:27 +00:00
libssp Daily bump. 2022-08-26 00:16:21 +00:00
libstdc++-v3 c++: Make __is_{,nothrow_}convertible SFINAE on access [PR107049] 2022-09-27 11:59:53 +01:00
libvtv Daily bump. 2022-08-26 00:16:21 +00:00
lto-plugin Daily bump. 2022-08-02 00:16:51 +00:00
maintainer-scripts Daily bump. 2022-07-29 00:16:21 +00:00
zlib Daily bump. 2022-08-26 00:16:21 +00:00
.dir-locals.el dir-locals: Use https for bug references 2021-07-20 11:40:34 +01:00
.gitattributes
.gitignore .gitignore: do not ignore config.h 2022-07-19 17:07:04 +03:00
ABOUT-NLS
ar-lib
ChangeLog Daily bump. 2022-09-27 00:17:52 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in
config.guess config.sub, config.guess : Import upstream 2021-01-25. 2021-02-23 17:21:10 +08:00
config.rpath
config.sub config.sub: change mode to 755. 2021-12-21 09:10:57 +01:00
configure [gdb/build] Fix build breaker with --enable-shared 2022-09-07 13:19:05 +02:00
configure.ac [gdb/build] Fix build breaker with --enable-shared 2022-09-07 13:19:05 +02:00
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
depcomp
install-sh
libtool-ldflags
libtool.m4 Revert "Sync with binutils: GCC: Pass --plugin to AR and RANLIB" 2021-12-15 20:45:58 -08:00
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
MAINTAINERS Update my address and DCO entry in MAINTAINERS file 2022-09-26 09:14:55 -06:00
Makefile.def Makefile.def: drop remnants of unused libelf 2022-08-18 09:37:09 +01:00
Makefile.in Makefile.def: drop remnants of unused libelf 2022-08-18 09:37:09 +01:00
Makefile.tpl Makefile.def: drop remnants of unused libelf 2022-08-18 09:37:09 +01:00
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
symlink-tree
test-driver
ylwrap

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.