[libcxx-commits] [libcxx] [libc++][ios] Applied `[[nodiscard]]` (PR #173520)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Wed Dec 24 19:02:24 PST 2025


================
@@ -305,25 +305,25 @@ public:
   class _LIBCPP_EXPORTED_FROM_ABI Init;
 
   // 27.5.2.2 fmtflags state:
-  _LIBCPP_HIDE_FROM_ABI fmtflags flags() const;
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI fmtflags flags() const;
   _LIBCPP_HIDE_FROM_ABI fmtflags flags(fmtflags __fmtfl);
   _LIBCPP_HIDE_FROM_ABI fmtflags setf(fmtflags __fmtfl);
   _LIBCPP_HIDE_FROM_ABI fmtflags setf(fmtflags __fmtfl, fmtflags __mask);
   _LIBCPP_HIDE_FROM_ABI void unsetf(fmtflags __mask);
 
-  _LIBCPP_HIDE_FROM_ABI streamsize precision() const;
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI streamsize precision() const;
   _LIBCPP_HIDE_FROM_ABI streamsize precision(streamsize __prec);
-  _LIBCPP_HIDE_FROM_ABI streamsize width() const;
+  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI streamsize width() const;
   _LIBCPP_HIDE_FROM_ABI streamsize width(streamsize __wide);
 
   // 27.5.2.3 locales:
   locale imbue(const locale& __loc);
-  locale getloc() const;
+  [[__nodiscard__]] locale getloc() const;
 
   // 27.5.2.5 storage:
-  static int xalloc();
-  long& iword(int __index);
-  void*& pword(int __index);
+  [[__nodiscard__]] static int xalloc();
+  [[__nodiscard__]] long& iword(int __index);
+  [[__nodiscard__]] void*& pword(int __index);
----------------
frederick-vs-ja wrote:

Ignoring the return values of these functions seems to be a mistake to me (as they are somehow similar to `operator new` and `operator[]`). But I'm not very sure, and I haven't found anyone using these functions in practice.

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


More information about the libcxx-commits mailing list