diff --git a/ci/Linux.bazelrc b/ci/Linux.bazelrc index fb91d049b8..354a7582c3 100644 --- a/ci/Linux.bazelrc +++ b/ci/Linux.bazelrc @@ -2,5 +2,6 @@ import common.bazelrc build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 build --cxxopt="-Woverloaded-virtual" +build --copt="-Wpointer-arith" build --copt="-Werror" --copt="-Wno-sign-compare" --copt="-Wno-sign-conversion" --copt="-Wno-error=sign-conversion" --copt="-Wno-deprecated-declarations" diff --git a/ci/macOS.bazelrc b/ci/macOS.bazelrc index 847810e8a4..2fd5a2a3db 100644 --- a/ci/macOS.bazelrc +++ b/ci/macOS.bazelrc @@ -2,6 +2,7 @@ import common.bazelrc build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 build --cxxopt="-Woverloaded-virtual" +build --copt="-Wpointer-arith" build --copt="-Werror" --copt="-Wno-sign-compare" --copt="-Wno-sign-conversion" --copt="-Wno-error=sign-conversion" --copt="-Wno-deprecated-declarations" common --repo_env=BAZEL_NO_APPLE_CPP_TOOLCHAIN=1 common --xcode_version_config=@com_google_protobuf//.github:host_xcodes diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 1778672134..f05b62af89 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -84,7 +84,7 @@ using google::protobuf::io::win32::write; // Disable the whole test when we use tcmalloc for "draconian" heap checks, in // which case tcmalloc will print warnings that fail the plugin tests. -#if !GOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN +#if !defined(GOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN) namespace { diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h index 96a3091105..fa83a979bf 100644 --- a/src/google/protobuf/message_lite.h +++ b/src/google/protobuf/message_lite.h @@ -178,7 +178,7 @@ class PROTOBUF_EXPORT CachedSize { // NOLINTNEXTLINE(google-explicit-constructor) constexpr CachedSize(Scalar desired) noexcept : atom_(desired) {} -#if PROTOBUF_BUILTIN_ATOMIC +#ifdef PROTOBUF_BUILTIN_ATOMIC constexpr CachedSize(const CachedSize& other) = default; Scalar Get() const noexcept { @@ -233,7 +233,7 @@ class PROTOBUF_EXPORT CachedSize { #endif private: -#if PROTOBUF_BUILTIN_ATOMIC +#ifdef PROTOBUF_BUILTIN_ATOMIC mutable Scalar atom_; #else mutable std::atomic atom_; diff --git a/upb/message/internal/message.c b/upb/message/internal/message.c index fea8822bc9..1ba26df582 100644 --- a/upb/message/internal/message.c +++ b/upb/message/internal/message.c @@ -85,7 +85,7 @@ bool UPB_PRIVATE(_upb_Message_EnsureAvailable)(struct upb_Message* msg, return true; } -#if UPB_TRACING_ENABLED +#ifdef UPB_TRACING_ENABLED static void (*_message_trace_handler)(const upb_MiniTable*, const upb_Arena*); void upb_Message_LogNewMessage(const upb_MiniTable* m, const upb_Arena* arena) { diff --git a/upb/mini_descriptor/decode.c b/upb/mini_descriptor/decode.c index 1094fc0435..c916f98c5a 100644 --- a/upb/mini_descriptor/decode.c +++ b/upb/mini_descriptor/decode.c @@ -742,7 +742,7 @@ static upb_MiniTable* upb_MtDecoder_DoBuildMiniTableWithBuf( decoder->table->UPB_PRIVATE(dense_below) = 0; decoder->table->UPB_PRIVATE(table_mask) = -1; decoder->table->UPB_PRIVATE(required_count) = 0; -#if UPB_TRACING_ENABLED +#ifdef UPB_TRACING_ENABLED // MiniTables built from MiniDescriptors will not be able to vend the message // name unless it is explicitly set with upb_MiniTable_SetFullName(). decoder->table->UPB_PRIVATE(full_name) = 0; diff --git a/upb/reflection/descriptor_bootstrap.h b/upb/reflection/descriptor_bootstrap.h index c0b760cfa1..0a7961d2af 100644 --- a/upb/reflection/descriptor_bootstrap.h +++ b/upb/reflection/descriptor_bootstrap.h @@ -6,7 +6,7 @@ #if defined(UPB_BOOTSTRAP_STAGE) && UPB_BOOTSTRAP_STAGE == 0 // This header is checked in. #include "upb/reflection/stage0/google/protobuf/descriptor.upb.h" -#elif UPB_BOOTSTRAP_STAGE == 1 +#elif defined(UPB_BOOTSTRAP_STAGE) && UPB_BOOTSTRAP_STAGE == 1 // This header is generated at build time by the bootstrapping process. #include "upb/reflection/stage1/google/protobuf/descriptor.upb.h" #else diff --git a/upb_generator/plugin_bootstrap.h b/upb_generator/plugin_bootstrap.h index 87afc06fbb..da9fe6875a 100644 --- a/upb_generator/plugin_bootstrap.h +++ b/upb_generator/plugin_bootstrap.h @@ -6,7 +6,7 @@ #if defined(UPB_BOOTSTRAP_STAGE) && UPB_BOOTSTRAP_STAGE == 0 // This header is checked in. #include "upb_generator/stage0/google/protobuf/compiler/plugin.upb.h" -#elif UPB_BOOTSTRAP_STAGE == 1 +#elif defined(UPB_BOOTSTRAP_STAGE) && UPB_BOOTSTRAP_STAGE == 1 // This header is generated at build time by the bootstrapping process. #include "upb_generator/stage1/google/protobuf/compiler/plugin.upb.h" #else