From 712d22976c2f8c0053865790f0e0674337864ab9 Mon Sep 17 00:00:00 2001 From: manu Date: Tue, 7 Jul 2009 02:55:59 +0000 Subject: =?UTF-8?q?2009-07-07=20=20Manuel=20L=C3=B3pez-Ib=C3=A1=C3=B1ez=20?= =?UTF-8?q?=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * cgraphunit.c: Replace %J by an explicit location. Update all calls. * c-decl.c: Likewise. * function.c: Likewise. * varasm.c: Likewise. * tree-ssa.c: Likewise. * c-common.c: Likewise. * tree-cfg.c: Likewise. * config/spu/spu.c: Likewise. * config/ia64/ia64.c: Likewise. * config/v850/v850.c: Likewise. java/ * class.c: Replace %J by an explicit location. Update all calls. objc/ * objc-act.c: Replace %J by an explicit location. Update all calls. cp/ * init.c: Replace %J by an explicit location. Update all calls. * decl.c: Likewise. * typeck2.c: Likewise. * pt.c: Likewise. * name-lookup.c: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@149312 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 26089965d0c..96dd6c1dfad 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -426,8 +426,9 @@ perform_member_init (tree member, tree init) /* Effective C++ rule 12 requires that all data members be initialized. */ if (warn_ecpp && init == NULL_TREE && TREE_CODE (type) != ARRAY_TYPE) - warning (OPT_Weffc__, "%J%qD should be initialized in the member initialization " - "list", current_function_decl, member); + warning_at (DECL_SOURCE_LOCATION (current_function_decl), OPT_Weffc__, + "%qD should be initialized in the member initialization list", + member); /* Get an lvalue for the data member. */ decl = build_class_member_access_expr (current_class_ref, member, @@ -451,9 +452,9 @@ perform_member_init (tree member, tree init) else { if (TREE_CODE (type) == REFERENCE_TYPE) - permerror (input_location, "%Jvalue-initialization of %q#D, " - "which has reference type", - current_function_decl, member); + permerror (DECL_SOURCE_LOCATION (current_function_decl), + "value-initialization of %q#D, which has reference type", + member); else { init = build2 (INIT_EXPR, type, decl, build_value_init (type)); @@ -492,8 +493,9 @@ perform_member_init (tree member, tree init) && !type_has_user_provided_default_constructor (type)) /* TYPE_NEEDS_CONSTRUCTING can be set just because we have a vtable; still give this diagnostic. */ - permerror (input_location, "%Juninitialized member %qD with % type %qT", - current_function_decl, member, type); + permerror (DECL_SOURCE_LOCATION (current_function_decl), + "uninitialized member %qD with % type %qT", + member, type); finish_expr_stmt (build_aggr_init (decl, init, 0, tf_warning_or_error)); } @@ -504,11 +506,13 @@ perform_member_init (tree member, tree init) { /* member traversal: note it leaves init NULL */ if (TREE_CODE (type) == REFERENCE_TYPE) - permerror (input_location, "%Juninitialized reference member %qD", - current_function_decl, member); + permerror (DECL_SOURCE_LOCATION (current_function_decl), + "uninitialized reference member %qD", + member); else if (CP_TYPE_CONST_P (type)) - permerror (input_location, "%Juninitialized member %qD with % type %qT", - current_function_decl, member, type); + permerror (DECL_SOURCE_LOCATION (current_function_decl), + "uninitialized member %qD with % type %qT", + member, type); } else if (TREE_CODE (init) == TREE_LIST) /* There was an explicit member initialization. Do some work @@ -661,7 +665,8 @@ sort_mem_initializers (tree t, tree mem_inits) warning (OPT_Wreorder, " %q+#D", subobject); else warning (OPT_Wreorder, " base %qT", subobject); - warning (OPT_Wreorder, "%J when initialized here", current_function_decl); + warning_at (DECL_SOURCE_LOCATION (current_function_decl), + OPT_Wreorder, " when initialized here"); } /* Look again, from the beginning of the list. */ @@ -677,11 +682,13 @@ sort_mem_initializers (tree t, tree mem_inits) if (TREE_VALUE (subobject_init)) { if (TREE_CODE (subobject) == FIELD_DECL) - error ("%Jmultiple initializations given for %qD", - current_function_decl, subobject); + error_at (DECL_SOURCE_LOCATION (current_function_decl), + "multiple initializations given for %qD", + subobject); else - error ("%Jmultiple initializations given for base %qT", - current_function_decl, subobject); + error_at (DECL_SOURCE_LOCATION (current_function_decl), + "multiple initializations given for base %qT", + subobject); } /* Record the initialization. */ @@ -747,8 +754,9 @@ sort_mem_initializers (tree t, tree mem_inits) if (same_type_p (last_field_type, field_type)) { if (TREE_CODE (field_type) == UNION_TYPE) - error ("%Jinitializations for multiple members of %qT", - current_function_decl, last_field_type); + error_at (DECL_SOURCE_LOCATION (current_function_decl), + "initializations for multiple members of %qT", + last_field_type); done = 1; break; } @@ -810,9 +818,10 @@ emit_mem_initializers (tree mem_inits) if (extra_warnings && !arguments && DECL_COPY_CONSTRUCTOR_P (current_function_decl) && type_has_user_nondefault_constructor (BINFO_TYPE (subobject))) - warning (OPT_Wextra, "%Jbase class %q#T should be explicitly initialized in the " - "copy constructor", - current_function_decl, BINFO_TYPE (subobject)); + warning_at (DECL_SOURCE_LOCATION (current_function_decl), OPT_Wextra, + "base class %q#T should be explicitly initialized in the " + "copy constructor", + BINFO_TYPE (subobject)); /* Initialize the base. */ if (BINFO_VIRTUAL_P (subobject)) -- cgit v1.2.1 From e627cda1433a6aa4f632ec896cea9568a6ce734a Mon Sep 17 00:00:00 2001 From: manu Date: Tue, 7 Jul 2009 22:18:35 +0000 Subject: =?UTF-8?q?2009-07-08=20=20Manuel=20L=C3=B3pez-Ib=C3=A1=C3=B1ez=20?= =?UTF-8?q?=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR c++/31246 * gimplify.c (gimplify_expr): Propagate no_warning flag when gimplifying. * gimple (gimple_build_call_from_tree): Likewise. * tree-cfg.c (remove_useless_stmts_warn_notreached): Check no_warning flag before warning. cp/ * init.c (build_new_1): Set TREE_NO_WARNING for compiler-generated code. * cp-gimplify.c (genericize_eh_spec_block): Likewise. testsuite/ * g++.dg/warn/pr31246.C: New. * g++.dg/warn/pr31246-2.C: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@149354 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 96dd6c1dfad..68ffe3a3dd0 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2185,8 +2185,14 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, else if (stable) /* This is much simpler if we were able to preevaluate all of the arguments to the constructor call. */ - init_expr = build2 (TRY_CATCH_EXPR, void_type_node, - init_expr, cleanup); + { + /* CLEANUP is compiler-generated, so no diagnostics. */ + TREE_NO_WARNING (cleanup) = true; + init_expr = build2 (TRY_CATCH_EXPR, void_type_node, + init_expr, cleanup); + /* Likewise, this try-catch is compiler-generated. */ + TREE_NO_WARNING (init_expr) = true; + } else /* Ack! First we allocate the memory. Then we set our sentry variable to true, and expand a cleanup that deletes the @@ -2206,6 +2212,9 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, sentry = TARGET_EXPR_SLOT (begin); + /* CLEANUP is compiler-generated, so no diagnostics. */ + TREE_NO_WARNING (cleanup) = true; + TARGET_EXPR_CLEANUP (begin) = build3 (COND_EXPR, void_type_node, sentry, cleanup, void_zero_node); @@ -2217,8 +2226,9 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, = build2 (COMPOUND_EXPR, void_type_node, begin, build2 (COMPOUND_EXPR, void_type_node, init_expr, end)); + /* Likewise, this is compiler-generated. */ + TREE_NO_WARNING (init_expr) = true; } - } } else -- cgit v1.2.1 From a8fe6bf41bf0280fc339f79aa0d2073363693fe4 Mon Sep 17 00:00:00 2001 From: jason Date: Sun, 12 Jul 2009 19:19:03 +0000 Subject: PR c++/40689 * init.c (build_new_1): Handle initializer list as array initializer. (build_vec_init): Likewise. * typeck.c (cp_build_modify_expr): Likewise. * typeck2.c (process_init_constructor_array): Error rather than abort if too many initializers. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@149533 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 68ffe3a3dd0..19b24895e55 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1773,6 +1773,7 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, /* The type of the new-expression. (This type is always a pointer type.) */ tree pointer_type; + tree non_const_pointer_type; tree outer_nelts = NULL_TREE; tree alloc_call, alloc_expr; /* The address returned by the call to "operator new". This node is @@ -2076,9 +2077,15 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, } /* Now use a pointer to the type we've actually allocated. */ - data_addr = fold_convert (pointer_type, data_addr); + + /* But we want to operate on a non-const version to start with, + since we'll be modifying the elements. */ + non_const_pointer_type = build_pointer_type + (cp_build_qualified_type (type, TYPE_QUALS (type) & ~TYPE_QUAL_CONST)); + + data_addr = fold_convert (non_const_pointer_type, data_addr); /* Any further uses of alloc_node will want this type, too. */ - alloc_node = fold_convert (pointer_type, alloc_node); + alloc_node = fold_convert (non_const_pointer_type, alloc_node); /* Now initialize the allocated object. Note that we preevaluate the initialization expression, apart from the actual constructor call or @@ -2098,12 +2105,32 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, if (array_p) { - if (*init) + tree vecinit = NULL_TREE; + if (*init && VEC_length (tree, *init) == 1 + && BRACE_ENCLOSED_INITIALIZER_P (VEC_index (tree, *init, 0)) + && CONSTRUCTOR_IS_DIRECT_INIT (VEC_index (tree, *init, 0))) + { + tree arraytype, domain; + vecinit = VEC_index (tree, *init, 0); + if (TREE_CONSTANT (nelts)) + domain = compute_array_index_type (NULL_TREE, nelts); + else + { + domain = NULL_TREE; + if (CONSTRUCTOR_NELTS (vecinit) > 0) + warning (0, "non-constant array size in new, unable to " + "verify length of initializer-list"); + } + arraytype = build_cplus_array_type (type, domain); + vecinit = digest_init (arraytype, vecinit); + } + else if (*init) { if (complain & tf_error) permerror (input_location, "ISO C++ forbids initialization in array new"); else return error_mark_node; + vecinit = build_tree_list_vec (*init); } init_expr = build_vec_init (data_addr, @@ -2111,7 +2138,7 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, MINUS_EXPR, outer_nelts, integer_one_node, complain), - build_tree_list_vec (*init), + vecinit, explicit_value_init_p, /*from_array=*/0, complain); @@ -2270,7 +2297,7 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, /* A new-expression is never an lvalue. */ gcc_assert (!lvalue_p (rval)); - return rval; + return convert (pointer_type, rval); } /* Generate a representation for a C++ "new" expression. *PLACEMENT @@ -2664,6 +2691,7 @@ build_vec_init (tree base, tree maxindex, tree init, inner_elt_type = strip_array_types (type); if (init + && TREE_CODE (atype) == ARRAY_TYPE && (from_array == 2 ? (!CLASS_TYPE_P (inner_elt_type) || !TYPE_HAS_COMPLEX_ASSIGN_REF (inner_elt_type)) @@ -2679,7 +2707,6 @@ build_vec_init (tree base, tree maxindex, tree init, brace-enclosed initializers. In this case, digest_init and store_constructor will handle the semantics for us. */ - gcc_assert (TREE_CODE (atype) == ARRAY_TYPE); stmt_expr = build2 (INIT_EXPR, atype, base, init); return stmt_expr; } -- cgit v1.2.1 From c1c67b4f5041c4367842002c81ffe912ff97f2d8 Mon Sep 17 00:00:00 2001 From: jason Date: Thu, 16 Jul 2009 20:36:10 +0000 Subject: PR libstdc++/37907 Support std::is_standard_layout and std::is_trivial traits, change POD to C++0x version (except for layout). * gcc/c-common.c (c_common_reswords): Add __is_standard_layout and __is_trivial. * gcc/c-common.h (enum rid): Add RID_IS_STD_LAYOUT and RID_IS_TRIVIAL. * gcc/cp/cp-tree.h (enum cp_trait_kind): Add CPTK_IS_STD_LAYOUT, CPTK_IS_TRIVIAL. (struct lang_type_class): Add non_std_layout. (CLASSTYPE_NON_STD_LAYOUT): New. * gcc/cp/class.c (check_bases): Set it. (check_field_decls): Likewise. (check_bases_and_members): Likewise. * gcc/cp/parser.c (cp_parser_primary_expression): Handle RID_IS_STD_LAYOUT, RID_IS_TRIVIAL. (cp_parser_trait_expr): Likewise. * gcc/cp/semantics.c (trait_expr_value): Handle CPTK_IS_STD_LAYOUT, CPTK_IS_TRIVIAL. (finish_trait_expr): Likewise. * gcc/cp/tree.c (scalarish_type_p, trivial_type_p, std_layout_type_p): New. (pod_type_p): Use them. * gcc/cp/typeck.c (build_class_member_access_expr): Check CLASSTYPE_NON_STD_LAYOUT rather than CLASSTYPE_NON_POD_P. * libstdc++-v3/include/std/type_traits: Add is_standard_layout, is_trivial. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@149721 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 19b24895e55..9118c61928b 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2703,7 +2703,7 @@ build_vec_init (tree base, tree maxindex, tree init, || ! TYPE_HAS_NONTRIVIAL_DESTRUCTOR (inner_elt_type))) || from_array)) { - /* Do non-default initialization of POD arrays resulting from + /* Do non-default initialization of trivial arrays resulting from brace-enclosed initializers. In this case, digest_init and store_constructor will handle the semantics for us. */ @@ -2769,7 +2769,7 @@ build_vec_init (tree base, tree maxindex, tree init, if (init != NULL_TREE && TREE_CODE (init) == CONSTRUCTOR) { - /* Do non-default initialization of non-POD arrays resulting from + /* Do non-default initialization of non-trivial arrays resulting from brace-enclosed initializers. */ unsigned HOST_WIDE_INT idx; tree elt; -- cgit v1.2.1 From 389dd41bd043170e7dc7660304f14a5f16af3562 Mon Sep 17 00:00:00 2001 From: manu Date: Thu, 16 Jul 2009 22:29:52 +0000 Subject: =?UTF-8?q?2009-07-17=20=20Aldy=20Hernandez=20=20=20=09=20=20=20=20Manuel=20L=C3=B3pez-Ib=C3=A1=C3=B1ez=20=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR 40435 * tree-complex.c, tree-loop-distribution.c, tree.c, tree.h, builtins.c, fold-const.c, omp-low.c, cgraphunit.c, tree-ssa-ccp.c, tree-ssa-dom.c, gimple-low.c, expr.c, tree-ssa-ifcombine.c, c-decl.c, stor-layout.c, tree-if-conv.c, c-typeck.c, gimplify.c, calls.c, tree-sra.c, tree-mudflap.c, tree-ssa-copy.c, tree-ssa-forwprop.c, c-convert.c, c-omp.c, varasm.c, tree-inline.c, c-common.c, c-common.h, gimple.c, tree-switch-conversion.c, gimple.h, tree-cfg.c, c-parser.c, convert.c: Add location argument to fold_{unary,binary,ternary}, fold_build[123], build_call_expr, build_size_arg, build_fold_addr_expr, build_call_array, non_lvalue, size_diffop, fold_build1_initializer, fold_build2_initializer, fold_build3_initializer, fold_build_call_array, fold_build_call_array_initializer, fold_single_bit_test, omit_one_operand, omit_two_operands, invert_truthvalue, fold_truth_not_expr, build_fold_indirect_ref, fold_indirect_ref, combine_comparisons, fold_builtin_*, fold_call_expr, build_range_check, maybe_fold_offset_to_address, round_up, round_down. objc/ * objc-act.c: Add location argument to all calls to build_fold_addr_expr. testsuite/ * gcc.dg/pr36902.c: Add column info. * g++.dg/gcov/gcov-2.C: Change count for definition. cp/ * typeck.c, init.c, class.c, method.c, rtti.c, except.c, error.c, tree.c, cp-gimplify.c, cxx-pretty-print.c, pt.c, semantics.c, call.c, cvt.c, mangle.c: Add location argument to fold_{unary,binary,ternary}, fold_build[123], build_call_expr, build_size_arg, build_fold_addr_expr, build_call_array, non_lvalue, size_diffop, fold_build1_initializer, fold_build2_initializer, fold_build3_initializer, fold_build_call_array, fold_build_call_array_initializer, fold_single_bit_test, omit_one_operand, omit_two_operands, invert_truthvalue, fold_truth_not_expr, build_fold_indirect_ref, fold_indirect_ref, combine_comparisons, fold_builtin_*, fold_call_expr, build_range_check, maybe_fold_offset_to_address, round_up, round_down. fortran/ * trans-expr.c, trans-array.c, trans-openmp.c, trans-stmt.c, trans.c, trans-io.c, trans-decl.c, trans-intrinsic.c: Add location argument to fold_{unary,binary,ternary}, fold_build[123], build_call_expr, build_size_arg, build_fold_addr_expr, build_call_array, non_lvalue, size_diffop, fold_build1_initializer, fold_build2_initializer, fold_build3_initializer, fold_build_call_array, fold_build_call_array_initializer, fold_single_bit_test, omit_one_operand, omit_two_operands, invert_truthvalue, fold_truth_not_expr, build_fold_indirect_ref, fold_indirect_ref, combine_comparisons, fold_builtin_*, fold_call_expr, build_range_check, maybe_fold_offset_to_address, round_up, round_down. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@149722 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 9118c61928b..73403e9113a 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -219,7 +219,8 @@ build_zero_init (tree type, tree nelts, bool static_storage_p) /* Iterate over the array elements, building initializations. */ if (nelts) - max_index = fold_build2 (MINUS_EXPR, TREE_TYPE (nelts), + max_index = fold_build2_loc (input_location, + MINUS_EXPR, TREE_TYPE (nelts), nelts, integer_one_node); else max_index = array_type_nelts (type); @@ -965,7 +966,8 @@ expand_cleanup_for_base (tree binfo, tree flag) LOOKUP_NORMAL | LOOKUP_NONVIRTUAL, tf_warning_or_error); if (flag) - expr = fold_build3 (COND_EXPR, void_type_node, + expr = fold_build3_loc (input_location, + COND_EXPR, void_type_node, c_common_truthvalue_conversion (input_location, flag), expr, integer_zero_node); @@ -2048,7 +2050,8 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, many elements to destroy later. We use the last sizeof (size_t) bytes to store the number of elements. */ cookie_ptr = size_binop (MINUS_EXPR, cookie_size, size_in_bytes (sizetype)); - cookie_ptr = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (alloc_node), + cookie_ptr = fold_build2_loc (input_location, + POINTER_PLUS_EXPR, TREE_TYPE (alloc_node), alloc_node, cookie_ptr); size_ptr_type = build_pointer_type (sizetype); cookie_ptr = fold_convert (size_ptr_type, cookie_ptr); @@ -2060,7 +2063,8 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, { /* Also store the element size. */ cookie_ptr = build2 (POINTER_PLUS_EXPR, size_ptr_type, cookie_ptr, - fold_build1 (NEGATE_EXPR, sizetype, + fold_build1_loc (input_location, + NEGATE_EXPR, sizetype, size_in_bytes (sizetype))); cookie = cp_build_indirect_ref (cookie_ptr, NULL, complain); @@ -2498,7 +2502,8 @@ build_vec_delete_1 (tree base, tree maxindex, tree type, tbase = create_temporary_var (ptype); tbase_init = cp_build_modify_expr (tbase, NOP_EXPR, - fold_build2 (POINTER_PLUS_EXPR, ptype, + fold_build2_loc (input_location, + POINTER_PLUS_EXPR, ptype, fold_convert (ptype, base), virtual_size), tf_warning_or_error); @@ -2510,7 +2515,7 @@ build_vec_delete_1 (tree base, tree maxindex, tree type, body = build1 (EXIT_EXPR, void_type_node, build2 (EQ_EXPR, boolean_type_node, tbase, fold_convert (ptype, base))); - tmp = fold_build1 (NEGATE_EXPR, sizetype, size_exp); + tmp = fold_build1_loc (input_location, NEGATE_EXPR, sizetype, size_exp); body = build_compound_expr (input_location, body, cp_build_modify_expr (tbase, NOP_EXPR, @@ -2575,8 +2580,9 @@ build_vec_delete_1 (tree base, tree maxindex, tree type, body = integer_zero_node; /* Outermost wrapper: If pointer is null, punt. */ - body = fold_build3 (COND_EXPR, void_type_node, - fold_build2 (NE_EXPR, boolean_type_node, base, + body = fold_build3_loc (input_location, COND_EXPR, void_type_node, + fold_build2_loc (input_location, + NE_EXPR, boolean_type_node, base, convert (TREE_TYPE (base), integer_zero_node)), body, integer_zero_node); @@ -3279,7 +3285,8 @@ build_vec_delete (tree base, tree maxindex, base = TARGET_EXPR_SLOT (base_init); } type = strip_array_types (TREE_TYPE (type)); - cookie_addr = fold_build1 (NEGATE_EXPR, sizetype, TYPE_SIZE_UNIT (sizetype)); + cookie_addr = fold_build1_loc (input_location, NEGATE_EXPR, + sizetype, TYPE_SIZE_UNIT (sizetype)); cookie_addr = build2 (POINTER_PLUS_EXPR, size_ptr_type, fold_convert (size_ptr_type, base), -- cgit v1.2.1 From 4600cfb46bf223de57c14b12f230a0156a7ed3e0 Mon Sep 17 00:00:00 2001 From: rguenth Date: Fri, 17 Jul 2009 09:09:11 +0000 Subject: 2009-07-17 Richard Guenther * init.c (build_vec_delete_1): Do not set DECL_REGISTER on the temporary pointer. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@149736 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 1 - 1 file changed, 1 deletion(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 73403e9113a..3da8ab8464c 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2507,7 +2507,6 @@ build_vec_delete_1 (tree base, tree maxindex, tree type, fold_convert (ptype, base), virtual_size), tf_warning_or_error); - DECL_REGISTER (tbase) = 1; controller = build3 (BIND_EXPR, void_type_node, tbase, NULL_TREE, NULL_TREE); TREE_SIDE_EFFECTS (controller) = 1; -- cgit v1.2.1 From 1ba56394133cf064d0b3ed1d80aab88c6790dd30 Mon Sep 17 00:00:00 2001 From: jason Date: Tue, 4 Aug 2009 02:10:05 +0000 Subject: PR c++/40948 * init.c (build_vec_init): Look through a TARGET_EXPR around a CONSTRUCTOR. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@150394 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 3da8ab8464c..4462428321b 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2695,6 +2695,12 @@ build_vec_init (tree base, tree maxindex, tree init, gcc_assert (!init); inner_elt_type = strip_array_types (type); + + /* Look through the TARGET_EXPR around a compound literal. */ + if (init && TREE_CODE (init) == TARGET_EXPR + && TREE_CODE (TARGET_EXPR_INITIAL (init)) == CONSTRUCTOR) + init = TARGET_EXPR_INITIAL (init); + if (init && TREE_CODE (atype) == ARRAY_TYPE && (from_array == 2 -- cgit v1.2.1 From d748d5cd08b9a7d6099b640dcb43e8dd91608f89 Mon Sep 17 00:00:00 2001 From: jason Date: Thu, 6 Aug 2009 16:25:19 +0000 Subject: PR c++/40948 * init.c (build_vec_init): Evaluate the initializer before starting the initialization try block. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@150529 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 4462428321b..ef18a6c1041 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2698,7 +2698,8 @@ build_vec_init (tree base, tree maxindex, tree init, /* Look through the TARGET_EXPR around a compound literal. */ if (init && TREE_CODE (init) == TARGET_EXPR - && TREE_CODE (TARGET_EXPR_INITIAL (init)) == CONSTRUCTOR) + && TREE_CODE (TARGET_EXPR_INITIAL (init)) == CONSTRUCTOR + && from_array != 2) init = TARGET_EXPR_INITIAL (init); if (init @@ -2769,6 +2770,17 @@ build_vec_init (tree base, tree maxindex, tree init, base = get_temp_regvar (ptype, rval); iterator = get_temp_regvar (ptrdiff_type_node, maxindex); + /* If initializing one array from another, initialize element by + element. We rely upon the below calls to do the argument + checking. Evaluate the initializer before entering the try block. */ + if (from_array && init && TREE_CODE (init) != CONSTRUCTOR) + { + base2 = decay_conversion (init); + itype = TREE_TYPE (base2); + base2 = get_temp_regvar (itype, base2); + itype = TREE_TYPE (itype); + } + /* Protect the entire array initialization so that we can destroy the partially constructed array if an exception is thrown. But don't do this if we're assigning. */ @@ -2811,16 +2823,8 @@ build_vec_init (tree base, tree maxindex, tree init, } else if (from_array) { - /* If initializing one array from another, initialize element by - element. We rely upon the below calls the do argument - checking. */ if (init) - { - base2 = decay_conversion (init); - itype = TREE_TYPE (base2); - base2 = get_temp_regvar (itype, base2); - itype = TREE_TYPE (itype); - } + /* OK, we set base2 above. */; else if (TYPE_LANG_SPECIFIC (type) && TYPE_NEEDS_CONSTRUCTING (type) && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type)) -- cgit v1.2.1 From 67702eb899864e03a05b9cf0f0ef542533900d7c Mon Sep 17 00:00:00 2001 From: jason Date: Sun, 16 Aug 2009 17:42:56 +0000 Subject: Make TREE_USED match the [basic.def.odr] concept for FUNCTION_DECL and VAR_DECL, so mark_used only has effect the first time. * decl2.c (mark_used): Just return if TREE_USED is already set. Don't set TREE_USED if cp_unevaluated_operand is set. (tree_used_ok): New fn. * init.c (build_offset_ref): Check it instead of TREE_USED. * call.c (build_call_a): Likewise. * cp-tree.h: Declare it. (DECL_NO_LINKAGE_CHECKED): No longer needed. (struct lang_decl_base): Remove no_linkage_checked bitfield. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@150807 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index ef18a6c1041..9dac7de400e 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1502,7 +1502,7 @@ build_offset_ref (tree type, tree member, bool address_p) gcc_assert (DECL_P (member) || BASELINK_P (member)); /* Callers should call mark_used before this point. */ - gcc_assert (!DECL_P (member) || TREE_USED (member)); + gcc_assert (!DECL_P (member) || tree_used_ok (member)); if (!COMPLETE_TYPE_P (complete_type (type)) && !TYPE_BEING_DEFINED (type)) -- cgit v1.2.1 From 411978d2740734b2c200d92136dc1a62a05b1b23 Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 24 Aug 2009 21:31:54 +0000 Subject: PR c++/41109 PR c++/41110 PR c++/41134 * cp-tree.h (DECL_ODR_USED): New macro. (struct lang_decl_base): Add odr_used flag. * decl.c (duplicate_decls): Propagate it. Use it for error. * pt.c (register_specialization): Use it for error. * decl2.c (mark_used): Use it as gating flag rather than TREE_USED. (cp_write_global_declarations): Use it for error. (tree_used_ok): Remove. * cp-tree.h: Remove tree_used_ok. * call.c (build_call_a): Don't call it. * init.c (build_offset_ref): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@151061 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 9dac7de400e..ef18a6c1041 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1502,7 +1502,7 @@ build_offset_ref (tree type, tree member, bool address_p) gcc_assert (DECL_P (member) || BASELINK_P (member)); /* Callers should call mark_used before this point. */ - gcc_assert (!DECL_P (member) || tree_used_ok (member)); + gcc_assert (!DECL_P (member) || TREE_USED (member)); if (!COMPLETE_TYPE_P (complete_type (type)) && !TYPE_BEING_DEFINED (type)) -- cgit v1.2.1 From f3943982534f64948d4c4de6b2005ec60451c076 Mon Sep 17 00:00:00 2001 From: jason Date: Thu, 12 Nov 2009 18:25:51 +0000 Subject: * typeck.c (cv_qualified_p): New fn. (decay_conversion): Use it. * cp-tree.h: Declare it. * tree.c (rvalue): Use it and cv_unqualified. * init.c (build_aggr_init): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@154125 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index ef18a6c1041..db2920450eb 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1248,13 +1248,13 @@ build_aggr_init (tree exp, tree init, int flags, tsubst_flags_t complain) /* Must arrange to initialize each element of EXP from elements of INIT. */ itype = init ? TREE_TYPE (init) : NULL_TREE; - if (cp_type_quals (type) != TYPE_UNQUALIFIED) - TREE_TYPE (exp) = TYPE_MAIN_VARIANT (type); - if (itype && cp_type_quals (itype) != TYPE_UNQUALIFIED) - itype = TREE_TYPE (init) = TYPE_MAIN_VARIANT (itype); + if (cv_qualified_p (type)) + TREE_TYPE (exp) = cv_unqualified (type); + if (itype && cv_qualified_p (itype)) + TREE_TYPE (init) = cv_unqualified (itype); stmt_expr = build_vec_init (exp, NULL_TREE, init, /*explicit_value_init_p=*/false, - itype && same_type_p (itype, + itype && same_type_p (TREE_TYPE (init), TREE_TYPE (exp)), complain); TREE_READONLY (exp) = was_const; -- cgit v1.2.1 From 8e9e8d76599e6392050ce67a4c965fc493ed01ef Mon Sep 17 00:00:00 2001 From: jakub Date: Wed, 2 Dec 2009 08:39:10 +0000 Subject: * 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@154899 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index db2920450eb..e6397446b02 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2666,7 +2666,6 @@ build_vec_init (tree base, tree maxindex, tree init, { tree rval; tree base2 = NULL_TREE; - tree size; tree itype = NULL_TREE; tree iterator; /* The type of BASE. */ @@ -2724,7 +2723,6 @@ build_vec_init (tree base, tree maxindex, tree init, } maxindex = cp_convert (ptrdiff_type_node, maxindex); - size = size_in_bytes (type); if (TREE_CODE (atype) == ARRAY_TYPE) { ptype = build_pointer_type (type); -- cgit v1.2.1 From f08923b304ae4677059147e8cd52278a201f9ce0 Mon Sep 17 00:00:00 2001 From: pzhao Date: Thu, 17 Dec 2009 03:22:22 +0000 Subject: 2009-12-17 Shujing Zhao PR c/40885 * c-common.h (ref_operator): New type. (build_indirect_ref): Adjust prototype with new argument. * c-typeck.c (build_indirect_ref): Accept ref_operator as argument and emit the diagnostics for easy translation. (build_array_ref): Update calls to build_indirect_ref. * c-omp.c (c_finish_omp_atomic): Likewise. * c-parser.c (c_parser_unary_expression, c_parser_postfix_expression_after_primary): Likewise. cp/ 2009-12-17 Shujing Zhao * typeck.c (build_indirect_ref): Update the argument. (build_x_indirect_ref): Likewise. (cp_build_indirect_ref): Update the argument and emit the diagnostics for easy translation. (build_class_member_access_expr, build_array_ref, get_member_function_from_ptrfunc): Update calls. * cp-tree.h (build_x_indirect_ref, cp_build_indirect_ref): Update prototypes. * call.c (build_new_op, convert_like_real, build_x_va_arg, build_over_call): Update calls. * class.c (build_base_path, build_simple_base_path, build_vfn_ref): Likewise. * decl.c (start_preparsed_function): Likewise. * except.c (expand_start_catch_block, build_throw): Likewise. * init.c (emit_mem_initializers, expand_virtual_init, expand_virtual_init, build_new_1, build_vec_init, build_delete, build_vec_delete): Likewise. * parser.c (cp_parser_unary_expression): Likewise. * pt.c (tsubst_copy_and_build): Likewise. * rtti.c (build_headof, get_tinfo_decl_dynamic, get_typeid): Likewise. * semantics.c (finish_non_static_data_member, thisify_lambda_field): Likewise. * tree.c (build_dummy_object, stabilize_expr): Likewise. * typeck2.c (build_x_arrow): Likewise. testsuite/ 2009-12-17 Shujing Zhao * g++.old-deja/g++.mike/net31.C: Make expected dg-error strings explicit. * g++.old-deja/g++.bugs/900213_02.C: Likewise. * g++.old-deja/g++.bugs/900215_02.C: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@155302 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index e6397446b02..1bd80ffa0f8 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -834,7 +834,7 @@ emit_mem_initializers (tree mem_inits) base_addr = build_base_path (PLUS_EXPR, current_class_ptr, subobject, 1); expand_aggr_init_1 (subobject, NULL_TREE, - cp_build_indirect_ref (base_addr, NULL, + cp_build_indirect_ref (base_addr, RO_NULL, tf_warning_or_error), arguments, LOOKUP_NORMAL, @@ -918,7 +918,7 @@ expand_virtual_init (tree binfo, tree decl) TREE_TYPE (vtt_parm), vtt_parm, vtt_index); - vtbl2 = cp_build_indirect_ref (vtbl2, NULL, tf_warning_or_error); + vtbl2 = cp_build_indirect_ref (vtbl2, RO_NULL, tf_warning_or_error); vtbl2 = convert (TREE_TYPE (vtbl), vtbl2); /* The actual initializer is the VTT value only in the subobject @@ -933,7 +933,7 @@ expand_virtual_init (tree binfo, tree decl) } /* Compute the location of the vtpr. */ - vtbl_ptr = build_vfield_ref (cp_build_indirect_ref (decl, NULL, + vtbl_ptr = build_vfield_ref (cp_build_indirect_ref (decl, RO_NULL, tf_warning_or_error), TREE_TYPE (binfo)); gcc_assert (vtbl_ptr != error_mark_node); @@ -2055,7 +2055,7 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, alloc_node, cookie_ptr); size_ptr_type = build_pointer_type (sizetype); cookie_ptr = fold_convert (size_ptr_type, cookie_ptr); - cookie = cp_build_indirect_ref (cookie_ptr, NULL, complain); + cookie = cp_build_indirect_ref (cookie_ptr, RO_NULL, complain); cookie_expr = build2 (MODIFY_EXPR, sizetype, cookie, nelts); @@ -2067,7 +2067,7 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, NEGATE_EXPR, sizetype, size_in_bytes (sizetype))); - cookie = cp_build_indirect_ref (cookie_ptr, NULL, complain); + cookie = cp_build_indirect_ref (cookie_ptr, RO_NULL, complain); cookie = build2 (MODIFY_EXPR, sizetype, cookie, size_in_bytes (elt_type)); cookie_expr = build2 (COMPOUND_EXPR, TREE_TYPE (cookie_expr), @@ -2154,7 +2154,7 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, } else { - init_expr = cp_build_indirect_ref (data_addr, NULL, complain); + init_expr = cp_build_indirect_ref (data_addr, RO_NULL, complain); if (TYPE_NEEDS_CONSTRUCTING (type) && !explicit_value_init_p) { @@ -2949,7 +2949,7 @@ build_vec_init (tree base, tree maxindex, tree init, { atype = build_pointer_type (atype); stmt_expr = build1 (NOP_EXPR, atype, stmt_expr); - stmt_expr = cp_build_indirect_ref (stmt_expr, NULL, complain); + stmt_expr = cp_build_indirect_ref (stmt_expr, RO_NULL, complain); TREE_NO_WARNING (stmt_expr) = 1; } @@ -3144,7 +3144,7 @@ build_delete (tree type, tree addr, special_function_kind auto_delete, /*alloc_fn=*/NULL_TREE); } - expr = build_dtor_call (cp_build_indirect_ref (addr, NULL, + expr = build_dtor_call (cp_build_indirect_ref (addr, RO_NULL, tf_warning_or_error), auto_delete, flags); if (do_delete) @@ -3298,7 +3298,7 @@ build_vec_delete (tree base, tree maxindex, size_ptr_type, fold_convert (size_ptr_type, base), cookie_addr); - maxindex = cp_build_indirect_ref (cookie_addr, NULL, tf_warning_or_error); + maxindex = cp_build_indirect_ref (cookie_addr, RO_NULL, tf_warning_or_error); } else if (TREE_CODE (type) == ARRAY_TYPE) { -- cgit v1.2.1 From 2bc64004224123a8b204d5562368acdb78983c2c Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 12 Apr 2010 19:58:27 +0000 Subject: PR c++/25811 * cp-tree.h (diagnose_uninitialized_cst_or_ref_member): Declare. * init.c (build_new_1): Check for uninitialized const members and uninitialized reference members, when using new without new-initializer. Call diagnose_uninitialized_cst_or_ref_member. (diagnose_uninitialized_cst_or_ref_member): Define, call diagnose_uninitialized_cst_or_ref_member_1. (diagnose_uninitialized_cst_or_ref_member_1): New function. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@158239 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 1bd80ffa0f8..c1f1cbf4a38 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1,6 +1,6 @@ /* Handle initialization things in C++. Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 + 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. Contributed by Michael Tiemann (tiemann@cygnus.com) @@ -54,6 +54,7 @@ static tree dfs_initialize_vtbl_ptrs (tree, void *); static tree build_dtor_call (tree, special_function_kind, int); static tree build_field_list (tree, tree, int *); static tree build_vtbl_address (tree); +static void diagnose_uninitialized_cst_or_ref_member_1 (tree, tree, bool); /* We are about to generate some complex initialization code. Conceptually, it is all a single expression. However, we may want @@ -1753,6 +1754,59 @@ build_raw_new_expr (VEC(tree,gc) *placement, tree type, tree nelts, return new_expr; } +/* Diagnose uninitialized const members or reference members of type + TYPE. USING_NEW is used to disambiguate the diagnostic between a + new expression without a new-initializer and a declaration */ + +static void +diagnose_uninitialized_cst_or_ref_member_1 (tree type, tree origin, + bool using_new) +{ + tree field; + + for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) + { + tree field_type; + + if (TREE_CODE (field) != FIELD_DECL) + continue; + + field_type = strip_array_types (TREE_TYPE (field)); + + if (TREE_CODE (field_type) == REFERENCE_TYPE) + { + if (using_new) + error ("uninitialized reference member in %q#T using %", + origin); + else + error ("uninitialized reference member in %q#T", origin); + inform (DECL_SOURCE_LOCATION (field), + "%qD should be initialized", field); + } + + if (CP_TYPE_CONST_P (field_type)) + { + if (using_new) + error ("uninitialized const member in %q#T using %", + origin); + else + error ("uninitialized const member in %q#T", origin); + inform (DECL_SOURCE_LOCATION (field), + "%qD should be initialized", field); + } + + if (CLASS_TYPE_P (field_type)) + diagnose_uninitialized_cst_or_ref_member_1 (field_type, + origin, using_new); + } +} + +void +diagnose_uninitialized_cst_or_ref_member (tree type, bool using_new) +{ + diagnose_uninitialized_cst_or_ref_member_1 (type, type, using_new); +} + /* Generate code for a new-expression, including calling the "operator new" function, initializing the object, and, if an exception occurs during construction, cleaning up. The arguments are as for @@ -1839,6 +1893,38 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, is_initialized = (TYPE_NEEDS_CONSTRUCTING (elt_type) || *init != NULL); + if (*init == NULL && !type_has_user_provided_constructor (elt_type)) + { + bool uninitialized_error = false; + /* A program that calls for default-initialization [...] of an + entity of reference type is ill-formed. */ + if (CLASSTYPE_REF_FIELDS_NEED_INIT (elt_type)) + uninitialized_error = true; + + /* A new-expression that creates an object of type T initializes + that object as follows: + - If the new-initializer is omitted: + -- If T is a (possibly cv-qualified) non-POD class type + (or array thereof), the object is default-initialized (8.5). + [...] + -- Otherwise, the object created has indeterminate + value. If T is a const-qualified type, or a (possibly + cv-qualified) POD class type (or array thereof) + containing (directly or indirectly) a member of + const-qualified type, the program is ill-formed; */ + + if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (elt_type)) + uninitialized_error = true; + + if (uninitialized_error) + { + if (complain & tf_error) + diagnose_uninitialized_cst_or_ref_member (elt_type, + /*using_new*/true); + return error_mark_node; + } + } + if (CP_TYPE_CONST_P (elt_type) && *init == NULL && !type_has_user_provided_default_constructor (elt_type)) { -- cgit v1.2.1 From 7a00f93919dce5b91d4638bf98be606d968431ba Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 21 Apr 2010 06:06:27 +0000 Subject: PR c++/9335 gcc/cp: * init.c (constant_value_1): Treat error_mark_node as a constant if DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P is set. * cvt.c (ocp_convert): Handle getting error_mark_node from integral_constant_value. * decl.c (compute_array_index_type): Likewise. gcc/testsuite: * lib/prune.exp: Prune "skipping N instantiation contexts". git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@158586 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index c1f1cbf4a38..e1dee1d10dc 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1658,7 +1658,14 @@ constant_value_1 (tree decl, bool integral_p) init = DECL_INITIAL (decl); } if (init == error_mark_node) - return decl; + { + if (DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl)) + /* Treat the error as a constant to avoid cascading errors on + excessively recursive template instantiation (c++/9335). */ + return init; + else + return decl; + } /* Initializers in templates are generally expanded during instantiation, so before that for const int i(2) INIT is a TREE_LIST with the actual initializer as -- cgit v1.2.1 From a0bbd07d6b449271335d4f4407b5945fb3c9bded Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 28 Apr 2010 00:03:21 +0000 Subject: PR c++/29043 * init.c (perform_member_init): check for uninitialized const or reference members, including array types. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@158817 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index e1dee1d10dc..57b874d5e4a 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -506,6 +506,7 @@ perform_member_init (tree member, tree init) { if (init == NULL_TREE) { + tree core_type; /* member traversal: note it leaves init NULL */ if (TREE_CODE (type) == REFERENCE_TYPE) permerror (DECL_SOURCE_LOCATION (current_function_decl), @@ -515,6 +516,11 @@ perform_member_init (tree member, tree init) permerror (DECL_SOURCE_LOCATION (current_function_decl), "uninitialized member %qD with % type %qT", member, type); + + core_type = strip_array_types (type); + if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type) + || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)) + diagnose_uninitialized_cst_or_ref_member (core_type, /*using_new=*/false); } else if (TREE_CODE (init) == TREE_LIST) /* There was an explicit member initialization. Do some work -- cgit v1.2.1 From 40ab1ef45a45d30cc537b7154240b60fc1bccc2b Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 28 Apr 2010 01:45:00 +0000 Subject: * init.c (perform_member_init): Check CLASS_TYPE_P. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@158822 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 57b874d5e4a..5f0f665afe4 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -518,9 +518,11 @@ perform_member_init (tree member, tree init) member, type); core_type = strip_array_types (type); - if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type) - || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)) - diagnose_uninitialized_cst_or_ref_member (core_type, /*using_new=*/false); + if (CLASS_TYPE_P (core_type) + && (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type) + || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type))) + diagnose_uninitialized_cst_or_ref_member (core_type, + /*using_new=*/false); } else if (TREE_CODE (init) == TREE_LIST) /* There was an explicit member initialization. Do some work -- cgit v1.2.1 From f65ee287c49e15212739e1750e58c0ef7581f02f Mon Sep 17 00:00:00 2001 From: jason Date: Fri, 30 Apr 2010 04:23:00 +0000 Subject: PR c++/43890 * init.c (diagnose_uninitialized_cst_or_ref_member): check for user-provided constructor while recursing. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@158918 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 5f0f665afe4..70e3d387e9e 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1779,6 +1779,9 @@ diagnose_uninitialized_cst_or_ref_member_1 (tree type, tree origin, { tree field; + if (type_has_user_provided_constructor (type)) + return; + for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) { tree field_type; @@ -1791,8 +1794,8 @@ diagnose_uninitialized_cst_or_ref_member_1 (tree type, tree origin, if (TREE_CODE (field_type) == REFERENCE_TYPE) { if (using_new) - error ("uninitialized reference member in %q#T using %", - origin); + error ("uninitialized reference member in %q#T " + "using % without new-initializer", origin); else error ("uninitialized reference member in %q#T", origin); inform (DECL_SOURCE_LOCATION (field), @@ -1802,8 +1805,8 @@ diagnose_uninitialized_cst_or_ref_member_1 (tree type, tree origin, if (CP_TYPE_CONST_P (field_type)) { if (using_new) - error ("uninitialized const member in %q#T using %", - origin); + error ("uninitialized const member in %q#T " + "using % without new-initializer", origin); else error ("uninitialized const member in %q#T", origin); inform (DECL_SOURCE_LOCATION (field), @@ -1908,13 +1911,13 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, is_initialized = (TYPE_NEEDS_CONSTRUCTING (elt_type) || *init != NULL); - if (*init == NULL && !type_has_user_provided_constructor (elt_type)) + if (*init == NULL) { - bool uninitialized_error = false; + bool maybe_uninitialized_error = false; /* A program that calls for default-initialization [...] of an entity of reference type is ill-formed. */ if (CLASSTYPE_REF_FIELDS_NEED_INIT (elt_type)) - uninitialized_error = true; + maybe_uninitialized_error = true; /* A new-expression that creates an object of type T initializes that object as follows: @@ -1929,9 +1932,9 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, const-qualified type, the program is ill-formed; */ if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (elt_type)) - uninitialized_error = true; + maybe_uninitialized_error = true; - if (uninitialized_error) + if (maybe_uninitialized_error) { if (complain & tf_error) diagnose_uninitialized_cst_or_ref_member (elt_type, -- cgit v1.2.1 From cbfb0388f9a280f886410cddf2c8cac6c6b197f9 Mon Sep 17 00:00:00 2001 From: hjl Date: Sat, 1 May 2010 13:52:52 +0000 Subject: Revert the accidental checkin in revision 158918. gcc/cp/ 2010-05-01 H.J. Lu PR c++/43951 * init.c (build_new_1): Revert the accidental checkin in revision 158918. gcc/testsuite/ 2010-05-01 H.J. Lu PR c++/43951 * g++.dg/init/new28.C: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@158959 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 70e3d387e9e..4fc90e6c276 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1911,13 +1911,13 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, is_initialized = (TYPE_NEEDS_CONSTRUCTING (elt_type) || *init != NULL); - if (*init == NULL) + if (*init == NULL && !type_has_user_provided_constructor (elt_type)) { - bool maybe_uninitialized_error = false; + bool uninitialized_error = false; /* A program that calls for default-initialization [...] of an entity of reference type is ill-formed. */ if (CLASSTYPE_REF_FIELDS_NEED_INIT (elt_type)) - maybe_uninitialized_error = true; + uninitialized_error = true; /* A new-expression that creates an object of type T initializes that object as follows: @@ -1932,9 +1932,9 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, const-qualified type, the program is ill-formed; */ if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (elt_type)) - maybe_uninitialized_error = true; + uninitialized_error = true; - if (maybe_uninitialized_error) + if (uninitialized_error) { if (complain & tf_error) diagnose_uninitialized_cst_or_ref_member (elt_type, -- cgit v1.2.1 From fbb73d9bb6980aacb2366cbde38d255de0fde0fe Mon Sep 17 00:00:00 2001 From: dodji Date: Thu, 6 May 2010 06:52:30 +0000 Subject: C++ support for -Wunused-but-set-variable gcc/cp/ChangeLog: PR 18624 * cp-tree.h (mark_exp_read, mark_rvalue_use, mark_lvalue_use, mark_type_use): Declare ... * expr.c (mark_exp_read, mark_rvalue_use, mark_lvalue_use, mark_type_use): ... new fns. * typeck.c (cxx_sizeof_expr, cxx_alignof_expr): Call mark_type_use. (perform_integral_promotions): Call mark_rvalue_use. (cp_build_unary_op): Call mark_lvalue_use. (decay_conversion): Update comment. Call mark_lvalue. * decl.c (unused_but_set_errorcount): New variable. (poplevel): Issue -Wunused-but-set-variable diagnostics. (duplicate_decls): Merge DECL_READ_P flags. (start_cleanup_fn): Set DECL_READ_P flag. (finish_function): Issue -Wunused-but-set-parameter diagnostics. * tree.c (rvalue): Call mark_rvalue_use. * pt.c (convert_nontype_argument): Likewise. * semantics.c (finish_typeof, finish_decltype_type): Call mark_type_use. (finish_asm_stmt): Call mark_lvalue_use. (finish_expr_stmt): Call mark_exp_read. * call.c (convert_like_real) : Call mark_rvalue_use. (build_x_va_arg): Call mark_lvalue_use. (build_over_call): Call mark_type_use. * init.c (build_new, build_delete): Call mark_value_use. * rtti.c (build_typeid): Call mark_lvalue_use or mark_type_use. (build_dynamic_cast_1): call mark_lvalue_use or mark_rvalue_use. gcc/testsuite/ChangeLog: PR 18624 * g++.dg/warn/Wunused-7.C: Add dg-warning. * g++.dg/template/sfinae16.C: Likewise. * gcc.dg/Wunused-var-1.c: Moved to... * c-c++-common/Wunused-var-1.c: ...here. New test. * gcc.dg/Wunused-var-2.c: Moved to... * c-c++-common/Wunused-var-2.c: ...here. New test. * gcc.dg/Wunused-var-3.c: Moved to... * c-c++-common/Wunused-var-3.c: ...here. New test. * gcc.dg/Wunused-var-4.c: Moved to... * gcc.dg/Wunused-var-1.c: ... here. * gcc.dg/Wunused-var-5.c: Moved to... * c-c++-common/Wunused-var-4.c: ...here. New test. * gcc.dg/Wunused-var-7.c: Moved to... * c-c++-common/Wunused-var-5.c: ...here. New test. * gcc.dg/Wunused-var-6.c: Moved to... * gcc.dg/Wunused-var-2.c: ... here. * c-c++-common/Wunused-var-1.c: New test. * c-c++-common/Wunused-var-2.c: New test. * c-c++-common/Wunused-var-3.c: New test. * c-c++-common/Wunused-var-4.c: New test. * c-c++-common/Wunused-var-5.c: New test. * g++.dg/warn/Wunused-var-1.C: New test. * g++.dg/warn/Wunused-var-2.C: New test. * g++.dg/warn/Wunused-var-3.C: New test. * g++.dg/warn/Wunused-var-4.C: New test. * g++.dg/warn/Wunused-var-5.C: New test. * g++.dg/warn/Wunused-var-6.C: New test. * g++.dg/warn/Wunused-var-7.C: New test. * g++.dg/warn/Wunused-var-8.C: New test. * g++.dg/warn/Wunused-parm-1.C: New test. * g++.dg/warn/Wunused-parm-2.C: New test. * g++.dg/warn/Wunused-parm-3.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@159096 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 4fc90e6c276..a2d9837f66b 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2465,6 +2465,7 @@ build_new (VEC(tree,gc) **placement, tree type, tree nelts, else return error_mark_node; } + nelts = mark_rvalue_use (nelts); nelts = cp_save_expr (cp_convert (sizetype, nelts)); } @@ -3120,6 +3121,8 @@ build_delete (tree type, tree addr, special_function_kind auto_delete, type = TYPE_MAIN_VARIANT (type); + addr = mark_rvalue_use (addr); + if (TREE_CODE (type) == POINTER_TYPE) { bool complete_p = true; -- cgit v1.2.1 From fa60f42b454d2f8e591d9cf767ac00821dbf2ee2 Mon Sep 17 00:00:00 2001 From: jason Date: Fri, 7 May 2010 15:52:06 +0000 Subject: PR c++/43951 * init.c (diagnose_uninitialized_cst_or_ref_member_1): Returns the error count. Emit errors only if compain is true. (build_new_1): Do not return error_mark_node if diagnose_uninitialized_cst_or_ref_member_1 does not diagnose any errors. Delay the check for user-provided constructor. (perform_member_init): Adjust. * cp-tree.h (diagnose_uninitialized_cst_or_ref_member): Change the prototype. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@159158 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 83 +++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 36 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index a2d9837f66b..e45d2b882b5 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -54,7 +54,7 @@ static tree dfs_initialize_vtbl_ptrs (tree, void *); static tree build_dtor_call (tree, special_function_kind, int); static tree build_field_list (tree, tree, int *); static tree build_vtbl_address (tree); -static void diagnose_uninitialized_cst_or_ref_member_1 (tree, tree, bool); +static int diagnose_uninitialized_cst_or_ref_member_1 (tree, tree, bool, bool); /* We are about to generate some complex initialization code. Conceptually, it is all a single expression. However, we may want @@ -522,7 +522,8 @@ perform_member_init (tree member, tree init) && (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type) || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type))) diagnose_uninitialized_cst_or_ref_member (core_type, - /*using_new=*/false); + /*using_new=*/false, + /*complain=*/true); } else if (TREE_CODE (init) == TREE_LIST) /* There was an explicit member initialization. Do some work @@ -1771,16 +1772,18 @@ build_raw_new_expr (VEC(tree,gc) *placement, tree type, tree nelts, /* Diagnose uninitialized const members or reference members of type TYPE. USING_NEW is used to disambiguate the diagnostic between a - new expression without a new-initializer and a declaration */ + new expression without a new-initializer and a declaration. Returns + the error count. */ -static void +static int diagnose_uninitialized_cst_or_ref_member_1 (tree type, tree origin, - bool using_new) + bool using_new, bool complain) { tree field; + int error_count = 0; if (type_has_user_provided_constructor (type)) - return; + return 0; for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) { @@ -1793,36 +1796,46 @@ diagnose_uninitialized_cst_or_ref_member_1 (tree type, tree origin, if (TREE_CODE (field_type) == REFERENCE_TYPE) { - if (using_new) - error ("uninitialized reference member in %q#T " - "using % without new-initializer", origin); - else - error ("uninitialized reference member in %q#T", origin); - inform (DECL_SOURCE_LOCATION (field), - "%qD should be initialized", field); + ++ error_count; + if (complain) + { + if (using_new) + error ("uninitialized reference member in %q#T " + "using % without new-initializer", origin); + else + error ("uninitialized reference member in %q#T", origin); + inform (DECL_SOURCE_LOCATION (field), + "%qD should be initialized", field); + } } if (CP_TYPE_CONST_P (field_type)) { - if (using_new) - error ("uninitialized const member in %q#T " - "using % without new-initializer", origin); - else - error ("uninitialized const member in %q#T", origin); - inform (DECL_SOURCE_LOCATION (field), - "%qD should be initialized", field); + ++ error_count; + if (complain) + { + if (using_new) + error ("uninitialized const member in %q#T " + "using % without new-initializer", origin); + else + error ("uninitialized const member in %q#T", origin); + inform (DECL_SOURCE_LOCATION (field), + "%qD should be initialized", field); + } } if (CLASS_TYPE_P (field_type)) - diagnose_uninitialized_cst_or_ref_member_1 (field_type, - origin, using_new); + error_count + += diagnose_uninitialized_cst_or_ref_member_1 (field_type, origin, + using_new, complain); } + return error_count; } -void -diagnose_uninitialized_cst_or_ref_member (tree type, bool using_new) +int +diagnose_uninitialized_cst_or_ref_member (tree type, bool using_new, bool complain) { - diagnose_uninitialized_cst_or_ref_member_1 (type, type, using_new); + return diagnose_uninitialized_cst_or_ref_member_1 (type, type, using_new, complain); } /* Generate code for a new-expression, including calling the "operator @@ -1911,13 +1924,13 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, is_initialized = (TYPE_NEEDS_CONSTRUCTING (elt_type) || *init != NULL); - if (*init == NULL && !type_has_user_provided_constructor (elt_type)) + if (*init == NULL) { - bool uninitialized_error = false; + bool maybe_uninitialized_error = false; /* A program that calls for default-initialization [...] of an entity of reference type is ill-formed. */ if (CLASSTYPE_REF_FIELDS_NEED_INIT (elt_type)) - uninitialized_error = true; + maybe_uninitialized_error = true; /* A new-expression that creates an object of type T initializes that object as follows: @@ -1932,15 +1945,13 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, const-qualified type, the program is ill-formed; */ if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (elt_type)) - uninitialized_error = true; + maybe_uninitialized_error = true; - if (uninitialized_error) - { - if (complain & tf_error) - diagnose_uninitialized_cst_or_ref_member (elt_type, - /*using_new*/true); - return error_mark_node; - } + if (maybe_uninitialized_error + && diagnose_uninitialized_cst_or_ref_member (elt_type, + /*using_new=*/true, + complain & tf_error)) + return error_mark_node; } if (CP_TYPE_CONST_P (elt_type) && *init == NULL -- cgit v1.2.1 From ce494fcf6cecbd423d44d552e2094b923fac9a22 Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 19 May 2010 21:02:27 +0000 Subject: * call.c (reference_binding): Use cp_build_qualified_type_real and cp_type_quals consistently. (add_function_candidate): Likewise. (build_conditional_expr): Likewise. (convert_like_real): Likewise. (type_passed_as): Likewise. * class.c (add_method): Likewise. (same_signature_p): Likewise. (layout_class_type): Likewise. * decl.c (cxx_init_decl_processing): Likewise. (cp_fname_init): Likewise. (grokdeclarator): Likewise. * decl2.c (cp_reconstruct_complex_type): Likewise. * init.c (build_new_1): Likewise. * method.c (do_build_copy_constructor): Likewise. (implicitly_declare_fn): Likewise. * pt.c (tsubst_aggr_type): Likewise. (tsubst): Likewise. * rtti.c (init_rtti_processing): Likewise. (build_headof): Likewise. (build_dynamic_cast_1): Likewise. (tinfo_base_init): Likewise. (emit_support_tinfos): Likewise. * semantics.c (capture_decltype): Likewise. * tree.c (cv_unqualified): Likewise. * typeck.c (composite_pointer_type): Likewise. (string_conv_p): Likewise. * mangle.c (write_CV_qualifiers_for_type): Tweak. * call.c (initialize_reference): Use CP_TYPE_CONST_P. * decl.c (start_decl): Likewise. * semantics.c (finish_compound_literal): Likewise. * typeck.c (check_return_expr): Use CP_TYPE_VOLATILE_P. (cp_type_readonly): Remove. * cp-tree.h: Remove declaration. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@159599 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index e45d2b882b5..1fb5eb0d069 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2200,7 +2200,7 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, /* But we want to operate on a non-const version to start with, since we'll be modifying the elements. */ non_const_pointer_type = build_pointer_type - (cp_build_qualified_type (type, TYPE_QUALS (type) & ~TYPE_QUAL_CONST)); + (cp_build_qualified_type (type, cp_type_quals (type) & ~TYPE_QUAL_CONST)); data_addr = fold_convert (non_const_pointer_type, data_addr); /* Any further uses of alloc_node will want this type, too. */ -- cgit v1.2.1 From f955934c261dc2757b87671643376e05b9387009 Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 24 May 2010 18:38:16 +0000 Subject: PR c++/41510 * decl.c (check_initializer): Don't wrap an init-list in a TREE_LIST. * init.c (build_aggr_init): Don't assume copy-initialization if init has CONSTRUCTOR_IS_DIRECT_INIT. * call.c (build_new_method_call): Sanity check. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@159792 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 1fb5eb0d069..bf80c096d7e 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1240,7 +1240,9 @@ build_aggr_init (tree exp, tree init, int flags, tsubst_flags_t complain) TREE_READONLY (exp) = 0; TREE_THIS_VOLATILE (exp) = 0; - if (init && TREE_CODE (init) != TREE_LIST) + if (init && TREE_CODE (init) != TREE_LIST + && !(BRACE_ENCLOSED_INITIALIZER_P (init) + && CONSTRUCTOR_IS_DIRECT_INIT (init))) flags |= LOOKUP_ONLYCONVERTING; if (TREE_CODE (type) == ARRAY_TYPE) -- cgit v1.2.1 From c4b9c21a2470c2d1d1cca1577a802531752ab067 Mon Sep 17 00:00:00 2001 From: steven Date: Tue, 25 May 2010 18:14:23 +0000 Subject: gcc/ChangeLog: * Makefile.in (EXCEPT_H): Fix typo. objc/ChangeLog: * objc-act.h: Do not include gimple.h. * objc-act.c: Do not include rtl.h, expr.h, libfuncs.h, and tm_p.h. Include gimple.h. Explain why except.h has to be included. * objc-lang.c: Do not include diagnostics.h. * Make-lang.in: Update dependencies. objcp/ChangeLog: * objcp-decl.c: Do not include tm.h, rtl.h, expr.h, c-common.h, flags.h, input.h, except.h, output.h, toplev.h, cpplib.h, debug.h, and target.h. * objcp-lang.c: Do not include tm.h, toplev.h, diagnostics.h, and debug.h. Explain why except.h has to be included. * Make-lang.in: Update dependencies. cp/ChangeLog: * cp-tree.h: Do not include splay-tree.h. (struct prtmem_cst): Remove unused field and false comment. * typeck.c: Do not include rtl.h, expr.h, and tm_p.h. * optimize.c: Do not inclde rtl.h, insn-config.h, and integrate.h. * init.c: Do not include rtl.h and expr.h. * class.c: Do not include rtl.h. Include splay-tree.h. (build_clone): Use plain NULL instead of NULL_RTX. * decl.c: Do not include expr.h. Explain why rtl.h has to be included. Include splay-tree.h. * method.c: Do not include rtl.h and expr.h. (use_thunk): Use plain NULL instead of NULL_RTX. * except.c: Do not include rtl.h, expr.h, and libfuncs.h. * tree.c: Do not include rtl.h, insn-config.h, integrate.h, and target.h. Include splay-tree.h. * expr.c: Do not include rtl.h and expr.h. * pt.c: Do not include obstack.h and rtl.h. (tsubst_friend_function): Use plain NULL instead of NULL_RTX. (tsubst_decl): Likewise. (instantiate_decl): Likewise. * semantics.c: Do not include exprt.h and debug.h. Explain why rtl.h has to be included. * decl2.c: Do not include rtl.h and expr.h. Include splay-tree.h. * call.c: Do not include rtl.h and expr.h. * search.c: Do not include obstack.h and rtl.h. * friend.c: Do not include rtl.h and expr.h. * Make-lang.in: Update dependencies. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@159839 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index bf80c096d7e..3e56417ff36 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -27,8 +27,6 @@ along with GCC; see the file COPYING3. If not see #include "coretypes.h" #include "tm.h" #include "tree.h" -#include "rtl.h" -#include "expr.h" #include "cp-tree.h" #include "flags.h" #include "output.h" -- cgit v1.2.1 From dbfcf37800a9f03b43c0ecf2e9f317439deb26ac Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 2 Jun 2010 03:55:42 +0000 Subject: DR 990 * call.c (add_list_candidates): Prefer the default constructor. (build_aggr_conv): Treat missing initializers like { }. * typeck2.c (process_init_constructor_record): Likewise. * init.c (expand_default_init): Use digest_init for direct aggregate initialization, too. * call.c (add_list_candidates): Split out... (build_user_type_conversion_1): ...from here. (build_new_method_call): And here. (implicit_conversion): Propagate LOOKUP_NO_NARROWING. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@160132 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 3e56417ff36..1f3e8035382 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1308,6 +1308,18 @@ expand_default_init (tree binfo, tree true_exp, tree exp, tree init, int flags, tree rval; VEC(tree,gc) *parms; + if (init && BRACE_ENCLOSED_INITIALIZER_P (init) + && CP_AGGREGATE_TYPE_P (type)) + { + /* A brace-enclosed initializer for an aggregate. In C++0x this can + happen for direct-initialization, too. */ + init = digest_init (type, init); + init = build2 (INIT_EXPR, TREE_TYPE (exp), exp, init); + TREE_SIDE_EFFECTS (init) = 1; + finish_expr_stmt (init); + return; + } + if (init && TREE_CODE (init) != TREE_LIST && (flags & LOOKUP_ONLYCONVERTING)) { @@ -1320,12 +1332,6 @@ expand_default_init (tree binfo, tree true_exp, tree exp, tree init, int flags, to run a new constructor; and catching an exception, where we have already built up the constructor call so we could wrap it in an exception region. */; - else if (BRACE_ENCLOSED_INITIALIZER_P (init) - && CP_AGGREGATE_TYPE_P (type)) - { - /* A brace-enclosed initializer for an aggregate. */ - init = digest_init (type, init); - } else init = ocp_convert (type, init, CONV_IMPLICIT|CONV_FORCE_TEMP, flags); -- cgit v1.2.1 From 869dcfe4e732da27f580387d0caf1d494b114d60 Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 7 Jun 2010 20:42:37 +0000 Subject: * cp-tree.h (COMPLETE_OR_OPEN_TYPE_P): New macro. * init.c (build_offset_ref): Use it. * pt.c (maybe_process_partial_specialization): Use it. (instantiate_class_template): Use it. * search.c (lookup_base): Use it. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@160398 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 1f3e8035382..66451b1e356 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1520,8 +1520,7 @@ build_offset_ref (tree type, tree member, bool address_p) /* Callers should call mark_used before this point. */ gcc_assert (!DECL_P (member) || TREE_USED (member)); - if (!COMPLETE_TYPE_P (complete_type (type)) - && !TYPE_BEING_DEFINED (type)) + if (!COMPLETE_OR_OPEN_TYPE_P (complete_type (type))) { error ("incomplete type %qT does not have member %qD", type, member); return error_mark_node; -- cgit v1.2.1 From 183407eee40eeb1aa710d1b41eb7e68a2664849b Mon Sep 17 00:00:00 2001 From: pzhao Date: Fri, 11 Jun 2010 03:54:28 +0000 Subject: 2010-06-11 Shujing Zhao * cp-tree.h (expr_list_kind): New type. (impl_conv_rhs): New type. (build_x_compound_expr_from_list, convert_for_initialization): Adjust prototype. (typeck.c (convert_arguments): Use impl_conv_rhs and emit the diagnostics for easy translation. Change caller. (convert_for_initialization): Use impl_conv_rhs and change caller. (build_x_compound_expr_from_list): Use expr_list_kind and emit the diagnostics for easy translation. Change caller. * decl.c (bad_spec_place): New enum. (bad_specifiers): Use it and emit the diagnostics for easy translation. Change caller. * pt.c (coerce_template_parms): Put the diagnostics in full sentence. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@160591 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 66451b1e356..84e486cea46 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -526,7 +526,7 @@ perform_member_init (tree member, tree init) else if (TREE_CODE (init) == TREE_LIST) /* There was an explicit member initialization. Do some work in that case. */ - init = build_x_compound_expr_from_list (init, "member initializer"); + init = build_x_compound_expr_from_list (init, ELK_MEM_INIT); if (init) finish_expr_stmt (cp_build_modify_expr (decl, INIT_EXPR, init, -- cgit v1.2.1 From 596981c8fa329037fcb1297eaa219a36ad323e3e Mon Sep 17 00:00:00 2001 From: steven Date: Mon, 28 Jun 2010 10:52:46 +0000 Subject: gcc/ChangeLog: 2010-06-28 Steven Bosscher * system.h: Poison GCC_EXCEPT_H for front-end files. * langhooks.h (struct lang_hooks): Add eh_protect_cleanup_actions langhook. * langhooks-def.h (LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS) New. Define to NULL by default. * except.h: Define GCC_EXCEPT_H. (doing_eh): Remove prototype. (init_eh, init_eh_for_function): Move prototypes to toplev.h. (lang_protect_cleanup_actions): Remove. * except.c (lang_protect_cleanup_actions): Remove. (doing_eh): Remove. (gen_eh_region): Don't check doing_eh here. * toplev.h (init_eh, init_eh_for_function_): Moved from except.h. * tree-eh.c (honor_protect_cleanup_actions): Use new langhook instead of lang_protect_cleanup_actions. * omp-low.c (maybe_catch_exception): Likewise. * Makefile.in: Update dependencies. gcc/c-family/ChangeLog: 2010-06-28 Steven Bosscher * c-cppbuiltin.c: Do not include except.h. gcc/objc/ChangeLog: 2010-06-28 Steven Bosscher * objc-act.c: Do not include except.h. gcc/cp/ChangeLog: 2010-06-28 Steven Bosscher * init.c: Do not include except.h. * decl.c: Likewise. * expr.c: Likewise. * cp-lang.c: Likewise. * pt.c: Likewise. * semantics.c: Likewise. * decl2.c: Likewise. * except.c: Likewise. (init_exception_processing): Do not set the removed lang_protect_cleanup_actions here. (cp_protect_cleanup_actions): Make non-static and remove prototype. (doing_eh): New, moved from except.c but removed the do_warning flag. (expand_start_catch_block): Update doing_eh call. (expand_end_catch_block): Likewise. (build_throw): Likewise. * cp-tree.h: Prototype cp_protect_cleanup_actions. * cp-objcp-common.h: Set LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS to cp_protect_cleanup_actions. * Make-lang.in: Update dependencies. gcc/objcp/ChangeLog: 2010-06-28 Steven Bosscher * objcp-lang.c: Do not include except.h. * Make-lang.in: Update dependencies. gcc/java/ChangeLog: 2010-06-28 Steven Bosscher * lang.c: Do not include except.h * except.c: Likewise. (doing_eh): New, moved from except.c (in gcc/) but removed the do_warning flag. (maybe_start_try): Update doing_eh call. * Make-lang.in: Update dependencies. gcc/ada/ChangeLog: 2010-06-28 Steven Bosscher * gcc-interface/misc.c: Do not include except.h. * gcc-interface/Make-lang.in: Update dependencies. gcc/fortran/ChangeLog: 2010-06-28 Steven Bosscher * Make-lang.in: Update dependencies. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@161484 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 1 - 1 file changed, 1 deletion(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 84e486cea46..30808b233ce 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -30,7 +30,6 @@ along with GCC; see the file COPYING3. If not see #include "cp-tree.h" #include "flags.h" #include "output.h" -#include "except.h" #include "toplev.h" #include "target.h" -- cgit v1.2.1 From e67b8324af5ff08a8c7567383d34b276d78e1ceb Mon Sep 17 00:00:00 2001 From: jason Date: Tue, 29 Jun 2010 19:29:14 +0000 Subject: * pt.c (dependent_scope_ref_p): Remove. (value_dependent_expression_p): Don't call it. (type_dependent_expression_p): Here either. * init.c (build_offset_ref): Set TREE_TYPE on a qualified-id if the scope isn't dependent. * pt.c (convert_nontype_argument): Use mark_lvalue_use if we want a reference. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@161560 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 30808b233ce..7df57ab9e98 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1508,8 +1508,17 @@ build_offset_ref (tree type, tree member, bool address_p) return member; if (dependent_type_p (type) || type_dependent_expression_p (member)) - return build_qualified_name (NULL_TREE, type, member, - /*template_p=*/false); + { + tree ref, mem_type = NULL_TREE; + if (!dependent_scope_p (type)) + mem_type = TREE_TYPE (member); + ref = build_qualified_name (mem_type, type, member, + /*template_p=*/false); + /* Undo convert_from_reference. */ + if (TREE_CODE (ref) == INDIRECT_REF) + ref = TREE_OPERAND (ref, 0); + return ref; + } gcc_assert (TYPE_P (type)); if (! is_class_type (type, 1)) -- cgit v1.2.1 From ab8002def2756caef8dab23e0fd27c446dbd343e Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 30 Jun 2010 00:50:34 +0000 Subject: * cp-tree.h (TYPE_HAS_ASSIGN_REF): Rename to TYPE_HAS_COPY_ASSIGN. (TYPE_HAS_CONST_ASSIGN_REF): Rename to TYPE_HAS_CONST_COPY_ASSIGN. (TYPE_HAS_INIT_REF): Rename to TYPE_HAS_COPY_CTOR. (TYPE_HAS_CONST_INIT_REF): Rename to TYPE_HAS_CONST_COPY_CTOR. (TYPE_HAS_COMPLEX_ASSIGN_REF): Rename to TYPE_HAS_COMPLEX_COPY_ASSIGN. (TYPE_HAS_COMPLEX_INIT_REF): Rename to TYPE_HAS_COMPLEX_COPY_CTOR. (TYPE_HAS_TRIVIAL_ASSIGN_REF): Rename to TYPE_HAS_TRIVIAL_COPY_ASSIGN. (TYPE_HAS_TRIVIAL_INIT_REF): Rename to TYPE_HAS_TRIVIAL_COPY_CTOR. (CLASSTYPE_LAZY_ASSIGNMENT_OP): Rename to CLASSTYPE_LAZY_COPY_ASSIGN. (sfk_assignment_operator): Rename to sfk_copy_assignment. * decl.c, call.c, class.c, init.c, method.c, pt.c, ptree.c: Adjust. * search.c, semantics.c, tree.c: Adjust. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@161577 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 7df57ab9e98..85ad582f2d1 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2834,7 +2834,7 @@ build_vec_init (tree base, tree maxindex, tree init, && TREE_CODE (atype) == ARRAY_TYPE && (from_array == 2 ? (!CLASS_TYPE_P (inner_elt_type) - || !TYPE_HAS_COMPLEX_ASSIGN_REF (inner_elt_type)) + || !TYPE_HAS_COMPLEX_COPY_ASSIGN (inner_elt_type)) : !TYPE_NEEDS_CONSTRUCTING (type)) && ((TREE_CODE (init) == CONSTRUCTOR /* Don't do this if the CONSTRUCTOR might contain something -- cgit v1.2.1 From dab3247a40d1376d0e1492670884a3041a86f840 Mon Sep 17 00:00:00 2001 From: pzhao Date: Tue, 6 Jul 2010 05:53:49 +0000 Subject: /cp 2010-07-06 Shujing Zhao * cp-tree.h (impl_conv_void): New type. (convert_to_void): Adjust prototype. * cvt.c (convert_to_void): Use impl_conv_void, emit and adjust the diagnostic for easy translation. Change caller. * typeck.c: Update call to convert_to_void. * semantics.c: Likewise. * init.c: Likewise. /testsuite 2010-07-06 Shujing Zhao * g++.dg/warn/noeffect2.C: Adjust expected warning. * g++.dg/warn/volatile1.C: Likewise. * g++.dg/template/warn1.C: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@161863 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 85ad582f2d1..ec7dca936c9 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1374,7 +1374,7 @@ expand_default_init (tree binfo, tree true_exp, tree exp, tree init, int flags, release_tree_vector (parms); if (TREE_SIDE_EFFECTS (rval)) - finish_expr_stmt (convert_to_void (rval, NULL, complain)); + finish_expr_stmt (convert_to_void (rval, ICV_CAST, complain)); } /* This function is responsible for initializing EXP with INIT @@ -2726,7 +2726,7 @@ build_vec_delete_1 (tree base, tree maxindex, tree type, /* Pre-evaluate the SAVE_EXPR outside of the BIND_EXPR. */ body = build2 (COMPOUND_EXPR, void_type_node, base, body); - return convert_to_void (body, /*implicit=*/NULL, tf_warning_or_error); + return convert_to_void (body, ICV_CAST, tf_warning_or_error); } /* Create an unnamed variable of the indicated TYPE. */ -- cgit v1.2.1 From 7d19d445164b30f521eb64e229b6cabe30ccb8e2 Mon Sep 17 00:00:00 2001 From: jason Date: Tue, 6 Jul 2010 19:22:49 +0000 Subject: PR c++/44778 * init.c (build_offset_ref): If scope isn't dependent, don't exit early. Look at TYPE_MAIN_VARIANT. * pt.c (tsubst_copy) [OFFSET_REF]: Do substitution. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@161879 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index ec7dca936c9..20f921db7a7 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1507,18 +1507,9 @@ build_offset_ref (tree type, tree member, bool address_p) if (TREE_CODE (member) == TEMPLATE_DECL) return member; - if (dependent_type_p (type) || type_dependent_expression_p (member)) - { - tree ref, mem_type = NULL_TREE; - if (!dependent_scope_p (type)) - mem_type = TREE_TYPE (member); - ref = build_qualified_name (mem_type, type, member, + if (dependent_scope_p (type) || type_dependent_expression_p (member)) + return build_qualified_name (NULL_TREE, type, member, /*template_p=*/false); - /* Undo convert_from_reference. */ - if (TREE_CODE (ref) == INDIRECT_REF) - ref = TREE_OPERAND (ref, 0); - return ref; - } gcc_assert (TYPE_P (type)); if (! is_class_type (type, 1)) @@ -1528,6 +1519,7 @@ build_offset_ref (tree type, tree member, bool address_p) /* Callers should call mark_used before this point. */ gcc_assert (!DECL_P (member) || TREE_USED (member)); + type = TYPE_MAIN_VARIANT (type); if (!COMPLETE_OR_OPEN_TYPE_P (complete_type (type))) { error ("incomplete type %qT does not have member %qD", type, member); -- cgit v1.2.1 From 80e5473297f3b9131a8e689f9a60714e486c72fb Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 14 Jul 2010 17:00:51 +0000 Subject: Implement C++0x unrestricted unions (N2544) * class.c (check_field_decl): Loosen union handling in C++0x. * method.c (walk_field_subobs): Split out from... (synthesized_method_walk): ...here. Set msg before loops. (process_subob_fn): Check for triviality in union members. * init.c (sort_mem_initializers): Splice out uninitialized anonymous unions and union members. (push_base_cleanups): Don't automatically destroy anonymous unions and union members. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@162187 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 53 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 12 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 20f921db7a7..4e7cab382aa 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -708,23 +708,34 @@ sort_mem_initializers (tree t, tree mem_inits) If a ctor-initializer specifies more than one mem-initializer for multiple members of the same union (including members of - anonymous unions), the ctor-initializer is ill-formed. */ + anonymous unions), the ctor-initializer is ill-formed. + + Here we also splice out uninitialized union members. */ if (uses_unions_p) { tree last_field = NULL_TREE; - for (init = sorted_inits; init; init = TREE_CHAIN (init)) + tree *p; + for (p = &sorted_inits; *p; ) { tree field; tree field_type; int done; - /* Skip uninitialized members and base classes. */ - if (!TREE_VALUE (init) - || TREE_CODE (TREE_PURPOSE (init)) != FIELD_DECL) - continue; + init = *p; + + field = TREE_PURPOSE (init); + + /* Skip base classes. */ + if (TREE_CODE (field) != FIELD_DECL) + goto next; + + /* If this is an anonymous union with no explicit initializer, + splice it out. */ + if (!TREE_VALUE (init) && ANON_UNION_TYPE_P (TREE_TYPE (field))) + goto splice; + /* See if this field is a member of a union, or a member of a structure contained in a union, etc. */ - field = TREE_PURPOSE (init); for (field_type = DECL_CONTEXT (field); !same_type_p (field_type, t); field_type = TYPE_CONTEXT (field_type)) @@ -732,14 +743,19 @@ sort_mem_initializers (tree t, tree mem_inits) break; /* If this field is not a member of a union, skip it. */ if (TREE_CODE (field_type) != UNION_TYPE) - continue; + goto next; + + /* If this union member has no explicit initializer, splice + it out. */ + if (!TREE_VALUE (init)) + goto splice; /* It's only an error if we have two initializers for the same union type. */ if (!last_field) { last_field = field; - continue; + goto next; } /* See if LAST_FIELD and the field initialized by INIT are @@ -785,6 +801,13 @@ sort_mem_initializers (tree t, tree mem_inits) while (!done); last_field = field; + + next: + p = &TREE_CHAIN (*p); + continue; + splice: + *p = TREE_CHAIN (*p); + continue; } } @@ -3353,21 +3376,27 @@ push_base_cleanups (void) finish_decl_cleanup (NULL_TREE, expr); } + /* Don't automatically destroy union members. */ + if (TREE_CODE (current_class_type) == UNION_TYPE) + return; + for (member = TYPE_FIELDS (current_class_type); member; member = TREE_CHAIN (member)) { - if (TREE_TYPE (member) == error_mark_node + tree this_type = TREE_TYPE (member); + if (this_type == error_mark_node || TREE_CODE (member) != FIELD_DECL || DECL_ARTIFICIAL (member)) continue; - if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (member))) + if (ANON_UNION_TYPE_P (this_type)) + continue; + if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (this_type)) { tree this_member = (build_class_member_access_expr (current_class_ref, member, /*access_path=*/NULL_TREE, /*preserve_reference=*/false, tf_warning_or_error)); - tree this_type = TREE_TYPE (member); expr = build_delete (this_type, this_member, sfk_complete_destructor, LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL, -- cgit v1.2.1 From b01002fa49f5b80858f539a7791e259b8781dfad Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 14 Jul 2010 17:01:03 +0000 Subject: * init.c (sort_mem_initializers): Rename "field_type" to "ctx". (build_field_list): Cache field type. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@162188 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 4e7cab382aa..98a45cd41b2 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -564,25 +564,27 @@ build_field_list (tree t, tree list, int *uses_unions_p) for (fields = TYPE_FIELDS (t); fields; fields = TREE_CHAIN (fields)) { + tree fieldtype; + /* Skip CONST_DECLs for enumeration constants and so forth. */ if (TREE_CODE (fields) != FIELD_DECL || DECL_ARTIFICIAL (fields)) continue; + fieldtype = TREE_TYPE (fields); /* Keep track of whether or not any fields are unions. */ - if (TREE_CODE (TREE_TYPE (fields)) == UNION_TYPE) + if (TREE_CODE (fieldtype) == UNION_TYPE) *uses_unions_p = 1; /* For an anonymous struct or union, we must recursively consider the fields of the anonymous type. They can be directly initialized from the constructor. */ - if (ANON_AGGR_TYPE_P (TREE_TYPE (fields))) + if (ANON_AGGR_TYPE_P (fieldtype)) { /* Add this field itself. Synthesized copy constructors initialize the entire aggregate. */ list = tree_cons (fields, NULL_TREE, list); /* And now add the fields in the anonymous aggregate. */ - list = build_field_list (TREE_TYPE (fields), list, - uses_unions_p); + list = build_field_list (fieldtype, list, uses_unions_p); } /* Add this field. */ else if (DECL_NAME (fields)) @@ -718,7 +720,7 @@ sort_mem_initializers (tree t, tree mem_inits) for (p = &sorted_inits; *p; ) { tree field; - tree field_type; + tree ctx; int done; init = *p; @@ -736,13 +738,13 @@ sort_mem_initializers (tree t, tree mem_inits) /* See if this field is a member of a union, or a member of a structure contained in a union, etc. */ - for (field_type = DECL_CONTEXT (field); - !same_type_p (field_type, t); - field_type = TYPE_CONTEXT (field_type)) - if (TREE_CODE (field_type) == UNION_TYPE) + for (ctx = DECL_CONTEXT (field); + !same_type_p (ctx, t); + ctx = TYPE_CONTEXT (ctx)) + if (TREE_CODE (ctx) == UNION_TYPE) break; /* If this field is not a member of a union, skip it. */ - if (TREE_CODE (field_type) != UNION_TYPE) + if (TREE_CODE (ctx) != UNION_TYPE) goto next; /* If this union member has no explicit initializer, splice @@ -766,37 +768,37 @@ sort_mem_initializers (tree t, tree mem_inits) union { struct { int i; int j; }; }; initializing both `i' and `j' makes sense. */ - field_type = DECL_CONTEXT (field); + ctx = DECL_CONTEXT (field); done = 0; do { - tree last_field_type; + tree last_ctx; - last_field_type = DECL_CONTEXT (last_field); + last_ctx = DECL_CONTEXT (last_field); while (1) { - if (same_type_p (last_field_type, field_type)) + if (same_type_p (last_ctx, ctx)) { - if (TREE_CODE (field_type) == UNION_TYPE) + if (TREE_CODE (ctx) == UNION_TYPE) error_at (DECL_SOURCE_LOCATION (current_function_decl), "initializations for multiple members of %qT", - last_field_type); + last_ctx); done = 1; break; } - if (same_type_p (last_field_type, t)) + if (same_type_p (last_ctx, t)) break; - last_field_type = TYPE_CONTEXT (last_field_type); + last_ctx = TYPE_CONTEXT (last_ctx); } /* If we've reached the outermost class, then we're done. */ - if (same_type_p (field_type, t)) + if (same_type_p (ctx, t)) break; - field_type = TYPE_CONTEXT (field_type); + ctx = TYPE_CONTEXT (ctx); } while (!done); -- cgit v1.2.1 From 1767a056f10a2ccbc900df04d01193da73a3d272 Mon Sep 17 00:00:00 2001 From: froydnj Date: Thu, 15 Jul 2010 14:31:28 +0000 Subject: gcc/ * tree.h (DECL_CHAIN): Define. * alias.c: Carefully replace TREE_CHAIN with DECL_CHAIN. * c-decl.c: Likewise. * c-parser.c: Likewise. * c-typeck.c: Likewise. * cfgexpand.c: Likewise. * cgraph.c: Likewise. * cgraphunit.c: Likewise. * combine.c: Likewise. * config/alpha/alpha.c: Likewise. * config/arm/arm.c: Likewise. * config/frv/frv.c: Likewise. * config/i386/i386.c: Likewise. * config/i386/winnt-cxx.c: Likewise. * config/ia64/ia64.c: Likewise. * config/iq2000/iq2000.c: Likewise. * config/mep/mep.c: Likewise. * config/mips/mips.c: Likewise. * config/pa/som.h: Likewise. * config/rs6000/rs6000.c: Likewise. * config/s390/s390.c: Likewise. * config/sh/sh.c: Likewise. * config/sh/symbian-cxx.c: Likewise. * config/sparc/sparc.c: Likewise. * config/spu/spu.c: Likewise. * config/stormy16/stormy16.c: Likewise. * config/vxworks.c: Likewise. * config/xtensa/xtensa.c: Likewise. * coverage.c: Likewise. * dbxout.c: Likewise. * dwarf2out.c: Likewise. * emit-rtl.c: Likewise. * expr.c: Likewise. * function.c: Likewise. * gimple-low.c: Likewise. * gimple-pretty-print.c: Likewise. * gimplify.c: Likewise. * integrate.c: Likewise. * ipa-inline.c: Likewise. * ipa-prop.c: Likewise. * ipa-split.c: Likewise. * ipa-struct-reorg.c: Likewise. * ipa-type-escape.c: Likewise. * langhooks.c: Likewise. * lto-cgraph.c: Likewise. * omp-low.c: Likewise. * stor-layout.c: Likewise. * tree-cfg.c: Likewise. * tree-complex.c: Likewise. * tree-dfa.c: Likewise. * tree-dump.c: Likewise. * tree-inline.c: Likewise. * tree-mudflap.c: Likewise. * tree-nested.c: Likewise. * tree-object-size.c: Likewise. * tree-pretty-print.c: Likewise. * tree-sra.c: Likewise. * tree-ssa-live.c: Likewise. * tree-ssa-loop-niter.c: Likewise. * tree-ssa-math-opts.c: Likewise. * tree-ssa-reassoc.c: Likewise. * tree-ssa-sccvn.c: Likewise. * tree-ssa-structalias.c: Likewise. * tree-tailcall.c: Likewise. * tree-vrp.c: Likewise. * tree.c: Likewise. * var-tracking.c: Likewise. * varasm.c: Likewise. gcc/ada/ * gcc-interface/decl.c: Carefully replace TREE_CHAIN with DECL_CHAIN. * gcc-interface/trans.c: Likewise. * gcc-interface/utils.c: Likewise. * gcc-interface/utils2.c: Likewise. gcc/c-family/ * c-common.c: Carefully replace TREE_CHAIN with DECL_CHAIN. * c-format.c: Likewise. gcc/cp/ * cp-tree.h: Carefully replace TREE_CHAIN with DECL_CHAIN. * call.c: Likewise. * class.c: Likewise. * cp-gimplify.c: Likewise. * decl.c: Likewise. * decl2.c: Likewise. * init.c: Likewise. * mangle.c: Likewise. * name-lookup.c: Likewise. * optimize.c: Likewise. * parser.c: Likewise. * pt.c: Likewise. * rtti.c: Likewise. * search.c: Likewise. * semantics.c: Likewise. * typeck.c: Likewise. * typeck2.c: Likewise. gcc/fortran/ * f95-lang.c: Carefully replace TREE_CHAIN with DECL_CHAIN. * trans-common.c: Likewise. * trans-decl.c: Likewise. * trans-types.c: Likewise. * trans.c: Likewise. gcc/java/ * java-tree.h: Carefully replace TREE_CHAIN with DECL_CHAIN. * boehm.c: Likewise. * class.c: Likewise. * decl.c: Likewise. * expr.c: Likewise. * jcf-parse.c: Likewise. * typeck.c: Likewise. * verify-glue.c: Likewise. gcc/objc/ * objc-act.c: Carefully replace TREE_CHAIN with DECL_CHAIN. gcc/testsuite/ * g++.dg/plugin/attribute_plugin.c: Carefully replace TREE_CHAIN with DECL_CHAIN. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@162223 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 98a45cd41b2..507da922b4c 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -184,7 +184,7 @@ build_zero_init (tree type, tree nelts, bool static_storage_p) VEC(constructor_elt,gc) *v = NULL; /* Iterate over the fields, building initializations. */ - for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) + for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) { if (TREE_CODE (field) != FIELD_DECL) continue; @@ -337,7 +337,7 @@ build_value_init_noctor (tree type) VEC(constructor_elt,gc) *v = NULL; /* Iterate over the fields, building initializations. */ - for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) + for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) { tree ftype, value; @@ -562,7 +562,7 @@ build_field_list (tree t, tree list, int *uses_unions_p) if (TREE_CODE (t) == UNION_TYPE) *uses_unions_p = 1; - for (fields = TYPE_FIELDS (t); fields; fields = TREE_CHAIN (fields)) + for (fields = TYPE_FIELDS (t); fields; fields = DECL_CHAIN (fields)) { tree fieldtype; @@ -1030,7 +1030,7 @@ construct_virtual_base (tree vbase, tree arguments) in the outer block.) We trust the back end to figure out that the FLAG will not change across initializations, and avoid doing multiple tests. */ - flag = TREE_CHAIN (DECL_ARGUMENTS (current_function_decl)); + flag = DECL_CHAIN (DECL_ARGUMENTS (current_function_decl)); inner_if_stmt = begin_if_stmt (); finish_if_stmt_cond (flag, inner_if_stmt); @@ -1815,7 +1815,7 @@ diagnose_uninitialized_cst_or_ref_member_1 (tree type, tree origin, if (type_has_user_provided_constructor (type)) return 0; - for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) + for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) { tree field_type; @@ -2578,7 +2578,7 @@ build_java_class_ref (tree type) /* Mangle the class$ field. */ { tree field; - for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) + for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) if (DECL_NAME (field) == CL_suffix) { mangle_decl (field); @@ -3383,7 +3383,7 @@ push_base_cleanups (void) return; for (member = TYPE_FIELDS (current_class_type); member; - member = TREE_CHAIN (member)) + member = DECL_CHAIN (member)) { tree this_type = TREE_TYPE (member); if (this_type == error_mark_node -- cgit v1.2.1 From 49a7740d272211fea3cef5d8dad74da60f972928 Mon Sep 17 00:00:00 2001 From: froydnj Date: Fri, 16 Jul 2010 02:37:10 +0000 Subject: * init.c (build_new_1): Use cp_build_function_call_nary instead of cp_build_function_call. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@162241 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 507da922b4c..5da8191a8f8 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2033,10 +2033,8 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts, } alloc_fn = OVL_CURRENT (alloc_fn); class_addr = build1 (ADDR_EXPR, jclass_node, class_decl); - alloc_call = (cp_build_function_call - (alloc_fn, - build_tree_list (NULL_TREE, class_addr), - complain)); + alloc_call = cp_build_function_call_nary (alloc_fn, complain, + class_addr, NULL_TREE); } else if (TYPE_FOR_JAVA (elt_type) && MAYBE_CLASS_TYPE_P (elt_type)) { -- cgit v1.2.1 From 1f3d2e3f83165b46221d86b0a39ad34246c1319b Mon Sep 17 00:00:00 2001 From: paolo Date: Mon, 19 Jul 2010 10:27:58 +0000 Subject: /cp 2010-07-19 Paolo Carlini PR c++/44969 * typeck.c (build_x_compound_expr_from_list): Add tsubst_flags_t parameter. * cp-tree.h: Adjust declaration. * init.c (perform_member_init): Adjust caller. * decl.c (grok_reference_init, cp_finish_decl): Likewise. * typeck2.c (store_init_value): Likewise. (build_functional_cast): Pass complain argument to build_x_compound_expr_from_list. /testsuite 2010-07-19 Paolo Carlini PR c++/44969 * g++.dg/template/sfinae23.C: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@162303 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/init.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 5da8191a8f8..d796fd0822c 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -525,7 +525,8 @@ perform_member_init (tree member, tree init) else if (TREE_CODE (init) == TREE_LIST) /* There was an explicit member initialization. Do some work in that case. */ - init = build_x_compound_expr_from_list (init, ELK_MEM_INIT); + init = build_x_compound_expr_from_list (init, ELK_MEM_INIT, + tf_warning_or_error); if (init) finish_expr_stmt (cp_build_modify_expr (decl, INIT_EXPR, init, -- cgit v1.2.1