Replace WARN_UNUSED_RESULT with [[nodiscard]].

Use the standard C++17 attribute instead of a macro.

Change-Id: Ieba23e70bb0a46a6e1019f15d029aecbadddc93b
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/92830
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/bytestring.h b/core/fxcrt/bytestring.h
index a21c584..01881f7 100644
--- a/core/fxcrt/bytestring.h
+++ b/core/fxcrt/bytestring.h
@@ -23,7 +23,6 @@
 #include "core/fxcrt/string_view_template.h"
 #include "third_party/abseil-cpp/absl/types/optional.h"
 #include "third_party/base/check.h"
-#include "third_party/base/compiler_specific.h"
 #include "third_party/base/span.h"
 
 namespace fxcrt {
@@ -36,11 +35,10 @@
   using const_iterator = const CharType*;
   using const_reverse_iterator = std::reverse_iterator<const_iterator>;
 
-  static ByteString FormatInteger(int i) WARN_UNUSED_RESULT;
-  static ByteString FormatFloat(float f) WARN_UNUSED_RESULT;
-  static ByteString Format(const char* pFormat, ...) WARN_UNUSED_RESULT;
-  static ByteString FormatV(const char* pFormat,
-                            va_list argList) WARN_UNUSED_RESULT;
+  [[nodiscard]] static ByteString FormatInteger(int i);
+  [[nodiscard]] static ByteString FormatFloat(float f);
+  [[nodiscard]] static ByteString Format(const char* pFormat, ...);
+  [[nodiscard]] static ByteString FormatV(const char* pFormat, va_list argList);
 
   ByteString();
   ByteString(const ByteString& other);
diff --git a/core/fxcrt/fx_stream.h b/core/fxcrt/fx_stream.h
index 46ebb60..f82b264 100644
--- a/core/fxcrt/fx_stream.h
+++ b/core/fxcrt/fx_stream.h
@@ -62,9 +62,9 @@
   virtual FX_FILESIZE GetPosition();
   virtual size_t ReadBlock(void* buffer, size_t size);
 
-  virtual bool ReadBlockAtOffset(void* buffer,
-                                 FX_FILESIZE offset,
-                                 size_t size) WARN_UNUSED_RESULT = 0;
+  [[nodiscard]] virtual bool ReadBlockAtOffset(void* buffer,
+                                               FX_FILESIZE offset,
+                                               size_t size) = 0;
 };
 
 class IFX_SeekableStream : public IFX_SeekableReadStream,
diff --git a/core/fxcrt/widestring.h b/core/fxcrt/widestring.h
index e95033f..24774bd 100644
--- a/core/fxcrt/widestring.h
+++ b/core/fxcrt/widestring.h
@@ -22,7 +22,6 @@
 #include "core/fxcrt/string_view_template.h"
 #include "third_party/abseil-cpp/absl/types/optional.h"
 #include "third_party/base/check.h"
