[libcxx-commits] [libcxx] [libc++][memory] Applied `[[nodiscard]]` to more functions (PR #172131)
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jan 6 13:09:38 PST 2026
================
@@ -6,37 +6,122 @@
//
//===----------------------------------------------------------------------===//
-// UNSUPPORTED: c++03
+// <memory>
-// check that <memory> functions are marked [[nodiscard]]
+// Check that functions are marked [[nodiscard]]
+// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_TEMPORARY_BUFFER
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
-// clang-format off
-
#include <memory>
#include "test_macros.h"
void test() {
- std::get_temporary_buffer<int>(0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-}
+ int i = 0;
-void test_allocator_traits() {
- std::allocator<int> allocator;
- std::allocator_traits<std::allocator<int>> allocator_traits;
- allocator_traits.allocate(allocator, 1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
- allocator_traits.allocate(allocator, 1, nullptr); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-}
+ {
+ std::addressof(i); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::get_temporary_buffer<int>(0);
+#if _LIBCPP_STD_VER >= 26
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::is_sufficiently_aligned<2>(&i);
+#endif
+ }
-void test_allocator() {
- std::allocator<int> allocator;
- allocator.allocate(1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
-#if TEST_STD_VER <= 17
- allocator.allocate(1, nullptr); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
+ {
+ struct Alloc {
+ typedef int value_type;
----------------
H-G-Hristov wrote:
This test is supposed to run in C++03 mode also and `using` is a C++11 extension.
https://github.com/llvm/llvm-project/pull/172131
More information about the libcxx-commits
mailing list