[libcxx-commits] [libcxx] [libc++] Add nodiscard attribute to std::make_unique/std::make_shared (PR #153115)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 13 12:55:54 PDT 2025


================
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+// check that functions are marked [[nodiscard]] as an extension in C++17
+
+// [[nodiscard]] std::make_unique(Args&&...);
+// [[nodiscard]] std::make_shared(Args&&...);
+//
+// [[nodiscard]] std::make_unique(size_t);
+// [[nodiscard]] std::make_shared(size_t);
+//
+// [[nodiscard]] std::make_unique_for_overwrite();
+// [[nodiscard]] std::make_shared_for_overwrite();
+
+#include <memory>
+
+void f() {
+
+    struct S {
+        S() = default;
+    };
+
+    std::make_unique<S>(S{}); // expected-warning {{ignoring return value of function}}
----------------
lukasx999 wrote:

I'm sorry but you're not being very helpful, you do mind pointing me to a resource that explains how "annotations" in this test system work?

https://github.com/llvm/llvm-project/pull/153115


More information about the libcxx-commits mailing list