]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Use deducing this in std::bind when available [PR80564]
authorPatrick Palka <ppalka@redhat.com>
Sat, 6 Dec 2025 02:09:34 +0000 (21:09 -0500)
committerPatrick Palka <ppalka@redhat.com>
Sat, 6 Dec 2025 02:09:34 +0000 (21:09 -0500)
commit83aab2f73661ac8aa1643d58d2fbfed87d5c1601
tree5731c56f89f1f169063cbd5bfea4d32daaf185b7
parenta1d895cd7a1d83c22d2544336655be14ed8a981b
libstdc++: Use deducing this in std::bind when available [PR80564]

Implement the forwarding performed by std::bind via deducing this when
available, instead of needing 4 operator() overloads.  Using deducing
this here is more complicated than in other standard call wrappers
because std::bind is not really "perfect forwarding": it doesn't
consider value category, and along with const-ness it also forwards
volatile-ness (until C++20).

The old implementation suffers from the same problem that other
pre-C++23 SFINAE-friendly call wrappers have which is solved by using
deducing this (see p5.5 of the deducing this paper P0847R7).

PR libstdc++/80564

libstdc++-v3/ChangeLog:

* include/std/functional (__cv_like): New.
(_Bind::_Res_type): Don't define when not needed.
(_Bind::__dependent): Likewise.
(_Bind::_Res_type_cv): Likewise.
(_Bind::operator()) [_GLIBCXX_EXPLICIT_THIS_PARAMETER]:
Define as two instead of four overloads using deducing
this.
* testsuite/20_util/bind/cv_quals_2.cc: Ignore SFINAE
diagnostics inside headers.
* testsuite/20_util/bind/ref_neg.cc: Likewise.
* testsuite/20_util/bind/80564.cc: New test.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/include/std/functional
libstdc++-v3/testsuite/20_util/bind/80564.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/bind/cv_quals_2.cc
libstdc++-v3/testsuite/20_util/bind/ref_neg.cc