aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/doc
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2025-03-11 17:29:01 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2025-03-12 10:12:36 +0000
commit8ff7ff1a0691b7b409aa31c8f6dfcefec3e4720b (patch)
tree843db2927ffe6681202c3c97ae0d90f5c801392a /libstdc++-v3/doc
parent04815ae0a2b27895411506813db3a8b460be1d6d (diff)
downloadgcc-8ff7ff1a0691b7b409aa31c8f6dfcefec3e4720b.zip
gcc-8ff7ff1a0691b7b409aa31c8f6dfcefec3e4720b.tar.gz
gcc-8ff7ff1a0691b7b409aa31c8f6dfcefec3e4720b.tar.bz2
libstdc++: Prevent dangling references in std::unique_ptr::operator*
LWG 4148 (approved in Wrocław, November 2024) makes it ill-formed to dereference a std::unique_ptr if that would return a dangling reference. That can happen with a custom pointer type and a const-qualified element_type, such that std::add_lvalue_reference_t<element_type> is a reference-to-const that could bind to a short-lived temporary. In C++26 the compiler diagnoses this as an error anyway: bits/unique_ptr.h:457:16: error: returning reference to temporary [-Wreturn-local-addr] But that can be disabled with -Wno-return-local-addr so the static_assert ensures it is enforced consistently. libstdc++-v3/ChangeLog: * include/bits/unique_ptr.h (unique_ptr::operator*): Add static_assert to check for dangling reference, as per LWG 4148. * testsuite/20_util/unique_ptr/lwg4148.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Diffstat (limited to 'libstdc++-v3/doc')
0 files changed, 0 insertions, 0 deletions