Pass -Wno-return-type to GCC.

Remove several NOTREACHED() statements that were added specifically to
fix the GCC build, because GCC complains about the missing return value
even when a switch statement covers all the possible cases. Instead,
suppress the warning when building with GCC, just like in V8's build
configuration.

Change-Id: Icdfef5ce01538140e12027798495940025268c5f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/93254
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index 86dc11d..0cc37ba 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -231,8 +231,14 @@
   }
 
   if (!is_win && !is_clang) {
-    # Override -Wno-narrowing.
-    cflags += [ "-Wnarrowing" ]
+    cflags += [
+      # Override -Wno-narrowing for GCC.
+      "-Wnarrowing",
+
+      # GCC assumes that control can get past an exhaustive switch and then
+      # warns if there's no return there.
+      "-Wno-return-type",
+    ]
   }
 }
 
diff --git a/core/fpdfapi/font/cpdf_fontencoding.cpp b/core/fpdfapi/font/cpdf_fontencoding.cpp
index d2939c0..611a2b5 100644
--- a/core/fpdfapi/font/cpdf_fontencoding.cpp
+++ b/core/fpdfapi/font/cpdf_fontencoding.cpp
@@ -17,7 +17,6 @@
 #include "core/fxge/freetype/fx_freetype.h"
 #include "core/fxge/fx_font.h"
 #include "third_party/abseil-cpp/absl/types/optional.h"
-#include "third_party/base/notreached.h"
 
 namespace {
 
@@ -1778,8 +1777,6 @@
     case FontEncoding::kMsSymbol:
       return kMSSymbolEncoding;
   }
-  NOTREACHED();
-  return nullptr;
 }
 
 const char* CharNameFromPredefinedCharSet(FontEncoding encoding,
diff --git a/core/fpdfapi/parser/cpdf_security_handler.cpp b/core/fpdfapi/parser/cpdf_security_handler.cpp
index ae592d2..31c000b 100644
--- a/core/fpdfapi/parser/cpdf_security_handler.cpp
+++ b/core/fpdfapi/parser/cpdf_security_handler.cpp
@@ -83,10 +83,7 @@
       return keylen >= 5 && keylen <= 16;
     case CPDF_CryptoHandler::Cipher::kNone:
       return true;
-    default:
-      NOTREACHED();
   }
-  return false;
 }
 
 #define FX_GET_32WORD(n, b, i)                                        \
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp
index b0a4b6e..f69ed17 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.cpp
+++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp
@@ -39,7 +39,6 @@
 #include "core/fxge/dib/cfx_imagetransformer.h"
 #include "third_party/base/check.h"
 #include "third_party/base/cxx17_backports.h"
-#include "third_party/base/notreached.h"
 
 #if defined(_SKIA_SUPPORT_)
 #include "core/fxge/skia/fx_skia_device.h"
@@ -547,8 +546,6 @@
     case Mode::kTransform:
       return ContinueTransform(pPause);
   }
-  NOTREACHED();
-  return false;
 }
 
 bool CPDF_ImageRenderer::ContinueDefault(PauseIndicatorIface* pPause) {
diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp
index 8692699..8a2d269 100644
--- a/fpdfsdk/fpdf_editpage.cpp
+++ b/fpdfsdk/fpdf_editpage.cpp
@@ -38,7 +38,6 @@
 #include "fpdfsdk/cpdfsdk_helpers.h"
 #include "public/fpdf_formfill.h"
 #include "third_party/base/cxx17_backports.h"
-#include "third_party/base/notreached.h"
 #include "third_party/base/numerics/safe_conversions.h"
 
 #ifdef PDF_ENABLE_XFA
@@ -102,10 +101,6 @@
       pFormObj->CalcBoundingBox();
       break;
     }
-    default: {
-      NOTREACHED();
-      break;
-    }
   }
 }
 
@@ -647,9 +642,6 @@
     case CPDF_PageObject::Type::kForm:
       *matrix = FSMatrixFromCFXMatrix(pPageObj->AsForm()->form_matrix());
       return true;
-    default:
-      NOTREACHED();
-      return false;
   }
 }
 
@@ -675,9 +667,6 @@
     case CPDF_PageObject::Type::kForm:
       pPageObj->AsForm()->SetFormMatrix(cmatrix);
       break;
-    default:
-      NOTREACHED();
-      return false;
   }
   pPageObj->SetDirty(true);
   return true;
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
index c0f2917..d3e1e2a 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
@@ -27,7 +27,6 @@
 #include "fxjs/ijs_runtime.h"
 #include "public/fpdf_formfill.h"
 #include "third_party/base/check.h"
-#include "third_party/base/notreached.h"
 #include "v8/include/cppgc/allocation.h"
 #include "xfa/fgas/font/cfgas_gemodule.h"
 #include "xfa/fxfa/cxfa_eventparam.h"
@@ -204,8 +203,6 @@
     case FormType::kXFAFull:
       return m_pXFADoc ? m_pXFADocView->CountPageViews() : 0;
   }
-  NOTREACHED();
-  return 0;
 }
 
 RetainPtr<CPDFXFA_Page> CPDFXFA_Context::GetOrCreateXFAPage(int page_index) {
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp
index 4830001..907efb5 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp
@@ -15,7 +15,6 @@
 #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
 #include "fpdfsdk/fpdfxfa/cpdfxfa_widget.h"
 #include "third_party/base/check.h"
-#include "third_party/base/notreached.h"
 #include "xfa/fgas/graphics/cfgas_gegraphics.h"
 #include "xfa/fxfa/cxfa_ffdocview.h"
 #include "xfa/fxfa/cxfa_ffpageview.h"
@@ -118,8 +117,6 @@
     case FormType::kXFAFull:
       return !!GetXFAPageView();
   }
-  NOTREACHED();
-  return false;
 }
 
 void CPDFXFA_Page::LoadPDFPageFromDict(CPDF_Dictionary* pPageDict) {
diff --git a/fxjs/cjs_field.cpp b/fxjs/cjs_field.cpp
index a5ab1cd..2bd3eaa 100644
--- a/fxjs/cjs_field.cpp
+++ b/fxjs/cjs_field.cpp
@@ -199,8 +199,6 @@
                        pFormControl->GetOriginalColorComponent(2, entry),
                        pFormControl->GetOriginalColorComponent(3, entry));
   }
-  NOTREACHED();
-  return CFX_Color();
 }
 
 bool SetWidgetDisplayStatus(CPDFSDK_Widget* pWidget, int value) {
@@ -927,11 +925,6 @@
       return CJS_Result::Success(
           pRuntime->NewNumber(static_cast<int>(scale_method)));
   }
-
-  // Note this is deliberately not the default case for the switch statement
-  // above, so missing cases trigger compile time errors.
-  NOTREACHED();
-  return CJS_Result::Success();
 }
 
 CJS_Result CJS_Field::set_button_scale_when(CJS_Runtime* pRuntime,