Enable warnings as errors during tests (#10482)

* Enable warnings as errors by default for test builds

* Fixing C++ warnings

* Adding host flags, and enabling warnings as error for non-C++ too

* Switch to BUILD copts instead of bazelrc to treat Windows as a snowflake

* Disable warnings as errors on Windows, since it doesn't like the c++14 flag
diff --git a/.bazelrc b/.bazelrc
index 732859d..554440c 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -1 +1 @@
-build --cxxopt=-std=c++14
\ No newline at end of file
+build --cxxopt=-std=c++14 --host_cxxopt=-std=c++14
diff --git a/BUILD.bazel b/BUILD.bazel
index 9dd4bbd..67cd2db 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -160,6 +160,7 @@
 
 cc_binary(
     name = "protoc",
+    copts = COPTS,
     linkopts = LINK_OPTS + PROTOC_LINK_OPTS,
     visibility = ["//visibility:public"],
     deps = ["//src/google/protobuf/compiler:protoc_lib"],
diff --git a/build_defs/cpp_opts.bzl b/build_defs/cpp_opts.bzl
index f21b861..912c19b 100644
--- a/build_defs/cpp_opts.bzl
+++ b/build_defs/cpp_opts.bzl
@@ -19,6 +19,7 @@
         "-DHAVE_ZLIB",
         "-Woverloaded-virtual",
         "-Wno-sign-compare",
+        "-Werror",
     ],
 })
 
diff --git a/conformance/conformance_cpp.cc b/conformance/conformance_cpp.cc
index 95a0a00..6956285 100644
--- a/conformance/conformance_cpp.cc
+++ b/conformance/conformance_cpp.cc
@@ -87,7 +87,7 @@
 }
 
 absl::Status WriteFd(int fd, const void* buf, size_t len) {
-  if (write(fd, buf, len) != len) {
+  if (static_cast<size_t>(write(fd, buf, len)) != len) {
     return absl::ErrnoToStatus(errno, "error reading to test runner");
   }
   return absl::OkStatus();
diff --git a/src/google/protobuf/compiler/cpp/helpers.cc b/src/google/protobuf/compiler/cpp/helpers.cc
index 140c478..46d6f87 100644
--- a/src/google/protobuf/compiler/cpp/helpers.cc
+++ b/src/google/protobuf/compiler/cpp/helpers.cc
@@ -210,22 +210,6 @@
   return false;
 }
 
-// Describes different approaches to detect non-canonical int32 encoding. Only
-// kNever or kAlways is eligible for *simple* verification methods.
-enum class VerifyInt32Type {
-  kCustom,  // Only check if field number matches.
-  kNever,   // Do not check.
-  kAlways,  // Always check.
-};
-
-inline VerifySimpleType VerifyInt32TypeToVerifyCustom(VerifyInt32Type t) {
-  static VerifySimpleType kCustomTypes[] = {
-      VerifySimpleType::kCustom, VerifySimpleType::kCustomInt32Never,
-      VerifySimpleType::kCustomInt32Always};
-  return kCustomTypes[static_cast<int32_t>(t) -
-                      static_cast<int32_t>(VerifyInt32Type::kCustom)];
-}
-
 }  // namespace
 
 bool IsLazy(const FieldDescriptor* field, const Options& options,
diff --git a/src/google/protobuf/compiler/importer.cc b/src/google/protobuf/compiler/importer.cc
index d5eadf3..202210e 100644
--- a/src/google/protobuf/compiler/importer.cc
+++ b/src/google/protobuf/compiler/importer.cc
@@ -256,10 +256,6 @@
 
 DiskSourceTree::~DiskSourceTree() {}
 
-static inline char LastChar(const std::string& str) {
-  return str[str.size() - 1];
-}
-
 // Given a path, returns an equivalent path with these changes:
 // - On Windows, any backslashes are replaced with forward slashes.
 // - Any instances of the directory "." are removed.
diff --git a/src/google/protobuf/io/BUILD.bazel b/src/google/protobuf/io/BUILD.bazel
index 9364ed3..3c2b659 100644
--- a/src/google/protobuf/io/BUILD.bazel
+++ b/src/google/protobuf/io/BUILD.bazel
@@ -60,10 +60,7 @@
     name = "printer",
     srcs = ["printer.cc"],
     hdrs = ["printer.h"],
-    copts = COPTS + select({
-        "//build_defs:config_msvc": [],
-        "//conditions:default": ["-Wno-maybe-uninitialized"],
-    }),
+    copts = COPTS,
     include_prefix = "google/protobuf/io",
     deps = [
         ":io",
@@ -93,10 +90,7 @@
     name = "gzip_stream",
     srcs = ["gzip_stream.cc"],
     hdrs = ["gzip_stream.h"],
-    copts = COPTS + select({
-        "//build_defs:config_msvc": [],
-        "//conditions:default": ["-Wno-maybe-uninitialized"],
-    }),
+    copts = COPTS,
     include_prefix = "google/protobuf/io",
     deps = [
         ":io",
@@ -128,10 +122,7 @@
         "tokenizer_unittest.cc",
         "zero_copy_stream_unittest.cc",
     ],
-    copts = COPTS + select({
-        "//build_defs:config_msvc": [],
-        "//conditions:default": ["-Wno-maybe-uninitialized"],
-    }),
+    copts = COPTS,
     data = [
         "//src/google/protobuf:testdata",
     ],
diff --git a/src/google/protobuf/util/internal/expecting_objectwriter.h b/src/google/protobuf/util/internal/expecting_objectwriter.h
index b763f70..c14b87b 100644
--- a/src/google/protobuf/util/internal/expecting_objectwriter.h
+++ b/src/google/protobuf/util/internal/expecting_objectwriter.h
@@ -218,8 +218,8 @@
         .RetiresOnSaturation();
     return this;
   }
-  virtual ObjectWriter* RenderBytes(absl::string_view name,
-                                    absl::string_view value) {
+  ObjectWriter* RenderBytes(absl::string_view name,
+                            absl::string_view value) override {
     (name.empty() ? EXPECT_CALL(*mock_, RenderBytes(IsEmpty(),
                                                     TypedEq<absl::string_view>(
                                                         std::string(value))))