Fixes to support building in C++20 mode.

* Add an explicit comparison-with-nullptr function to eliminate
  warning about ambiguous function calls.
* Various kinds of math with enums are deprecated; fix with explicit
  type conversions.
* Structs with user-declared constructors are no longer aggregates;
  supply an all-members constructor.

Bug: chromium:1284275
Change-Id: I265f7bd66a5066b2c265f7938415e54a111c0dba
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/93375
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
diff --git a/core/fxcrt/unowned_ptr.h b/core/fxcrt/unowned_ptr.h
index 6417c1d..76ebac1 100644
--- a/core/fxcrt/unowned_ptr.h
+++ b/core/fxcrt/unowned_ptr.h
@@ -5,6 +5,7 @@
 #ifndef CORE_FXCRT_UNOWNED_PTR_H_
 #define CORE_FXCRT_UNOWNED_PTR_H_
 
+#include <cstddef>
 #include <functional>
 #include <type_traits>
 #include <utility>
@@ -87,8 +88,8 @@
     return *this;
   }
 
+  bool operator==(std::nullptr_t ptr) const { return Get() == nullptr; }
   bool operator==(const UnownedPtr& that) const { return Get() == that.Get(); }
-  bool operator!=(const UnownedPtr& that) const { return !(*this == that); }
   bool operator<(const UnownedPtr& that) const {
     return std::less<T*>()(Get(), that.Get());
   }
