[libcxx-commits] [libcxx] c4f4206 - [libc++][vector] Test `[[nodiscard]]` applied to `vector::iterator` (#202262)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jun 9 03:13:23 PDT 2026


Author: Hristo Hristov
Date: 2026-06-09T13:13:19+03:00
New Revision: c4f4206ff3ab97db9577f11bb2dabd40896bcca9

URL: https://github.com/llvm/llvm-project/commit/c4f4206ff3ab97db9577f11bb2dabd40896bcca9
DIFF: https://github.com/llvm/llvm-project/commit/c4f4206ff3ab97db9577f11bb2dabd40896bcca9.diff

LOG: [libc++][vector] Test `[[nodiscard]]` applied to `vector::iterator` (#202262)

Adds test coverage.

`[[nodicard]]` applied in:

- #198489
- #198492

Towards #172124

Co-authored-by: Hristo Hristov <zingam at outlook.com>

Added: 
    libcxx/test/libcxx/containers/sequences/vector/nodiscard.iterator.verify.cpp

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/libcxx/test/libcxx/containers/sequences/vector/nodiscard.iterator.verify.cpp b/libcxx/test/libcxx/containers/sequences/vector/nodiscard.iterator.verify.cpp
new file mode 100644
index 0000000000000..8570a920270d9
--- /dev/null
+++ b/libcxx/test/libcxx/containers/sequences/vector/nodiscard.iterator.verify.cpp
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <vector>
+
+// Check that functions are marked [[nodiscard]]
+
+#include <vector>
+
+#include "test_macros.h"
+
+void test() {
+  typedef std::vector<int> Container;
+  Container c;
+  Container::iterator it        = c.begin();
+  Container::const_iterator cit = c.cbegin();
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  *it;
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  *cit;
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  it[0];
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  cit[0];
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  it + 1;
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  cit + 1;
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  1 + it;
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  1 + cit;
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  it - 1;
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  cit - 1;
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  it - it;
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  cit - cit;
+}


        


More information about the libcxx-commits mailing list