[libcxx-commits] [libcxx] a19c346 - [libc++][string_view] Test [[nodiscard]] applied to `basic_string_view::const_iterator` (#202203)

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jun 7 11:45:17 PDT 2026


Author: Hristo Hristov
Date: 2026-06-07T21:45:13+03:00
New Revision: a19c34627b8ee062ff3ee238f54cc4be8720e8dc

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

LOG: [libc++][string_view] Test [[nodiscard]] applied to `basic_string_view::const_iterator` (#202203)

Adds test coverage.

`[[nodicard]]` applied in:
- https://github.com/llvm/llvm-project/pull/198489
- https://github.com/llvm/llvm-project/pull/198492

Towards #172124

Added: 
    libcxx/test/libcxx/strings/string.view/nodiscard.iterator.verify.cpp

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/libcxx/test/libcxx/strings/string.view/nodiscard.iterator.verify.cpp b/libcxx/test/libcxx/strings/string.view/nodiscard.iterator.verify.cpp
new file mode 100644
index 0000000000000..b8eb5f835b597
--- /dev/null
+++ b/libcxx/test/libcxx/strings/string.view/nodiscard.iterator.verify.cpp
@@ -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
+//
+//===----------------------------------------------------------------------===//
+
+// <string_view>
+
+// Check that functions are marked [[nodiscard]]
+
+#include <string_view>
+
+#include "test_macros.h"
+
+void test() {
+  typedef std::string_view Container;
+  Container c;
+  Container::const_iterator cit = c.begin();
+
+  // expected-warning-re at +1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
+  *cit;
+
+  // expected-warning-re at +1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
+  cit[0];
+
+  // expected-warning-re at +1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
+  cit + 1;
+
+  // expected-warning-re at +1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
+  1 + cit;
+
+  // expected-warning-re at +1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
+  cit - 1;
+
+  // expected-warning-re at +1 {{{{(ignoring return value of function declared with 'nodiscard' attribute|expression result unused)}}}}
+  cit - cit;
+}


        


More information about the libcxx-commits mailing list