Merge pull request #8859 from tamird/warnings
Disallow missing field initializers
diff --git a/BUILD b/BUILD
index f9261ab..0c5054b 100644
--- a/BUILD
+++ b/BUILD
@@ -48,6 +48,7 @@
"//conditions:default": [
"-DHAVE_PTHREAD",
"-DHAVE_ZLIB",
+ "-Wmissing-field-initializers",
"-Woverloaded-virtual",
"-Wno-sign-compare",
],
diff --git a/src/google/protobuf/arena_impl.h b/src/google/protobuf/arena_impl.h
index 40608df..9035581 100644
--- a/src/google/protobuf/arena_impl.h
+++ b/src/google/protobuf/arena_impl.h
@@ -206,13 +206,15 @@
// Blocks are variable length malloc-ed objects. The following structure
// describes the common header for all blocks.
struct Block {
+ Block(Block* next, size_t size) : next(next), size(size), start(nullptr) {}
+
char* Pointer(size_t n) {
GOOGLE_DCHECK(n <= size);
return reinterpret_cast<char*>(this) + n;
}
- Block* next;
- size_t size;
+ Block* const next;
+ const size_t size;
CleanupNode* start;
// data follows
};
diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc
index c25de21..86f8f91 100644
--- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc
@@ -1130,7 +1130,7 @@
MessageAnalysis MessageSCCAnalyzer::GetSCCAnalysis(const SCC* scc) {
if (analysis_cache_.count(scc)) return analysis_cache_[scc];
- MessageAnalysis result{};
+ MessageAnalysis result;
if (UsingImplicitWeakFields(scc->GetFile(), options_)) {
result.contains_weak = true;
}
diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.h b/src/google/protobuf/compiler/cpp/cpp_helpers.h
index 8c07e47..eda1047 100644
--- a/src/google/protobuf/compiler/cpp/cpp_helpers.h
+++ b/src/google/protobuf/compiler/cpp/cpp_helpers.h
@@ -545,11 +545,11 @@
}
struct MessageAnalysis {
- bool is_recursive;
- bool contains_cord;
- bool contains_extension;
- bool contains_required;
- bool contains_weak; // Implicit weak as well.
+ bool is_recursive = false;
+ bool contains_cord = false;
+ bool contains_extension = false;
+ bool contains_required = false;
+ bool contains_weak = false; // Implicit weak as well.
};
// This class is used in FileGenerator, to ensure linear instead of
diff --git a/src/google/protobuf/io/tokenizer_unittest.cc b/src/google/protobuf/io/tokenizer_unittest.cc
index 91c440c..2233eb9 100644
--- a/src/google/protobuf/io/tokenizer_unittest.cc
+++ b/src/google/protobuf/io/tokenizer_unittest.cc
@@ -325,10 +325,7 @@
// last token in "output" must have type TYPE_END.
struct MultiTokenCase {
std::string input;
- Tokenizer::Token output[10]; // The compiler wants a constant array
- // size for initialization to work. There
- // is no reason this can't be increased if
- // needed.
+ std::vector<Tokenizer::Token> output;
};
inline std::ostream& operator<<(std::ostream& out,