]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Add attributes to functions in <memory_resource>
authorJonathan Wakely <jwakely@redhat.com>
Tue, 17 May 2022 14:14:39 +0000 (15:14 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 17 May 2022 19:51:04 +0000 (20:51 +0100)
commit5c2d703e6d6d47f41635ca4df06c555010462081
treef48a78f7fff6b6350fb4fa804aa63578a9988c64
parent5f1ce85135a92481307f2eb4ad805bc53f6137a3
libstdc++: Add attributes to functions in <memory_resource>

Add attributes to the accessors for the global memory resource objects,
to allow the compiler to eliminate redundant calls to them. For example,
multiple calls to std::pmr::new_delete_resource() will always return the
same object, and so the compiler can replace them with a single call.

Ideally we would like adjacent calls to std::pmr::get_default_resource()
to be combined into a single call by the CSE pass. The 'pure' attribute
would permit that. However, the standard requires that calls to
std::pmr::set_default_resource() synchronize with subsequent calls to
std::pmr::get_default_resource().  With 'pure' the DCE pass might
eliminate seemingly redundant calls to std::pmr::get_default_resource().
That might be unsafe, because the caller might be relying on the
associated synchronization. We could use a hypothetical attribute that
allows CSE but not DCE, but we don't have one. So it can't be 'pure'.

Also add [[nodiscard]] to equality operators.

libstdc++-v3/ChangeLog:

* include/std/memory_resource (new_delete_resource): Add
nodiscard, returns_nonnull and const attributes.
(null_memory_resource): Likewise.
(set_default_resource, get_default_resource): Add returns_nonnull
attribute.
(memory_resource::is_equal): Add nodiscard attribute.
(operator==, operator!=): Likewise.
libstdc++-v3/include/std/memory_resource