Updated Branches: refs/heads/master f02934543 -> f8e8c5992
THRIFT-2105 Generated code for default values of collections ignores t_field::T_REQUIRED Client: cpp Patch: Vladimir Strisovsky Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/f8e8c599 Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/f8e8c599 Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/f8e8c599 Branch: refs/heads/master Commit: f8e8c599211fa0523b48fd0f5e8f0462c0e2b08a Parents: f029345 Author: Carl Yeksigian <[email protected]> Authored: Tue Aug 13 18:16:00 2013 -0400 Committer: Carl Yeksigian <[email protected]> Committed: Tue Aug 13 18:23:03 2013 -0400 ---------------------------------------------------------------------- compiler/cpp/src/generate/t_cpp_generator.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/f8e8c599/compiler/cpp/src/generate/t_cpp_generator.cc ---------------------------------------------------------------------- diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc index 99c1ace..523ce24 100644 --- a/compiler/cpp/src/generate/t_cpp_generator.cc +++ b/compiler/cpp/src/generate/t_cpp_generator.cc @@ -670,11 +670,14 @@ void t_cpp_generator::print_const_value(ofstream& out, string name, t_type* type vector<t_field*>::const_iterator f_iter; const map<t_const_value*, t_const_value*>& val = value->get_map(); map<t_const_value*, t_const_value*>::const_iterator v_iter; + bool is_nonrequired_field = false; for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) { t_type* field_type = NULL; + is_nonrequired_field = false; for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) { if ((*f_iter)->get_name() == v_iter->first->get_string()) { field_type = (*f_iter)->get_type(); + is_nonrequired_field = (*f_iter)->get_req() != t_field::T_REQUIRED; } } if (field_type == NULL) { @@ -682,7 +685,9 @@ void t_cpp_generator::print_const_value(ofstream& out, string name, t_type* type } string val = render_const_value(out, name, field_type, v_iter->second); indent(out) << name << "." << v_iter->first->get_string() << " = " << val << ";" << endl; - indent(out) << name << ".__isset." << v_iter->first->get_string() << " = true;" << endl; + if(is_nonrequired_field) { + indent(out) << name << ".__isset." << v_iter->first->get_string() << " = true;" << endl; + } } out << endl; } else if (type->is_map()) {