diff --git a/third_party/agg23/0013-cxx20.patch b/third_party/agg23/0013-cxx20.patch
new file mode 100644
index 0000000..1a77349
--- /dev/null
+++ b/third_party/agg23/0013-cxx20.patch
@@ -0,0 +1,56 @@
+diff --git a/third_party/agg23/agg_basics.h b/third_party/agg23/agg_basics.h
+index e7583e308..84313db5b 100644
+--- a/third_party/agg23/agg_basics.h
++++ b/third_party/agg23/agg_basics.h
+@@ -216,7 +216,7 @@ inline bool is_close(unsigned c)
+ {
+     c &= ~path_flags_jr;
+     return (c & ~(path_flags_cw | path_flags_ccw)) ==
+-           (path_cmd_end_poly | path_flags_close);
++           (unsigned{path_cmd_end_poly} | path_flags_close);
+ }
+ inline bool is_next_poly(unsigned c)
+ {
+diff --git a/third_party/agg23/agg_path_storage.cpp b/third_party/agg23/agg_path_storage.cpp
+index 1491e9e33..2981e9c0c 100644
+--- a/third_party/agg23/agg_path_storage.cpp
++++ b/third_party/agg23/agg_path_storage.cpp
+@@ -98,7 +98,7 @@ void path_storage::end_poly()
+ {
+     if(m_total_vertices) {
+         if(is_vertex(command(m_total_vertices - 1))) {
+-            add_vertex(0, 0, path_cmd_end_poly | path_flags_close);
++            add_vertex(0, 0, unsigned{path_cmd_end_poly} | path_flags_close);
+         }
+     }
+ }
+diff --git a/third_party/agg23/agg_rasterizer_scanline_aa.h b/third_party/agg23/agg_rasterizer_scanline_aa.h
+index 133d66c4f..dd0d00076 100644
+--- a/third_party/agg23/agg_rasterizer_scanline_aa.h
++++ b/third_party/agg23/agg_rasterizer_scanline_aa.h
+@@ -49,7 +49,7 @@ enum poly_base_scale_e {
+ };
+ inline int poly_coord(float c)
+ {
+-    return int(c * poly_base_size);
++    return int(c * float{poly_base_size});
+ }
+ struct cell_aa  {
+     int x;
+diff --git a/third_party/agg23/agg_vcgen_stroke.cpp b/third_party/agg23/agg_vcgen_stroke.cpp
+index f65eac55f..b0f8a50e2 100644
+--- a/third_party/agg23/agg_vcgen_stroke.cpp
++++ b/third_party/agg23/agg_vcgen_stroke.cpp
+@@ -202,10 +202,10 @@ unsigned vcgen_stroke::vertex(float* x, float* y)
+                 break;
+             case end_poly1:
+                 m_status = m_prev_status;
+-                return path_cmd_end_poly | path_flags_close | path_flags_ccw;
++                return unsigned{path_cmd_end_poly} | path_flags_close | path_flags_ccw;
+             case end_poly2:
+                 m_status = m_prev_status;
+-                return path_cmd_end_poly | path_flags_close | path_flags_cw;
++                return unsigned{path_cmd_end_poly} | path_flags_close | path_flags_cw;
+             case stop:
+                 cmd = path_cmd_stop;
+                 break;
diff --git a/third_party/agg23/README.pdfium b/third_party/agg23/README.pdfium
index 645eb20..c372941 100644
--- a/third_party/agg23/README.pdfium
+++ b/third_party/agg23/README.pdfium
@@ -29,3 +29,4 @@
 0010-math.patch: includes <math.h>
 0011-path-storage-move-ctor.patch: Add a move ctor for path_storage.
 0012-infinite-loop.patch: Fix an infinite loop in calc_dash_start().
+0013-cxx20.patch: C++20 support.
diff --git a/third_party/agg23/agg_basics.h b/third_party/agg23/agg_basics.h
index e7583e3..84313db 100644
--- a/third_party/agg23/agg_basics.h
+++ b/third_party/agg23/agg_basics.h
@@ -216,7 +216,7 @@
 {
     c &= ~path_flags_jr;
     return (c & ~(path_flags_cw | path_flags_ccw)) ==
-           (path_cmd_end_poly | path_flags_close);
+           (unsigned{path_cmd_end_poly} | path_flags_close);
 }
 inline bool is_next_poly(unsigned c)
 {
diff --git a/third_party/agg23/agg_path_storage.cpp b/third_party/agg23/agg_path_storage.cpp
index 1491e9e..2981e9c 100644
--- a/third_party/agg23/agg_path_storage.cpp
+++ b/third_party/agg23/agg_path_storage.cpp
@@ -98,7 +98,7 @@
 {
     if(m_total_vertices) {
         if(is_vertex(command(m_total_vertices - 1))) {
-            add_vertex(0, 0, path_cmd_end_poly | path_flags_close);
+            add_vertex(0, 0, unsigned{path_cmd_end_poly} | path_flags_close);
         }
     }
 }
diff --git a/third_party/agg23/agg_rasterizer_scanline_aa.h b/third_party/agg23/agg_rasterizer_scanline_aa.h
index 133d66c..dd0d000 100644
--- a/third_party/agg23/agg_rasterizer_scanline_aa.h
+++ b/third_party/agg23/agg_rasterizer_scanline_aa.h
@@ -49,7 +49,7 @@
 };
 inline int poly_coord(float c)
 {
-    return int(c * poly_base_size);
+    return int(c * float{poly_base_size});
 }
 struct cell_aa  {
     int x;
diff --git a/third_party/agg23/agg_vcgen_stroke.cpp b/third_party/agg23/agg_vcgen_stroke.cpp
index f65eac5..b0f8a50 100644
--- a/third_party/agg23/agg_vcgen_stroke.cpp
+++ b/third_party/agg23/agg_vcgen_stroke.cpp
@@ -202,10 +202,10 @@
                 break;
             case end_poly1:
                 m_status = m_prev_status;
-                return path_cmd_end_poly | path_flags_close | path_flags_ccw;
+                return unsigned{path_cmd_end_poly} | path_flags_close | path_flags_ccw;
             case end_poly2:
                 m_status = m_prev_status;
-                return path_cmd_end_poly | path_flags_close | path_flags_cw;
+                return unsigned{path_cmd_end_poly} | path_flags_close | path_flags_cw;
             case stop:
                 cmd = path_cmd_stop;
                 break;
diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h
index 0bc03c7..ae0fb71 100644
--- a/xfa/fxfa/parser/cxfa_node.h
+++ b/xfa/fxfa/parser/cxfa_node.h
@@ -93,6 +93,12 @@
  public:
   struct PropertyData {
     PropertyData() = delete;
+    constexpr PropertyData(XFA_Element property,
+                           uint8_t occurrence_count,
+                           Mask<XFA_PropertyFlag> flags)
+        : property(property),
+          occurrence_count(occurrence_count),
+          flags(flags) {}
 
     XFA_Element property;
     uint8_t occurrence_count;