Turn on -Wdeprecated-enum-enum-conversion in protobuf code, and fix existing warnings.

PiperOrigin-RevId: 497985362
pull/11390/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent b598b2dd1f
commit 81d90d1eab
  1. 4
      src/google/protobuf/compiler/cpp/parse_function_generator.cc
  2. 3
      src/google/protobuf/port_def.inc

@ -708,7 +708,9 @@ static void FormatFieldKind(Formatter& format,
const int rep_index = (type_card & fl::kRepMask) >> fl::kRepShift; const int rep_index = (type_card & fl::kRepMask) >> fl::kRepShift;
const int tv_index = (type_card & fl::kTvMask) >> fl::kTvShift; const int tv_index = (type_card & fl::kTvMask) >> fl::kTvShift;
format("("); // Use `0|` prefix to eagerly convert the enums to int to avoid enum-enum
// operations. They are deprecated in C++20.
format("(0 | ");
static constexpr const char* kFieldCardNames[] = {"Singular", "Optional", static constexpr const char* kFieldCardNames[] = {"Singular", "Optional",
"Repeated", "Oneof"}; "Repeated", "Oneof"};
static_assert((fl::kFcSingular >> fl::kFcShift) == 0, ""); static_assert((fl::kFcSingular >> fl::kFcShift) == 0, "");

@ -971,6 +971,9 @@ static_assert(PROTOBUF_CPLUSPLUS_MIN(201402L), "Protobuf only supports C++14 and
// char* p = strchr(s, '\n'); // char* p = strchr(s, '\n');
// return p ? p - s : -1; // return p ? p - s : -1;
#pragma clang diagnostic ignored "-Wshorten-64-to-32" #pragma clang diagnostic ignored "-Wshorten-64-to-32"
// Turn on -Wdeprecated-enum-enum-conversion. This deprecation comes in C++20
// via http://wg21.link/p1120r0.
#pragma clang diagnostic error "-Wdeprecated-enum-enum-conversion"
#endif #endif
#ifdef __GNUC__ #ifdef __GNUC__
#pragma GCC diagnostic push #pragma GCC diagnostic push

Loading…
Cancel
Save