From 8cb2c7fc2ea4b40494b9be0f446bfbb2e52e057d Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 2 Nov 2023 23:19:09 -0400 Subject: gdbsupport: mark array_view::slice with [[nodiscard]] I (almost) had a bug where I did: buffer.slice (...) but I meant: buffer = buffer.slice (...) The first one does nothing, it creates a new array_view but without using it, it's useless. Mark the slice methods with [[nodiscard]] (which is standard C++17) so that error would generate a warning. I guess that many functions could be marked as nodiscard, essentially function that is pure (doesn't have side-effects). But this one seems particularly easy to mis-use. Change-Id: Ib39a0a65a5728a3cfd68a02ae31635810baeaccb Approved-By: Tom Tromey --- gdbsupport/array-view.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gdbsupport') diff --git a/gdbsupport/array-view.h b/gdbsupport/array-view.h index ee3a3c5..4b51911 100644 --- a/gdbsupport/array-view.h +++ b/gdbsupport/array-view.h @@ -185,6 +185,7 @@ public: /* Slice an array view. */ /* Return a new array view over SIZE elements starting at START. */ + [[nodiscard]] constexpr array_view slice (size_type start, size_type size) const noexcept { #if defined(_GLIBCXX_DEBUG) && __cplusplus >= 201402L @@ -195,6 +196,7 @@ public: /* Return a new array view over all the elements after START, inclusive. */ + [[nodiscard]] constexpr array_view slice (size_type start) const noexcept { #if defined(_GLIBCXX_DEBUG) && __cplusplus >= 201402L -- cgit v1.1