Fix some superficial issues with GCC 4.9, MSVC, and CMake

pull/10729/head
Mike Kruskal 2 years ago
parent 5a95ef8fa2
commit b2e1d7d8a1
  1. 6
      build_defs/cpp_opts.bzl
  2. 16
      pkg/BUILD.bazel
  3. 27
      src/file_lists.cmake
  4. 14
      src/google/protobuf/arena.cc
  5. 2
      src/google/protobuf/arena_align.h
  6. 2
      src/google/protobuf/compiler/cpp/enum.cc
  7. 4
      src/google/protobuf/compiler/cpp/enum.h
  8. 11
      src/google/protobuf/json/BUILD.bazel
  9. 2
      src/google/protobuf/json/internal/lexer.cc
  10. 8
      src/google/protobuf/json/internal/writer.h
  11. 4
      src/google/protobuf/parse_context.h

@ -20,11 +20,9 @@ COPTS = select({
"-Woverloaded-virtual",
"-Wno-sign-compare",
"-Werror",
"-std=c++14", # Protobuf requires C++14.
],
}) + [
"-std=c++14", # Protobuf requires C++14.
]
})
# Android and MSVC builds do not need to link in a separate pthread library.
LINK_OPTS = select({
"//build_defs:config_android": [],

@ -340,6 +340,10 @@ cc_dist_library(
tags = ["manual"],
deps = [
"//src/google/protobuf:arena",
"//src/google/protobuf:arena_align",
"//src/google/protobuf:arena_allocation_policy",
"//src/google/protobuf:arena_cleanup",
"//src/google/protobuf:arena_config",
"//src/google/protobuf:protobuf_lite",
"//src/google/protobuf/io",
"//src/google/protobuf/io:io_win32",
@ -361,6 +365,10 @@ cc_dist_library(
"//src/google/protobuf:wkt_cc_proto",
"//src/google/protobuf:protobuf_nowkt",
"//src/google/protobuf:arena",
"//src/google/protobuf:arena_align",
"//src/google/protobuf:arena_allocation_policy",
"//src/google/protobuf:arena_cleanup",
"//src/google/protobuf:arena_config",
"//src/google/protobuf:protobuf_lite",
"//src/google/protobuf:port_def",
"//src/google/protobuf/compiler:importer",
@ -371,6 +379,14 @@ cc_dist_library(
"//src/google/protobuf/io:tokenizer",
"//src/google/protobuf/io:zero_copy_sink",
"//src/google/protobuf/json",
"//src/google/protobuf/json:descriptor_traits",
"//src/google/protobuf/json:lexer",
"//src/google/protobuf/json:message_path",
"//src/google/protobuf/json:parser",
"//src/google/protobuf/json:unparser",
"//src/google/protobuf/json:untyped_message",
"//src/google/protobuf/json:writer",
"//src/google/protobuf/json:zero_copy_buffered_stream",
"//src/google/protobuf/stubs",
"//src/google/protobuf/stubs:lite",
"//src/google/protobuf/util:delimited_message_util",

@ -24,6 +24,8 @@ set(libprotobuf_srcs
${protobuf_SOURCE_DIR}/src/google/protobuf/any.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/any_lite.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/arena.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/arena_align.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/arena_config.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/arenaz_sampler.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/importer.cc
@ -53,6 +55,13 @@ set(libprotobuf_srcs
${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_impl.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_impl_lite.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/lexer.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/message_path.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/parser.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/unparser.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/untyped_message.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/writer.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/zero_copy_buffered_stream.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/json/json.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/map.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/map_field.cc
@ -93,6 +102,9 @@ set(libprotobuf_hdrs
${protobuf_SOURCE_DIR}/src/google/protobuf/wrappers.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/any.h
${protobuf_SOURCE_DIR}/src/google/protobuf/arena.h
${protobuf_SOURCE_DIR}/src/google/protobuf/arena_align.h
${protobuf_SOURCE_DIR}/src/google/protobuf/arena_allocation_policy.h
${protobuf_SOURCE_DIR}/src/google/protobuf/arena_cleanup.h
${protobuf_SOURCE_DIR}/src/google/protobuf/arena_config.h
${protobuf_SOURCE_DIR}/src/google/protobuf/arena_impl.h
${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring.h
@ -129,6 +141,16 @@ set(libprotobuf_hdrs
${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream.h
${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_impl.h
${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_impl_lite.h
${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/descriptor_traits.h
${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/lexer.h
${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/message_path.h
${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/parser.h
${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/parser_traits.h
${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/unparser.h
${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/unparser_traits.h
${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/untyped_message.h
${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/writer.h
${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/zero_copy_buffered_stream.h
${protobuf_SOURCE_DIR}/src/google/protobuf/json/json.h
${protobuf_SOURCE_DIR}/src/google/protobuf/map.h
${protobuf_SOURCE_DIR}/src/google/protobuf/map_entry.h
@ -179,6 +201,8 @@ set(libprotobuf_hdrs
set(libprotobuf_lite_srcs
${protobuf_SOURCE_DIR}/src/google/protobuf/any_lite.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/arena.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/arena_align.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/arena_config.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/arenaz_sampler.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set.cc
@ -208,6 +232,9 @@ set(libprotobuf_lite_srcs
set(libprotobuf_lite_hdrs
${protobuf_SOURCE_DIR}/src/google/protobuf/any.h
${protobuf_SOURCE_DIR}/src/google/protobuf/arena.h
${protobuf_SOURCE_DIR}/src/google/protobuf/arena_align.h
${protobuf_SOURCE_DIR}/src/google/protobuf/arena_allocation_policy.h
${protobuf_SOURCE_DIR}/src/google/protobuf/arena_cleanup.h
${protobuf_SOURCE_DIR}/src/google/protobuf/arena_config.h
${protobuf_SOURCE_DIR}/src/google/protobuf/arena_impl.h
${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring.h

@ -56,14 +56,26 @@ namespace protobuf {
namespace internal {
namespace {
#if defined(__GNUC__) && __GNUC__ >= 5
// kSentryArenaBlock is used for arenas which can be referenced pre-main. So,
// constexpr is required.
constexpr ArenaBlock kSentryArenaBlock = {};
constexpr ArenaBlock kSentryArenaBlock;
ArenaBlock* SentryArenaBlock() {
// const_cast<> is okay as kSentryArenaBlock will never be mutated.
return const_cast<ArenaBlock*>(&kSentryArenaBlock);
}
#else
// TODO(b/248322260) Remove this once we're not using GCC 4.9 for tests.
// There is a compiler bug in this version that causes the above constexpr to
// fail. This version is no longer in our support window, but we use it in
// some of our aarch64 docker images.
ArenaBlock* SentryArenaBlock() {
static const ArenaBlock kSentryArenaBlock;
// const_cast<> is okay as kSentryArenaBlock will never be mutated.
return const_cast<ArenaBlock*>(&kSentryArenaBlock);
}
#endif
} // namespace

@ -110,7 +110,7 @@ struct ArenaAlignDefault {
struct ArenaAlign {
static constexpr bool IsDefault() { return false; };
size_t align = 8;
size_t align;
constexpr bool IsAligned(size_t n) const { return (n & (align - 1)) == 0; }

@ -97,7 +97,7 @@ EnumGenerator::ValueLimits EnumGenerator::ValueLimits::FromEnum(
}
}
return {min_desc, max_desc};
return EnumGenerator::ValueLimits{min_desc, max_desc};
}
EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor,

@ -82,8 +82,8 @@ class EnumGenerator {
friend class FileGenerator;
struct ValueLimits {
const EnumValueDescriptor* min = nullptr;
const EnumValueDescriptor* max = nullptr;
const EnumValueDescriptor* min;
const EnumValueDescriptor* max;
static ValueLimits FromEnum(const EnumDescriptor* descriptor);
};

@ -2,7 +2,8 @@ load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("//build_defs:cpp_opts.bzl", "COPTS")
package(default_visibility = [
"//src/google/protobuf/util:__subpackages__",
"//src/google/protobuf/json:__pkg__",
"//pkg:__pkg__",
])
licenses(["notice"])
@ -70,7 +71,6 @@ cc_library(
hdrs = ["internal/zero_copy_buffered_stream.h"],
copts = COPTS,
strip_include_prefix = "/src",
visibility = ["//visibility:private"],
deps = [
"//src/google/protobuf:port_def",
"//src/google/protobuf/io",
@ -101,7 +101,6 @@ cc_library(
hdrs = ["internal/untyped_message.h"],
copts = COPTS,
strip_include_prefix = "/src",
visibility = ["//visibility:private"],
deps = [
"//src/google/protobuf",
"//src/google/protobuf:port_def",
@ -124,7 +123,6 @@ cc_library(
hdrs = ["internal/lexer.h"],
copts = COPTS,
strip_include_prefix = "/src",
visibility = ["//visibility:private"],
deps = [
":message_path",
":zero_copy_buffered_stream",
@ -164,7 +162,6 @@ cc_library(
hdrs = ["internal/writer.h"],
copts = COPTS,
strip_include_prefix = "/src",
visibility = ["//visibility:private"],
deps = [
"//src/google/protobuf:port_def",
"//src/google/protobuf/io",
@ -180,7 +177,6 @@ cc_library(
hdrs = ["internal/descriptor_traits.h"],
copts = COPTS,
strip_include_prefix = "/src",
visibility = ["//visibility:private"],
deps = [
":lexer",
":untyped_message",
@ -207,7 +203,6 @@ cc_library(
],
copts = COPTS,
strip_include_prefix = "/src",
visibility = ["//visibility:private"],
deps = [
":descriptor_traits",
":lexer",
@ -242,7 +237,6 @@ cc_library(
],
copts = COPTS,
strip_include_prefix = "/src",
visibility = ["//visibility:private"],
deps = [
":descriptor_traits",
":untyped_message",
@ -266,7 +260,6 @@ cc_library(
hdrs = ["internal/message_path.h"],
copts = COPTS,
strip_include_prefix = "/src",
visibility = ["//visibility:private"],
deps = [
"//src/google/protobuf",
"@com_google_absl//absl/cleanup",

@ -79,7 +79,7 @@ void HardenAgainstHyrumsLaw(absl::string_view to_obfuscate, std::string& out) {
uint64_t state = absl::bit_cast<uintptr_t>(kAslrSeed) + kB +
kCounterSeed.fetch_add(1, std::memory_order_relaxed);
auto rng = [&state] {
auto rng = [&state, &kA, &kB] {
state = state * kA + kB;
return absl::rotr(static_cast<uint32_t>(((state >> 18) ^ state) >> 27),
state >> 59);

@ -80,7 +80,9 @@ struct WriterOptions {
template <typename Tuple, typename F, size_t... i>
void EachInner(const Tuple& value, F f, std::index_sequence<i...>) {
(void)(int[]){(f(std::get<i>(value)), 0)...}; // NOLINT(readability/braces)
int ignored[] =
{(f(std::get<i>(value)), 0)...}; // NOLINT(readability/braces)
(void)ignored;
}
// Executes f on each element of value.
@ -157,7 +159,7 @@ class JsonWriter {
template <typename... Ts>
void Write(Quoted<Ts...> val) {
Write('"');
Each(val.value, [this](auto x) { WriteQuoted(x); });
Each(val.value, [this](auto x) { this->WriteQuoted(x); });
Write('"');
}
@ -166,7 +168,7 @@ class JsonWriter {
// This bit of SFINAE avoids this function being called with one argument,
// so the other overloads of Write() can be picked up instead.
typename std::enable_if<sizeof...(Ts) != 1, void>::type {
Each(std::make_tuple(args...), [this](auto x) { Write(x); });
Each(std::make_tuple(args...), [this](auto x) { this->Write(x); });
}
void Whitespace(absl::string_view ws) {

@ -250,7 +250,9 @@ class PROTOBUF_EXPORT EpsCopyInputStream {
if (aliasing_ == kOnPatch) aliasing_ = kNoDelta;
return flat.data();
} else {
std::memcpy(buffer_, flat.data(), flat.size());
if (!flat.empty()) {
std::memcpy(buffer_, flat.data(), flat.size());
}
limit_ = 0;
limit_end_ = buffer_end_ = buffer_ + flat.size();
next_chunk_ = nullptr;

Loading…
Cancel
Save