]> gcc.gnu.org Git - 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, 28 Mar 2023 22:15:10 +0000 (23:15 +0100)
commit14d1ca9e5c4271e98afd025b2b36d229bcc2f6ea
tree468a8e207678d08b6f5edd2ab95b0fdb4e27493d
parent99f7d9133595463426c6ea75c4f6f9ebf0058b6e
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.

(cherry picked from commit 5c2d703e6d6d47f41635ca4df06c555010462081)
libstdc++-v3/include/std/memory_resource
This page took 0.059376 seconds and 6 git commands to generate.