Commit 2413cb57 authored by Nobuaki Sukegawa's avatar Nobuaki Sukegawa

Make C++ string oneof field compatible with C++11

string oneof field was generated into "const ArenaStringPtr" field inside
"default_oneof_instance_" struct (of name "<class name>OneofInstance").

On the other hand, in C++11, const field of type with trivial default
constructor causes enclosing type's implicit default constructor to be deleted.

Since ArenaStringPtr has tirvial default constructor, this caused default
constructor of "default_oneof_instance_" struct to be deleted, making the
constructor call inside generated code invalid and fail to compile.
parent 4470dcba
......@@ -1226,7 +1226,7 @@ GenerateDescriptorDeclarations(io::Printer* printer) {
for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j);
printer->Print(" ");
if (IsStringOrMessage(field)) {
if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
printer->Print("const ");
}
field_generators_.get(field).GeneratePrivateMembers(printer);
......
......@@ -613,8 +613,7 @@ GenerateSwappingCode(io::Printer* printer) const {
void StringOneofFieldGenerator::
GenerateConstructorCode(io::Printer* printer) const {
printer->Print(variables_,
" const_cast< ::google::protobuf::internal::ArenaStringPtr*>("
"&$classname$_default_oneof_instance_->$name$_)->UnsafeSetDefault("
" $classname$_default_oneof_instance_->$name$_.UnsafeSetDefault("
"$default_variable$);\n");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment