From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23196 invoked by alias); 27 Nov 2009 10:41:02 -0000 Received: (qmail 23177 invoked by uid 22791); 27 Nov 2009 10:41:00 -0000 X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL,BAYES_50,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 27 Nov 2009 10:40:54 +0000 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nARAekRh007542 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 27 Nov 2009 05:40:47 -0500 Received: from hs20-bc2-1.build.redhat.com (hs20-bc2-1.build.redhat.com [10.10.28.34]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nARAej1Z011782 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 27 Nov 2009 05:40:46 -0500 Received: from hs20-bc2-1.build.redhat.com (localhost.localdomain [127.0.0.1]) by hs20-bc2-1.build.redhat.com (8.13.1/8.13.1) with ESMTP id nARAejwt016401; Fri, 27 Nov 2009 05:40:45 -0500 Received: (from jakub@localhost) by hs20-bc2-1.build.redhat.com (8.13.1/8.13.1/Submit) id nARAej5P016397; Fri, 27 Nov 2009 05:40:45 -0500 Date: Fri, 27 Nov 2009 10:42:00 -0000 From: Jakub Jelinek To: Jason Merrill , Mark Mitchell Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix set but not used warnings in C++ FE Message-ID: <20091127104045.GW22813@hs20-bc2-1.build.redhat.com> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2009-11/txt/msg01525.txt.bz2 Hi! This patch fixes set but not used warnings in C++ FE. Most cases are quite obvious, though I'd appreciate if you could go through these and tell whether in some cases it wasn't just a bug that the variables aren't used anywhere and instead of dropping the variable we should actually use it. The build_vec_init change I'm particularly unsure about, size_in_bytes has side-effects (diagnosing incomplete types), I wonder if we need to preserve the call or if incomplete type in the build_vec_init case will be already diagnosed earlier. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2009-11-27 Jakub Jelinek * g++spec.c (lang_specific_driver): Remove unused saw_verbose_flag variable. * pt.c (tsubst_pack_expansion): Remove unused first_arg_pack variable. * init.c (build_vec_init): Remove unused size variable. * typeck2.c (check_narrowing): Remove unused was_decl variable. * decl.c (poplevel): Remove unused tmp and real_functionbody variables. (decls_match): Remove unused tree_name variable. (start_decl): Remove unused type variable. * parser.c (cp_parser_type_parameter): Remove unused parameter_list variable. (cp_parser_template_id, cp_parser_explicit_instantiation, cp_parser_declarator): Remove unused token variable. (cp_parser_simple_type_specifier): Remove unused id variable. (cp_parser_parameter_declaration): Remove unused greater_than_is_operator_p variable. (cp_parser_check_declarator_template_parameters): Remove unused member variable. (c_parse_file): Remove unused error_occurred variable. * cp-gimplify.c (cp_gimplify_init_expr): Remove unused slot variable. * typeck.c (cp_build_function_call_vec): Remove unused name variable. * class.c (resolve_address_of_overloaded_function): Remove unused is_reference variable. (build_rtti_vtbl_entries): Remove unused basetype variable. * mangle.c (write_template_param): Remove unused parm_level and parm_type variables. --- gcc/cp/g++spec.c.jj 2009-07-03 11:14:44.000000000 +0200 +++ gcc/cp/g++spec.c 2009-11-26 17:36:35.000000000 +0100 @@ -59,9 +59,6 @@ lang_specific_driver (int *in_argc, cons /* If nonzero, the user gave us the `-p' or `-pg' flag. */ int saw_profile_flag = 0; - /* If nonzero, the user gave us the `-v' flag. */ - int saw_verbose_flag = 0; - /* What do with libstdc++: -1 means we should not link in libstdc++ 0 means we should link in libstdc++ if it is needed @@ -153,8 +150,6 @@ lang_specific_driver (int *in_argc, cons args[i] |= WITHLIBC; else if (strcmp (argv[i], "-pg") == 0 || strcmp (argv[i], "-p") == 0) saw_profile_flag++; - else if (strcmp (argv[i], "-v") == 0) - saw_verbose_flag = 1; else if (strncmp (argv[i], "-x", 2) == 0) { const char * arg; --- gcc/cp/pt.c.jj 2009-11-25 10:50:09.000000000 +0100 +++ gcc/cp/pt.c 2009-11-26 17:36:35.000000000 +0100 @@ -7993,7 +7993,7 @@ tsubst_pack_expansion (tree t, tree args { tree pattern; tree pack, packs = NULL_TREE, unsubstituted_packs = NULL_TREE; - tree first_arg_pack; int i, len = -1; + int i, len = -1; tree result; int incomplete = 0; bool very_local_specializations = false; @@ -8077,10 +8077,7 @@ tsubst_pack_expansion (tree t, tree args incomplete = 1; if (len < 0) - { - len = my_len; - first_arg_pack = arg_pack; - } + len = my_len; else if (len != my_len) { if (incomplete) --- gcc/cp/init.c.jj 2009-11-13 11:13:20.000000000 +0100 +++ gcc/cp/init.c 2009-11-26 17:36:35.000000000 +0100 @@ -2666,7 +2666,6 @@ build_vec_init (tree base, tree maxindex { tree rval; tree base2 = NULL_TREE; - tree size; tree itype = NULL_TREE; tree iterator; /* The type of BASE. */ @@ -2724,7 +2723,7 @@ build_vec_init (tree base, tree maxindex } maxindex = cp_convert (ptrdiff_type_node, maxindex); - size = size_in_bytes (type); + size_in_bytes (type); if (TREE_CODE (atype) == ARRAY_TYPE) { ptype = build_pointer_type (type); --- gcc/cp/typeck2.c.jj 2009-11-23 13:04:26.000000000 +0100 +++ gcc/cp/typeck2.c 2009-11-26 17:36:35.000000000 +0100 @@ -655,13 +655,9 @@ check_narrowing (tree type, tree init) tree ftype = unlowered_expr_type (init); bool ok = true; REAL_VALUE_TYPE d; - bool was_decl = false; if (DECL_P (init)) - { - was_decl = true; - init = decl_constant_value (init); - } + init = decl_constant_value (init); if (TREE_CODE (type) == INTEGER_TYPE && TREE_CODE (ftype) == REAL_TYPE) --- gcc/cp/decl.c.jj 2009-11-23 16:14:32.000000000 +0100 +++ gcc/cp/decl.c 2009-11-26 17:36:35.000000000 +0100 @@ -520,8 +520,6 @@ poplevel (int keep, int reverse, int fun /* The chain of decls was accumulated in reverse order. Put it into forward order, just for cleanliness. */ tree decls; - int tmp = functionbody; - int real_functionbody; tree subblocks; tree block; tree decl; @@ -535,8 +533,8 @@ poplevel (int keep, int reverse, int fun gcc_assert (current_binding_level->kind != sk_class); - real_functionbody = (current_binding_level->kind == sk_cleanup - ? ((functionbody = 0), tmp) : functionbody); + if (current_binding_level->kind == sk_cleanup) + functionbody = 0; subblocks = functionbody >= 0 ? current_binding_level->blocks : 0; gcc_assert (!VEC_length(cp_class_binding, @@ -1035,8 +1033,6 @@ decls_match (tree newdecl, tree olddecl) void warn_extern_redeclared_static (tree newdecl, tree olddecl) { - tree name; - if (TREE_CODE (newdecl) == TYPE_DECL || TREE_CODE (newdecl) == TEMPLATE_DECL || TREE_CODE (newdecl) == CONST_DECL @@ -1059,7 +1055,6 @@ warn_extern_redeclared_static (tree newd && DECL_ARTIFICIAL (olddecl)) return; - name = DECL_ASSEMBLER_NAME (newdecl); permerror (input_location, "%qD was declared % and later %", newdecl); permerror (input_location, "previous declaration of %q+D", olddecl); } @@ -4071,7 +4066,6 @@ start_decl (const cp_declarator *declara tree *pushed_scope_p) { tree decl; - tree type; tree context; bool was_public; int flags; @@ -4094,8 +4088,6 @@ start_decl (const cp_declarator *declara || decl == error_mark_node) return error_mark_node; - type = TREE_TYPE (decl); - context = DECL_CONTEXT (decl); if (context) --- gcc/cp/parser.c.jj 2009-11-25 10:50:09.000000000 +0100 +++ gcc/cp/parser.c 2009-11-26 17:36:35.000000000 +0100 @@ -10650,14 +10650,13 @@ cp_parser_type_parameter (cp_parser* par case RID_TEMPLATE: { - tree parameter_list; tree identifier; tree default_argument; /* Look for the `<'. */ cp_parser_require (parser, CPP_LESS, "%<<%>"); /* Parse the template-parameter-list. */ - parameter_list = cp_parser_template_parameter_list (parser); + cp_parser_template_parameter_list (parser); /* Look for the `>'. */ cp_parser_require (parser, CPP_GREATER, "%<>%>"); /* Look for the `class' keyword. */ @@ -10791,7 +10790,7 @@ cp_parser_template_id (cp_parser *parser cp_token_position start_of_id = 0; deferred_access_check *chk; VEC (deferred_access_check,gc) *access_check; - cp_token *next_token = NULL, *next_token_2 = NULL, *token = NULL; + cp_token *next_token = NULL, *next_token_2 = NULL; bool is_identifier; /* If the next token corresponds to a template-id, there is no need @@ -10839,7 +10838,6 @@ cp_parser_template_id (cp_parser *parser /* Parse the template-name. */ is_identifier = false; - token = cp_lexer_peek_token (parser->lexer); templ = cp_parser_template_name (parser, template_keyword_p, check_dependency_p, is_declaration, @@ -11516,7 +11514,6 @@ cp_parser_explicit_instantiation (cp_par int declares_class_or_enum; cp_decl_specifier_seq decl_specifiers; tree extension_specifier = NULL_TREE; - cp_token *token; /* Look for an (optional) storage-class-specifier or function-specifier. */ @@ -11539,7 +11536,6 @@ cp_parser_explicit_instantiation (cp_par control while processing explicit instantiation directives. */ push_deferring_access_checks (dk_no_check); /* Parse a decl-specifier-seq. */ - token = cp_lexer_peek_token (parser->lexer); cp_parser_decl_specifier_seq (parser, CP_PARSER_FLAGS_OPTIONAL, &decl_specifiers, @@ -11996,8 +11992,6 @@ cp_parser_simple_type_specifier (cp_pars /* If the type-specifier was for a built-in type, we're done. */ if (type) { - tree id; - /* Record the type. */ if (decl_specs && (token->keyword != RID_SIGNED @@ -12012,7 +12006,7 @@ cp_parser_simple_type_specifier (cp_pars decl_specs->any_specifiers_p = true; /* Consume the token. */ - id = cp_lexer_consume_token (parser->lexer)->u.value; + cp_lexer_consume_token (parser->lexer); /* There is no valid C++ program where a non-template type is followed by a "<". That usually indicates that the user thought @@ -13800,7 +13794,6 @@ cp_parser_declarator (cp_parser* parser, bool* parenthesized_p, bool member_p) { - cp_token *token; cp_declarator *declarator; enum tree_code code; cp_cv_quals cv_quals; @@ -13815,9 +13808,6 @@ cp_parser_declarator (cp_parser* parser, if (cp_parser_allow_gnu_extensions_p (parser)) attributes = cp_parser_attributes_opt (parser); - /* Peek at the next token. */ - token = cp_lexer_peek_token (parser->lexer); - /* Check for the ptr-operator production. */ cp_parser_parse_tentatively (parser); /* Parse the ptr-operator. */ @@ -15012,7 +15002,6 @@ cp_parser_parameter_declaration (cp_pars bool *parenthesized_p) { int declares_class_or_enum; - bool greater_than_is_operator_p; cp_decl_specifier_seq decl_specifiers; cp_declarator *declarator; tree default_argument; @@ -15027,7 +15016,6 @@ cp_parser_parameter_declaration (cp_pars template-parameter, the first non-nested `>' is taken as the end of the template parameter-list rather than a greater-than operator. */ - greater_than_is_operator_p = !template_parm_p; /* Type definitions may not appear in parameter types. */ saved_message = parser->type_definition_forbidden_message; @@ -18221,10 +18209,8 @@ cp_parser_check_declarator_template_para if (declarator->u.id.qualifying_scope) { tree scope; - tree member; scope = declarator->u.id.qualifying_scope; - member = declarator->u.id.unqualified_name; while (scope && CLASS_TYPE_P (scope)) { @@ -23123,7 +23109,6 @@ pragma_lex (tree *value) void c_parse_file (void) { - bool error_occurred; static bool already_called = false; if (already_called) @@ -23136,7 +23121,7 @@ c_parse_file (void) the_parser = cp_parser_new (); push_deferring_access_checks (flag_access_control ? dk_no_deferred : dk_no_check); - error_occurred = cp_parser_translation_unit (the_parser); + cp_parser_translation_unit (the_parser); the_parser = NULL; } --- gcc/cp/cp-gimplify.c.jj 2009-09-30 12:19:17.000000000 +0200 +++ gcc/cp/cp-gimplify.c 2009-11-26 17:36:35.000000000 +0100 @@ -429,17 +429,13 @@ cp_gimplify_init_expr (tree *expr_p, gim tree from = TREE_OPERAND (*expr_p, 1); tree to = TREE_OPERAND (*expr_p, 0); tree t; - tree slot = NULL_TREE; /* What about code that pulls out the temp and uses it elsewhere? I think that such code never uses the TARGET_EXPR as an initializer. If I'm wrong, we'll abort because the temp won't have any RTL. In that case, I guess we'll need to replace references somehow. */ if (TREE_CODE (from) == TARGET_EXPR) - { - slot = TARGET_EXPR_SLOT (from); - from = TARGET_EXPR_INITIAL (from); - } + from = TARGET_EXPR_INITIAL (from); /* Look through any COMPOUND_EXPRs, since build_compound_expr pushes them inside the TARGET_EXPR. */ --- gcc/cp/typeck.c.jj 2009-11-23 13:04:26.000000000 +0100 +++ gcc/cp/typeck.c 2009-11-26 17:36:35.000000000 +0100 @@ -3021,7 +3021,6 @@ cp_build_function_call_vec (tree functio tsubst_flags_t complain) { tree fntype, fndecl; - tree name = NULL_TREE; int is_method; tree original = function; int nargs; @@ -3044,8 +3043,6 @@ cp_build_function_call_vec (tree functio if (TREE_CODE (function) == FUNCTION_DECL) { - name = DECL_NAME (function); - mark_used (function); fndecl = function; --- gcc/cp/class.c.jj 2009-11-23 13:04:26.000000000 +0100 +++ gcc/cp/class.c 2009-11-26 17:36:35.000000000 +0100 @@ -6059,7 +6059,6 @@ resolve_address_of_overloaded_function ( selected function. */ int is_ptrmem = 0; - int is_reference = 0; /* We store the matches in a TREE_LIST rooted here. The functions are the TREE_PURPOSE, not the TREE_VALUE, in this list, for easy interoperability with most_specialized_instantiation. */ @@ -6082,12 +6081,9 @@ resolve_address_of_overloaded_function ( /* This is OK, too. */ is_ptrmem = 1; else if (TREE_CODE (target_type) == FUNCTION_TYPE) - { - /* This is OK, too. This comes from a conversion to reference - type. */ - target_type = build_reference_type (target_type); - is_reference = 1; - } + /* This is OK, too. This comes from a conversion to reference + type. */ + target_type = build_reference_type (target_type); else { if (flags & tf_error) @@ -8043,12 +8039,10 @@ build_rtti_vtbl_entries (tree binfo, vtb { tree b; tree t; - tree basetype; tree offset; tree decl; tree init; - basetype = BINFO_TYPE (binfo); t = BINFO_TYPE (vid->rtti_binfo); /* To find the complete object, we will first convert to our most --- gcc/cp/mangle.c.jj 2009-11-02 15:54:23.000000000 +0100 +++ gcc/cp/mangle.c 2009-11-26 17:36:35.000000000 +0100 @@ -2809,8 +2809,6 @@ static void write_template_param (const tree parm) { int parm_index; - int parm_level; - tree parm_type = NULL_TREE; MANGLE_TRACE_TREE ("template-parm", parm); @@ -2820,13 +2818,10 @@ write_template_param (const tree parm) case TEMPLATE_TEMPLATE_PARM: case BOUND_TEMPLATE_TEMPLATE_PARM: parm_index = TEMPLATE_TYPE_IDX (parm); - parm_level = TEMPLATE_TYPE_LEVEL (parm); break; case TEMPLATE_PARM_INDEX: parm_index = TEMPLATE_PARM_IDX (parm); - parm_level = TEMPLATE_PARM_LEVEL (parm); - parm_type = TREE_TYPE (TEMPLATE_PARM_DECL (parm)); break; default: Jakub