diff options
Diffstat (limited to 'src')
3 files changed, 45 insertions, 2 deletions
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.cc b/src/google/protobuf/compiler/objectivec/objectivec_file.cc index ccf5fbb4..7774058e 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.cc @@ -182,6 +182,10 @@ void FileGenerator::GenerateHeader(io::Printer *printer) { import_writer.Print(printer); } + // Note: + // deprecated-declarations suppression is only needed if some place in this + // proto file is something deprecated or if it references something from + // another file that is deprecated. printer->Print( "// @@protoc_insertion_point(imports)\n" "\n" @@ -292,14 +296,34 @@ void FileGenerator::GenerateSource(io::Printer *printer) { import_writer.Print(printer); } + bool includes_oneof = false; + for (vector<MessageGenerator *>::iterator iter = message_generators_.begin(); + iter != message_generators_.end(); ++iter) { + if ((*iter)->IncludesOneOfDefinition()) { + includes_oneof = true; + break; + } + } + + // Note: + // deprecated-declarations suppression is only needed if some place in this + // proto file is something deprecated or if it references something from + // another file that is deprecated. printer->Print( "// @@protoc_insertion_point(imports)\n" "\n" "#pragma clang diagnostic push\n" - "#pragma clang diagnostic ignored \"-Wdeprecated-declarations\"\n" - "\n"); + "#pragma clang diagnostic ignored \"-Wdeprecated-declarations\"\n"); + if (includes_oneof) { + // The generated code for oneof's uses direct ivar access, suppress the + // warning incase developer turn that on in the context they compile the + // generated code. + printer->Print( + "#pragma clang diagnostic ignored \"-Wdirect-ivar-access\"\n"); + } printer->Print( + "\n" "#pragma mark - $root_class_name$\n" "\n" "@implementation $root_class_name$\n\n", diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.cc b/src/google/protobuf/compiler/objectivec/objectivec_message.cc index bf272596..e1a78619 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.cc @@ -246,6 +246,22 @@ void MessageGenerator::DetermineForwardDeclarations(set<string>* fwd_decls) { } } +bool MessageGenerator::IncludesOneOfDefinition() const { + if (!oneof_generators_.empty()) { + return true; + } + + for (vector<MessageGenerator*>::const_iterator iter = + nested_message_generators_.begin(); + iter != nested_message_generators_.end(); ++iter) { + if ((*iter)->IncludesOneOfDefinition()) { + return true; + } + } + + return false; +} + void MessageGenerator::GenerateEnumHeader(io::Printer* printer) { for (vector<EnumGenerator*>::iterator iter = enum_generators_.begin(); iter != enum_generators_.end(); ++iter) { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.h b/src/google/protobuf/compiler/objectivec/objectivec_message.h index 8565e76f..910535ac 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.h @@ -66,6 +66,9 @@ class MessageGenerator { void GenerateExtensionRegistrationSource(io::Printer* printer); void DetermineForwardDeclarations(set<string>* fwd_decls); + // Checks if the message or a nested message includes a oneof definition. + bool IncludesOneOfDefinition() const; + private: void GenerateParseFromMethodsHeader(io::Printer* printer); |