[libcxx-commits] [libcxx] [libc++][tuple] Applied `[[nodiscard]]` (PR #172008)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Dec 14 18:55:45 PST 2025
================
@@ -0,0 +1,64 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++11
+
+// Check that functions are marked [[nodiscard]]
+
+#include <tuple>
+
+#include "test_macros.h"
+
+void test() {
+ struct First {};
+ struct Second {};
+ struct Third {};
+
+ std::tuple<First, Second, Third> t;
+ const std::tuple<First, Second, Third> ct;
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::get<0>(t);
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::get<0>(ct);
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::get<0>(std::move(t));
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::get<0>(std::move(t));
+#if TEST_STD_VER >= 14
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::get<Third>(t);
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::get<Third>(ct);
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::get<Third>(std::move(t));
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::get<Third>(std::move(t));
+#endif
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::tie(ct);
+
+ First e1;
+ Second e2;
+ Third e3;
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::make_tuple(e1, e2, e3);
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::forward_as_tuple(First{}, Second{}, Third{});
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::tuple_cat(std::tuple<First>{}, std::tuple<Second, Third>{});
----------------
frederick-vs-ja wrote:
Let's verify `std::tuple_cat()` (nullary call) together.
https://github.com/llvm/llvm-project/pull/172008
More information about the libcxx-commits
mailing list