aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/sql/Time.java
diff options
context:
space:
mode:
authorTomasz Kamiński <tkaminsk@redhat.com>2026-02-02 10:19:51 +0100
committerTomasz Kamiński <tkaminsk@redhat.com>2026-02-11 17:54:09 +0100
commitb58cf254437aa78046666b7444a23e2658396f80 (patch)
tree8bafc267ebda4dd7cdcc4d52b523f620730fea8a /libjava/java/sql/Time.java
parentf407f0cf841fedde01f6485875ae14d5281baa63 (diff)
downloadgcc-b58cf254437aa78046666b7444a23e2658396f80.zip
gcc-b58cf254437aa78046666b7444a23e2658396f80.tar.gz
gcc-b58cf254437aa78046666b7444a23e2658396f80.tar.bz2
libstdc++: Make function_ref non-dangling for stateless wrappers
This patch makes the function_ref non-dangling for the stateless wrappers: * any functor for which operator() selected for arguments is static, * standard functors, including pre-C++20 ones. In other words, any function_ref fr, that is constructed from stateless wrapper w, can be still called after the object w is destroyed, e.g.: std::function_ref<bool(int, int)> fr(std::ranges::less{}); fr(1, 2); // OK, previously UB because fr referred to already destroyed // temporary As function_ref's operator() is not constexpr, we test the change by checking if the above declaration can be made constexpr, as such variable cannot contain dangling pointer values. We adjust the function_ref generic constructor from any functor, to use more specialized invoker: * _S_static (newly added) if the called operator() overload is static, after changes r16-5624-g0ea9d760fbf44c, this covers all post-c++20 functors; * _S_nttp<_Fd{}> for pre-C++20 standard functors. In both above cases the value of _M_ptrs is ignored and simply set to nullptr. This follows same technique (checking _Fd::operator()(args...)), and support the same set of types, as for one used for the transform views iterators in r16-5625-g9ed821d107f7a1. As after this change we provide well-defined behavior for the code, that previous was undefined, this changes is pure quality-of-implementation. As illustrated by the test cases, it has observable side effects, where non-longer dangling constructs can be used to define constexpr function_ref. However, the standard does not define when the constructors defined constexpr are actually usable at compile time, and the already have precedent in form of SSO string for validity such constructs being implementation specific. libstdc++-v3/ChangeLog: * include/bits/funcref_impl.h (function_ref::function_ref(_Fn&&)): Use _S_static and _S_nttp invokers. * include/bits/funcwrap.h (_Base_invoker::_S_static): Define. * include/bits/stl_function.h (std::__is_std_op_template) (std::__is_std_op_wrapper) [__cplusplus > 201703L]: Moved from std/ranges. * include/std/ranges (__detail::__is_std_op_template) (__detail::__is_std_op_wrapper): Moved to bits/stl_function.h. * testsuite/20_util/function_ref/dangling.cc: New test. * testsuite/20_util/function_ref/dangling_neg.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
Diffstat (limited to 'libjava/java/sql/Time.java')
0 files changed, 0 insertions, 0 deletions