From a70986fc34428c665ffadd602aae6a69ceeb418e Mon Sep 17 00:00:00 2001 From: Roger Meier Date: Tue, 21 Oct 2014 23:01:36 +0200 Subject: [PATCH] THRIFT-2784 Eliminate compiler warnings in generated C++ code Patch: Roger Meier --- compiler/cpp/src/generate/t_as3_generator.cc | 6 ++--- .../cpp/src/generate/t_c_glib_generator.cc | 12 +++++----- compiler/cpp/src/generate/t_d_generator.cc | 2 +- .../cpp/src/generate/t_delphi_generator.cc | 15 ++++++++++--- compiler/cpp/src/generate/t_go_generator.cc | 22 ++++++++++++++----- compiler/cpp/src/generate/t_html_generator.cc | 3 ++- compiler/cpp/src/generate/t_java_generator.cc | 11 ++++++++-- compiler/cpp/src/generate/t_json_generator.cc | 3 +++ compiler/cpp/src/generate/t_lua_generator.cc | 3 +++ compiler/cpp/src/generate/t_php_generator.cc | 5 +++-- compiler/cpp/src/parse/t_program.h | 2 +- 11 files changed, 60 insertions(+), 24 deletions(-) diff --git a/compiler/cpp/src/generate/t_as3_generator.cc b/compiler/cpp/src/generate/t_as3_generator.cc index 42486d67f..e84ab0de0 100644 --- a/compiler/cpp/src/generate/t_as3_generator.cc +++ b/compiler/cpp/src/generate/t_as3_generator.cc @@ -215,7 +215,7 @@ class t_as3_generator : public t_oop_generator { std::ofstream f_service_; std::string package_dir_; - bool bindable_; + bool bindable_; }; @@ -332,8 +332,8 @@ string t_as3_generator::as3_thrift_gen_imports(t_service* tservice) { } } - as3_thrift_gen_imports((*f_iter)->get_arglist(), imports); - as3_thrift_gen_imports((*f_iter)->get_xceptions(), imports); + as3_thrift_gen_imports((*f_iter)->get_arglist(), imports); + as3_thrift_gen_imports((*f_iter)->get_xceptions(), imports); } diff --git a/compiler/cpp/src/generate/t_c_glib_generator.cc b/compiler/cpp/src/generate/t_c_glib_generator.cc index 26c337494..e1431718a 100644 --- a/compiler/cpp/src/generate/t_c_glib_generator.cc +++ b/compiler/cpp/src/generate/t_c_glib_generator.cc @@ -3506,12 +3506,12 @@ void t_c_glib_generator::generate_object(t_struct *tstruct) { if (t->is_map() || t->is_set()) { f_types_impl_ << indent() << "if (tobject->" << name << " != NULL)" << endl; f_types_impl_ << indent() << "{" << endl; - indent_up(); - f_types_impl_ << - indent() << "g_hash_table_destroy (tobject->" << name << ");" << endl; - f_types_impl_ << indent() << "tobject->" << name << " = NULL;" << endl; - indent_down(); - f_types_impl_ << indent() << "}" << endl; + indent_up(); + f_types_impl_ << + indent() << "g_hash_table_destroy (tobject->" << name << ");" << endl; + f_types_impl_ << indent() << "tobject->" << name << " = NULL;" << endl; + indent_down(); + f_types_impl_ << indent() << "}" << endl; } else if (t->is_list()) { t_type *etype = ((t_list *) t)->get_elem_type(); string destructor_function = "g_ptr_array_unref"; diff --git a/compiler/cpp/src/generate/t_d_generator.cc b/compiler/cpp/src/generate/t_d_generator.cc index ecf908bdd..c23aa1fda 100644 --- a/compiler/cpp/src/generate/t_d_generator.cc +++ b/compiler/cpp/src/generate/t_d_generator.cc @@ -743,7 +743,7 @@ class t_d_generator : public t_oop_generator { ss << "Compiler error: Invalid requirement level " << req; throw ss.str(); } - + } } diff --git a/compiler/cpp/src/generate/t_delphi_generator.cc b/compiler/cpp/src/generate/t_delphi_generator.cc index 81853918c..35b8da97c 100644 --- a/compiler/cpp/src/generate/t_delphi_generator.cc +++ b/compiler/cpp/src/generate/t_delphi_generator.cc @@ -57,7 +57,10 @@ class t_delphi_generator : public t_oop_generator : t_oop_generator(program) { (void) option_string; - + indent_impl_ = 0; + has_forward = false; + has_enum = false; + has_const = false; std::map::const_iterator iter; iter = parsed_options.find("ansistr_binary"); @@ -1338,7 +1341,7 @@ void t_delphi_generator::print_delphi_struct_type_factory_func( ostream& out, t void t_delphi_generator::generate_delphi_struct_type_factory( ostream& out, string cls_prefix, t_struct* tstruct, bool is_exception, bool is_result, bool is_x_factory) { - + (void) cls_prefix; if (is_exception) return; if (is_result) @@ -1362,6 +1365,7 @@ void t_delphi_generator::generate_delphi_struct_type_factory( ostream& out, stri } void t_delphi_generator::generate_delphi_struct_type_factory_registration( ostream& out, string cls_prefix, t_struct* tstruct, bool is_exception, bool is_result, bool is_x_factory) { + (void) cls_prefix; if (is_exception) return; if (is_result) @@ -2952,8 +2956,13 @@ void t_delphi_generator::generate_delphi_isset_reader_definition(ostream& out, t indent(out) << "function Get__isset_" << prop_name( tfield, is_xception) << ": Boolean;" << endl; } -void t_delphi_generator::generate_delphi_clear_union_value(ostream& out, std::string cls_prefix, std::string name, t_type* type, t_field* tfield, std::string fieldPrefix, bool is_xception_class, bool is_union, bool is_xception_factory, std::string xception_factroy_name) { +void t_delphi_generator::generate_delphi_clear_union_value(ostream& out, std::string cls_prefix, std::string name, t_type* type, t_field* tfield, std::string fieldPrefix, bool is_xception_class, bool is_union, bool is_xception_factory, std::string xception_factory_name) { + (void) cls_prefix; + (void) name; (void) type; + (void) is_union; + (void) is_xception_factory; + (void) xception_factory_name; t_type * ftype = tfield->get_type(); bool is_xception = ftype->is_xception(); diff --git a/compiler/cpp/src/generate/t_go_generator.cc b/compiler/cpp/src/generate/t_go_generator.cc index 54ad88733..36a4e3697 100644 --- a/compiler/cpp/src/generate/t_go_generator.cc +++ b/compiler/cpp/src/generate/t_go_generator.cc @@ -73,7 +73,8 @@ public: const std::map& parsed_options, const std::string& option_string) : t_generator(program) { - std::map::const_iterator iter; + (void) option_string; + std::map::const_iterator iter; out_dir_base_ = "gen-go"; gen_thrift_import_ = default_thrift_import; @@ -344,6 +345,7 @@ static bool type_need_reference(t_type* type) { //returns false if field could not use comparison to default value as !IsSet* bool t_go_generator::is_pointer_field(t_field* tfield, bool in_container_value) { + (void) in_container_value; if (tfield->annotations_.count("cpp.ref")!=0) { return true; } @@ -1250,6 +1252,7 @@ void t_go_generator::generate_isset_helpers(ofstream& out, const string& tstruct_name, bool is_result) { + (void) is_result; const vector& fields = tstruct->get_members(); vector::const_iterator f_iter; const string escaped_tstruct_name(escape_string(tstruct->get_name())); @@ -1292,7 +1295,8 @@ void t_go_generator::generate_go_struct_reader(ofstream& out, const string& tstruct_name, bool is_result) { - const vector& fields = tstruct->get_members(); + (void) is_result; + const vector& fields = tstruct->get_members(); vector::const_iterator f_iter; string escaped_tstruct_name(escape_string(tstruct->get_name())); out << @@ -1416,7 +1420,8 @@ void t_go_generator::generate_go_struct_writer(ofstream& out, const string& tstruct_name, bool is_result) { - string name(tstruct->get_name()); + (void) is_result; + string name(tstruct->get_name()); const vector& fields = tstruct->get_sorted_members(); vector::const_iterator f_iter; indent(out) << @@ -2627,7 +2632,9 @@ void t_go_generator::generate_deserialize_field(ofstream &out, bool inkey, bool in_container_value) { - t_type* orig_type = tfield->get_type(); + (void) inclass; + (void) coerceData; + t_type* orig_type = tfield->get_type(); t_type* type = get_true_type(orig_type); string name(prefix + publicize(variable_name_to_go_name(tfield->get_name()))); @@ -2848,6 +2855,7 @@ void t_go_generator::generate_deserialize_map_element(ofstream &out, bool declare, string prefix) { + (void) declare; string key = tmp("_key"); string val = tmp("_val"); t_field fkey(tmap->get_key_type(), key); @@ -2869,6 +2877,7 @@ void t_go_generator::generate_deserialize_set_element(ofstream &out, bool declare, string prefix) { + (void) declare; string elem = tmp("_elem"); t_field felem(tset->get_elem_type(), elem); felem.set_req(t_field::T_OPT_IN_REQ_OUT); @@ -2885,6 +2894,7 @@ void t_go_generator::generate_deserialize_list_element(ofstream &out, bool declare, string prefix) { + (void) declare; string elem = tmp("_elem"); t_field felem(((t_list*)tlist)->get_elem_type(), elem); felem.set_req(t_field::T_OPT_IN_REQ_OUT); @@ -2997,6 +3007,7 @@ void t_go_generator::generate_serialize_struct(ofstream &out, t_struct* tstruct, string prefix) { + (void) tstruct; out << indent() << "if err := " << prefix << ".Write(oprot); err != nil {" << endl << indent() << " return fmt.Errorf(\"%T error writing struct: %s\", " << prefix << ", err)" << endl << @@ -3428,7 +3439,8 @@ string t_go_generator::type_to_go_type(t_type* type, bool is_container_value) { */ string t_go_generator::type_to_go_type_with_opt(t_type* type, bool optional_field, bool is_container_value) { - string maybe_pointer(optional_field ? "*" : ""); + (void) is_container_value; + string maybe_pointer(optional_field ? "*" : ""); if (type->is_base_type()) { t_base_type::t_base tbase = ((t_base_type*)type)->get_base(); diff --git a/compiler/cpp/src/generate/t_html_generator.cc b/compiler/cpp/src/generate/t_html_generator.cc index 8ac7ddb21..863272175 100644 --- a/compiler/cpp/src/generate/t_html_generator.cc +++ b/compiler/cpp/src/generate/t_html_generator.cc @@ -620,7 +620,7 @@ std::string t_html_generator::escape_html(std::string const & str) { } // some control code? - if( (0 <= ic) && (31 >= ic)) + if(ic <= 31) { switch( c) { @@ -764,6 +764,7 @@ void t_html_generator::print_const_value(t_type* type, t_const_value* tvalue) { break; default: f_out_ << "UNKNOWN BASE TYPE"; + break; } } else if (truetype->is_enum()) { f_out_ << escape_html(truetype->get_name()) << "." << escape_html(tvalue->get_identifier_name()); diff --git a/compiler/cpp/src/generate/t_java_generator.cc b/compiler/cpp/src/generate/t_java_generator.cc index ddf4c91c2..11b47545d 100644 --- a/compiler/cpp/src/generate/t_java_generator.cc +++ b/compiler/cpp/src/generate/t_java_generator.cc @@ -2414,10 +2414,15 @@ std::string t_java_generator::get_java_type_string(t_type* type) { case t_base_type::TYPE_I32 : return "org.apache.thrift.protocol.TType.I32"; break; case t_base_type::TYPE_I64 : return "org.apache.thrift.protocol.TType.I64"; break; case t_base_type::TYPE_DOUBLE : return "org.apache.thrift.protocol.TType.DOUBLE"; break; - default : throw std::runtime_error("Unknown thrift type \"" + type->get_name() + "\" passed to t_java_generator::get_java_type_string!"); break; // This should never happen! + default : + throw std::runtime_error("Unknown thrift type \"" + type->get_name() + "\" passed to t_java_generator::get_java_type_string!"); + return "Unknown thrift type \"" + type->get_name() + "\" passed to t_java_generator::get_java_type_string!"; + break; // This should never happen! } } else { - throw std::runtime_error("Unknown thrift type \"" + type->get_name() + "\" passed to t_java_generator::get_java_type_string!"); // This should never happen! + throw std::runtime_error("Unknown thrift type \"" + type->get_name() + "\" passed to t_java_generator::get_java_type_string!"); + return "Unknown thrift type \"" + type->get_name() + "\" passed to t_java_generator::get_java_type_string!"; + // This should never happen! } } @@ -3922,6 +3927,7 @@ string t_java_generator::function_signature_async(t_function* tfunction, bool us } string t_java_generator::async_function_call_arglist(t_function* tfunc, bool use_base_method, bool include_types) { + (void) use_base_method; std::string arglist = ""; if (tfunc->get_arglist()->get_members().size() > 0) { arglist = argument_list(tfunc->get_arglist(), include_types) + ", "; @@ -3959,6 +3965,7 @@ string t_java_generator::argument_list(t_struct* tstruct, bool include_types) { } string t_java_generator::async_argument_list(t_function* tfunct, t_struct* tstruct, t_type* ttype, bool include_types) { + (void) tfunct; (void) ttype; string result = ""; const vector& fields = tstruct->get_members(); diff --git a/compiler/cpp/src/generate/t_json_generator.cc b/compiler/cpp/src/generate/t_json_generator.cc index 14a2f89f7..290ffaa1f 100644 --- a/compiler/cpp/src/generate/t_json_generator.cc +++ b/compiler/cpp/src/generate/t_json_generator.cc @@ -51,6 +51,8 @@ public: const std::string& option_string) : t_generator(program) { + (void) parsed_options; + (void) option_string; out_dir_base_ = "gen-json"; } @@ -405,6 +407,7 @@ void t_json_generator::generate_field(t_field * field){ break; default: write_key("required", "false"); + break; } if (field->get_value()) write_key("default", get_const_value(field->get_value())); diff --git a/compiler/cpp/src/generate/t_lua_generator.cc b/compiler/cpp/src/generate/t_lua_generator.cc index 6acc6a99c..7303c216c 100644 --- a/compiler/cpp/src/generate/t_lua_generator.cc +++ b/compiler/cpp/src/generate/t_lua_generator.cc @@ -40,6 +40,7 @@ class t_lua_generator : public t_oop_generator { const std::string& option_string) : t_oop_generator(program) { + (void) option_string; std::map::const_iterator iter; iter = parsed_options.find("omit_requires"); @@ -1057,6 +1058,7 @@ void t_lua_generator::generate_serialize_field(ofstream &out, void t_lua_generator::generate_serialize_struct(ofstream &out, t_struct* tstruct, string prefix) { + (void) tstruct; indent(out) << prefix << ":write(oprot)" << endl; } @@ -1167,6 +1169,7 @@ string t_lua_generator::get_namespace(const t_program* program) { string t_lua_generator::function_signature(t_function* tfunction, string prefix) { + (void) prefix; std::string ret = tfunction->get_name() + "(" + argument_list(tfunction->get_arglist()) + ")"; return ret; diff --git a/compiler/cpp/src/generate/t_php_generator.cc b/compiler/cpp/src/generate/t_php_generator.cc index 0c34a13e2..ae57ec3ab 100644 --- a/compiler/cpp/src/generate/t_php_generator.cc +++ b/compiler/cpp/src/generate/t_php_generator.cc @@ -250,6 +250,7 @@ class t_php_generator : public t_oop_generator { //add a directory to allready existing namespace string php_namespace_directory(string directory, bool end = true) { + (void) directory; if(end) { return ";"; } else { @@ -413,8 +414,8 @@ void t_php_generator::init_generator() { package_dir_ = get_out_dir(); for (size_t i = 0; i < NSx.size(); ++i) { - package_dir_ = package_dir_ + "/" + NSx[i] + "/"; - MKDIR(package_dir_.c_str()); + package_dir_ = package_dir_ + "/" + NSx[i] + "/"; + MKDIR(package_dir_.c_str()); } // Make output file diff --git a/compiler/cpp/src/parse/t_program.h b/compiler/cpp/src/parse/t_program.h index 5cf273824..1536f81bc 100644 --- a/compiler/cpp/src/parse/t_program.h +++ b/compiler/cpp/src/parse/t_program.h @@ -89,7 +89,7 @@ class t_program : public t_doc { const std::string& get_out_path() const { return out_path_; } // Create gen-* dir accessor - const bool is_out_path_absolute() const { return out_path_is_absolute_; } + bool is_out_path_absolute() const { return out_path_is_absolute_; } // Name accessor const std::string& get_name() const { return name_; }