-#include "third_party/base/compiler_specific.h"
 #include "third_party/base/span.h"
 
 namespace fxcrt {
@@ -37,9 +36,9 @@
   using const_iterator = const CharType*;
   using const_reverse_iterator = std::reverse_iterator<const_iterator>;
 
-  static WideString Format(const wchar_t* pFormat, ...) WARN_UNUSED_RESULT;
-  static WideString FormatV(const wchar_t* lpszFormat,
-                            va_list argList) WARN_UNUSED_RESULT;
+  [[nodiscard]] static WideString Format(const wchar_t* pFormat, ...);
+  [[nodiscard]] static WideString FormatV(const wchar_t* lpszFormat,
+                                          va_list argList);
 
   WideString();
   WideString(const WideString& other);
@@ -66,16 +65,16 @@
 
   ~WideString();
 
-  static WideString FromASCII(ByteStringView str) WARN_UNUSED_RESULT;
-  static WideString FromLatin1(ByteStringView str) WARN_UNUSED_RESULT;
-  static WideString FromDefANSI(ByteStringView str) WARN_UNUSED_RESULT;
-  static WideString FromUTF8(ByteStringView str) WARN_UNUSED_RESULT;
-  static WideString FromUTF16LE(const unsigned short* str,
-                                size_t len) WARN_UNUSED_RESULT;
-  static WideString FromUTF16BE(const unsigned short* wstr,
-                                size_t wlen) WARN_UNUSED_RESULT;
+  [[nodiscard]] static WideString FromASCII(ByteStringView str);
+  [[nodiscard]] static WideString FromLatin1(ByteStringView str);
+  [[nodiscard]] static WideString FromDefANSI(ByteStringView str);
+  [[nodiscard]] static WideString FromUTF8(ByteStringView str);
+  [[nodiscard]] static WideString FromUTF16LE(const unsigned short* str,
+                                              size_t len);
+  [[nodiscard]] static WideString FromUTF16BE(const unsigned short* wstr,
+                                              size_t wlen);
 
-  static size_t WStringLength(const unsigned short* str) WARN_UNUSED_RESULT;
+  [[nodiscard]] static size_t WStringLength(const unsigned short* str);
 
   // Explicit conversion to C-style wide string.
   // Note: Any subsequent modification of |this| will invalidate the result.
diff --git a/fxjs/cjs_result.h b/fxjs/cjs_result.h
index d2265ac..a36a378 100644
--- a/fxjs/cjs_result.h
+++ b/fxjs/cjs_result.h
@@ -13,7 +13,7 @@
 
 class CJS_Result {
  public:
-  // Wrap constructors with static methods so we can apply WARN_UNUSED_RESULT,
+  // Wrap constructors with static methods so we can apply [[nodiscard]],
   // otherwise we can't catch places where someone mistakenly writes:
   //
   //     if (error)
@@ -24,14 +24,14 @@
   //     if (error)
   //       return CJS_Result(JS_ERROR_CODE);
   //
-  static CJS_Result Success() WARN_UNUSED_RESULT { return CJS_Result(); }
-  static CJS_Result Success(v8::Local<v8::Value> value) WARN_UNUSED_RESULT {
+  [[nodiscard]] static CJS_Result Success() { return CJS_Result(); }
+  [[nodiscard]] static CJS_Result Success(v8::Local<v8::Value> value) {
     return CJS_Result(value);
   }
-  static CJS_Result Failure(const WideString& str) WARN_UNUSED_RESULT {
+  [[nodiscard]] static CJS_Result Failure(const WideString& str) {
     return CJS_Result(str);
   }
-  static CJS_Result Failure(JSMessage id) WARN_UNUSED_RESULT {
+  [[nodiscard]] static CJS_Result Failure(JSMessage id) {
     return CJS_Result(id);
   }
 
diff --git a/third_party/base/allocator/partition_allocator/page_allocator.h b/third_party/base/allocator/partition_allocator/page_allocator.h
index b2eb7f6..bb3da8e 100644
--- a/third_party/base/allocator/partition_allocator/page_allocator.h
+++ b/third_party/base/allocator/partition_allocator/page_allocator.h
@@ -75,7 +75,7 @@
 //
 // Returns true if the permission change succeeded. In most cases you must
 // |CHECK| the result.
-BASE_EXPORT WARN_UNUSED_RESULT bool TrySetSystemPagesAccess(
+[[nodiscard]] BASE_EXPORT bool TrySetSystemPagesAccess(
     void* address,
     size_t length,
     PageAccessibilityConfiguration page_accessibility);
@@ -122,7 +122,7 @@
 //
 // Returns true if the recommit change succeeded. In most cases you must |CHECK|
 // the result.
-BASE_EXPORT WARN_UNUSED_RESULT bool RecommitSystemPages(
+[[nodiscard]] BASE_EXPORT bool RecommitSystemPages(
     void* address,
     size_t length,
     PageAccessibilityConfiguration page_accessibility);
diff --git a/third_party/base/allocator/partition_allocator/partition_page.h b/third_party/base/allocator/partition_allocator/partition_page.h
index 9eb136b..4e99753 100644
--- a/third_party/base/allocator/partition_allocator/partition_page.h
+++ b/third_party/base/allocator/partition_allocator/partition_page.h
@@ -77,8 +77,8 @@
 
   // Note the matching Alloc() functions are in PartitionPage.
   // Callers must invoke DeferredUnmap::Run() after releasing the lock.
-  BASE_EXPORT NOINLINE DeferredUnmap FreeSlowPath() WARN_UNUSED_RESULT;
-  ALWAYS_INLINE DeferredUnmap Free(void* ptr) WARN_UNUSED_RESULT;
+  [[nodiscard]] BASE_EXPORT NOINLINE DeferredUnmap FreeSlowPath();
+  [[nodiscard]] ALWAYS_INLINE DeferredUnmap Free(void* ptr);
 
   void Decommit(PartitionRootBase* root);
   void DecommitIfPossible(PartitionRootBase* root);
diff --git a/third_party/base/compiler_specific.h b/third_party/base/compiler_specific.h
index 705a8ac..7b3590c 100644
--- a/third_party/base/compiler_specific.h
+++ b/third_party/base/compiler_specific.h
@@ -70,17 +70,6 @@
 #define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment)))
 #endif
 
-// Annotate a function indicating the caller must examine the return value.
-// Use like:
-//   int foo() WARN_UNUSED_RESULT;
-// To explicitly ignore a result, see |ignore_result()| in base/macros.h.
-#undef WARN_UNUSED_RESULT
-#if defined(COMPILER_GCC) || defined(__clang__)
-#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
-#else
-#define WARN_UNUSED_RESULT
-#endif
-
 // Tell the compiler a function is using a printf-style format string.
 // |format_param| is the one-based index of the format string parameter;
 // |dots_param| is the one-based index of the "..." parameter.
diff --git a/xfa/fxfa/cxfa_ffcombobox.h b/xfa/fxfa/cxfa_ffcombobox.h
index c35a96a..dedbc28 100644
--- a/xfa/fxfa/cxfa_ffcombobox.h
+++ b/xfa/fxfa/cxfa_ffcombobox.h
@@ -28,7 +28,7 @@
   void UpdateWidgetProperty() override;
   bool OnRButtonUp(Mask<XFA_FWL_KeyFlag> dwFlags,
                    const CFX_PointF& point) override;
-  bool OnKillFocus(CXFA_FFWidget* pNewWidget) override WARN_UNUSED_RESULT;
+  [[nodiscard]] bool OnKillFocus(CXFA_FFWidget* pNewWidget) override;
   bool CanUndo() override;
   bool CanRedo() override;
   bool CanCopy() override;
diff --git a/xfa/fxfa/cxfa_fffield.h b/xfa/fxfa/cxfa_fffield.h
index 0ab8b62..868eb72 100644
--- a/xfa/fxfa/cxfa_fffield.h
+++ b/xfa/fxfa/cxfa_fffield.h
@@ -57,8 +57,8 @@
                    const CFX_PointF& point) override;
   bool OnRButtonDblClk(Mask<XFA_FWL_KeyFlag> dwFlags,
                        const CFX_PointF& point) override;
-  bool OnSetFocus(CXFA_FFWidget* pOldWidget) override WARN_UNUSED_RESULT;
-  bool OnKillFocus(CXFA_FFWidget* pNewWidget) override WARN_UNUSED_RESULT;
+  [[nodiscard]] bool OnSetFocus(CXFA_FFWidget* pOldWidget) override;
+  [[nodiscard]] bool OnKillFocus(CXFA_FFWidget* pNewWidget) override;
   bool OnKeyDown(XFA_FWL_VKEYCODE dwKeyCode,
                  Mask<XFA_FWL_KeyFlag> dwFlags) override;
   bool OnChar(uint32_t dwChar, Mask<XFA_FWL_KeyFlag> dwFlags) override;
diff --git a/xfa/fxfa/cxfa_fflistbox.h b/xfa/fxfa/cxfa_fflistbox.h
index 88a335f..ce700b3 100644
--- a/xfa/fxfa/cxfa_fflistbox.h
+++ b/xfa/fxfa/cxfa_fflistbox.h
@@ -23,7 +23,7 @@
   // CXFA_FFField:
   void Trace(cppgc::Visitor* visitor) const override;
   bool LoadWidget() override;
-  bool OnKillFocus(CXFA_FFWidget* pNewWidget) override WARN_UNUSED_RESULT;
+  [[nodiscard]] bool OnKillFocus(CXFA_FFWidget* pNewWidget) override;
   void OnProcessMessage(CFWL_Message* pMessage) override;
   void OnProcessEvent(CFWL_Event* pEvent) override;
   void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
diff --git a/xfa/fxfa/cxfa_fftextedit.h b/xfa/fxfa/cxfa_fftextedit.h
index fe56342..20cfbde 100644
--- a/xfa/fxfa/cxfa_fftextedit.h
+++ b/xfa/fxfa/cxfa_fftextedit.h
@@ -43,8 +43,8 @@
                      const CFX_PointF& point) override;
   bool OnRButtonUp(Mask<XFA_FWL_KeyFlag> dwFlags,
                    const CFX_PointF& point) override;
-  bool OnSetFocus(CXFA_FFWidget* pOldWidget) override WARN_UNUSED_RESULT;
-  bool OnKillFocus(CXFA_FFWidget* pNewWidget) override WARN_UNUSED_RESULT;
+  [[nodiscard]] bool OnSetFocus(CXFA_FFWidget* pOldWidget) override;
+  [[nodiscard]] bool OnKillFocus(CXFA_FFWidget* pNewWidget) override;
   void OnProcessMessage(CFWL_Message* pMessage) override;
   void OnProcessEvent(CFWL_Event* pEvent) override;
   void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
diff --git a/xfa/fxfa/cxfa_ffwidget.h b/xfa/fxfa/cxfa_ffwidget.h
index 3719a73..dac9ff0 100644
--- a/xfa/fxfa/cxfa_ffwidget.h
+++ b/xfa/fxfa/cxfa_ffwidget.h
@@ -109,31 +109,31 @@
       CFWL_MessageMouse::MouseCommand command);
 
   // Caution: Returning false from an On* method may mean |this| is destroyed.
-  virtual bool OnMouseEnter() WARN_UNUSED_RESULT;
-  virtual bool OnMouseExit() WARN_UNUSED_RESULT;
-  virtual bool OnLButtonDown(Mask<XFA_FWL_KeyFlag> dwFlags,
-                             const CFX_PointF& point) WARN_UNUSED_RESULT;
-  virtual bool OnLButtonUp(Mask<XFA_FWL_KeyFlag> dwFlags,
-                           const CFX_PointF& point) WARN_UNUSED_RESULT;
-  virtual bool OnLButtonDblClk(Mask<XFA_FWL_KeyFlag> dwFlags,
-                               const CFX_PointF& point) WARN_UNUSED_RESULT;
-  virtual bool OnMouseMove(Mask<XFA_FWL_KeyFlag> dwFlags,
-                           const CFX_PointF& point) WARN_UNUSED_RESULT;
-  virtual bool OnMouseWheel(Mask<XFA_FWL_KeyFlag> dwFlags,
-                            const CFX_PointF& point,
-                            const CFX_Vector& delta) WARN_UNUSED_RESULT;
-  virtual bool OnRButtonDown(Mask<XFA_FWL_KeyFlag> dwFlags,
-                             const CFX_PointF& point) WARN_UNUSED_RESULT;
-  virtual bool OnRButtonUp(Mask<XFA_FWL_KeyFlag> dwFlags,
-                           const CFX_PointF& point) WARN_UNUSED_RESULT;
-  virtual bool OnRButtonDblClk(Mask<XFA_FWL_KeyFlag> dwFlags,
-                               const CFX_PointF& point) WARN_UNUSED_RESULT;
-  virtual bool OnSetFocus(CXFA_FFWidget* pOldWidget) WARN_UNUSED_RESULT;
-  virtual bool OnKillFocus(CXFA_FFWidget* pNewWidget) WARN_UNUSED_RESULT;
-  virtual bool OnKeyDown(XFA_FWL_VKEYCODE dwKeyCode,
-                         Mask<XFA_FWL_KeyFlag> dwFlags) WARN_UNUSED_RESULT;
-  virtual bool OnChar(uint32_t dwChar,
-                      Mask<XFA_FWL_KeyFlag> dwFlags) WARN_UNUSED_RESULT;
+  [[nodiscard]] virtual bool OnMouseEnter();
+  [[nodiscard]] virtual bool OnMouseExit();
+  [[nodiscard]] virtual bool OnLButtonDown(Mask<XFA_FWL_KeyFlag> dwFlags,
+                                           const CFX_PointF& point);
+  [[nodiscard]] virtual bool OnLButtonUp(Mask<XFA_FWL_KeyFlag> dwFlags,
+                                         const CFX_PointF& point);
+  [[nodiscard]] virtual bool OnLButtonDblClk(Mask<XFA_FWL_KeyFlag> dwFlags,
+                                             const CFX_PointF& point);
+  [[nodiscard]] virtual bool OnMouseMove(Mask<XFA_FWL_KeyFlag> dwFlags,
+                                         const CFX_PointF& point);
+  [[nodiscard]] virtual bool OnMouseWheel(Mask<XFA_FWL_KeyFlag> dwFlags,
+                                          const CFX_PointF& point,
+                                          const CFX_Vector& delta);
+  [[nodiscard]] virtual bool OnRButtonDown(Mask<XFA_FWL_KeyFlag> dwFlags,
+                                           const CFX_PointF& point);
+  [[nodiscard]] virtual bool OnRButtonUp(Mask<XFA_FWL_KeyFlag> dwFlags,
+                                         const CFX_PointF& point);
+  [[nodiscard]] virtual bool OnRButtonDblClk(Mask<XFA_FWL_KeyFlag> dwFlags,
+                                             const CFX_PointF& point);
+  [[nodiscard]] virtual bool OnSetFocus(CXFA_FFWidget* pOldWidget);
+  [[nodiscard]] virtual bool OnKillFocus(CXFA_FFWidget* pNewWidget);
+  [[nodiscard]] virtual bool OnKeyDown(XFA_FWL_VKEYCODE dwKeyCode,
+                                       Mask<XFA_FWL_KeyFlag> dwFlags);
+  [[nodiscard]] virtual bool OnChar(uint32_t dwChar,
+                                    Mask<XFA_FWL_KeyFlag> dwFlags);
 
   virtual FWL_WidgetHit HitTest(const CFX_PointF& point);
   virtual bool CanUndo();