From c36e63fe2b701030011e6fcea3c6749dc80b591d Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 13 Nov 2017 21:49:16 +0000 Subject: PR c++/82360 - ICE with static_cast in template. * call.c (perform_direct_initialization_if_possible): Check processing_template_decl. * typeck.c (build_static_cast_1): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254710 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/call.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gcc/cp/call.c') diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 6875492e687..e6e0f901166 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -10647,6 +10647,16 @@ perform_direct_initialization_if_possible (tree type, LOOKUP_NORMAL, complain); if (!conv || conv->bad_p) expr = NULL_TREE; + else if (processing_template_decl && conv->kind != ck_identity) + { + /* In a template, we are only concerned about determining the + type of non-dependent expressions, so we do not have to + perform the actual conversion. But for initializers, we + need to be able to perform it at instantiation + (or instantiate_non_dependent_expr) time. */ + expr = build1 (IMPLICIT_CONV_EXPR, type, expr); + IMPLICIT_CONV_EXPR_DIRECT_INIT (expr) = true; + } else expr = convert_like_real (conv, expr, NULL_TREE, 0, /*issue_conversion_warnings=*/false, -- cgit v1.2.1 From 0744a0c1155bca3b0fee47ad2ac40a2652968bd4 Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 13 Nov 2017 22:12:55 +0000 Subject: Defer folding of *&. * typeck.c (cp_build_fold_indirect_ref): New. (cp_build_indirect_ref_1): Split out from cp_build_indirect_ref. Add 'fold' parameter. * cp-tree.h: Declare cp_build_fold_indirect_ref. * call.c, class.c, cp-ubsan.c, decl.c, except.c, init.c, lambda.c, parser.c, rtti.c, tree.c, typeck.c, typeck2.c: Use it. * parser.c (do_range_for_auto_deduction): Use RO_UNARY_STAR. (cp_convert_range_for): Likewise. * typeck2.c (build_x_arrow): Use RO_ARROW. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254712 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/call.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'gcc/cp/call.c') diff --git a/gcc/cp/call.c b/gcc/cp/call.c index e6e0f901166..e18f0770614 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -8063,7 +8063,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) if (targ) arg = targ; else - arg = cp_build_indirect_ref (arg, RO_NULL, complain); + arg = cp_build_fold_indirect_ref (arg); /* In C++17 we shouldn't be copying a TARGET_EXPR except into a base subobject. */ @@ -8100,9 +8100,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) else if ((trivial || TREE_CODE (arg) == TARGET_EXPR) && !unsafe_copy_elision_p (fa, arg)) { - tree to = cp_stabilize_reference (cp_build_indirect_ref (fa, - RO_NULL, - complain)); + tree to = cp_stabilize_reference (cp_build_fold_indirect_ref (fa)); val = build2 (INIT_EXPR, DECL_CONTEXT (fn), to, arg); return val; @@ -8114,7 +8112,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) && !DECL_DELETED_FN (fn)) { tree to = cp_stabilize_reference - (cp_build_indirect_ref (argarray[0], RO_NULL, complain)); + (cp_build_fold_indirect_ref (argarray[0])); tree type = TREE_TYPE (to); tree as_base = CLASSTYPE_AS_BASE (type); tree arg = argarray[1]; @@ -8127,7 +8125,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) } else if (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (as_base))) { - arg = cp_build_indirect_ref (arg, RO_NULL, complain); + arg = cp_build_fold_indirect_ref (arg); val = build2 (MODIFY_EXPR, TREE_TYPE (to), to, arg); /* Handle NSDMI that refer to the object being initialized. */ replace_placeholders (arg, to); @@ -8166,7 +8164,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) return force_target_expr (DECL_CONTEXT (fn), void_node, no_cleanup_complain); else - return cp_build_indirect_ref (argarray[0], RO_NULL, complain); + return cp_build_fold_indirect_ref (argarray[0]); } } -- cgit v1.2.1 From 297de7bc513f3f2eb82dde14ecc7f0661aa667db Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 13 Nov 2017 22:34:38 +0000 Subject: Capture adjustments for P0588R1. * semantics.c (process_outer_var_ref): Capture variables when they are named; complain about non-capture uses when odr-used. * expr.c (mark_use): Rvalue use looks through capture proxy. * constexpr.c (potential_constant_expression_1): Improve error about use of captured variable. * lambda.c (need_generic_capture, dependent_capture_r) (do_dependent_capture, processing_nonlambda_template): Remove. * call.c (build_this): Remove uses of the above. * decl.c (cp_finish_decl): Likewise. * semantics.c (maybe_cleanup_point_expr) (maybe_cleanup_point_expr_void, finish_goto_stmt) (maybe_convert_cond): Likewise. * typeck.c (check_return_expr): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254713 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/call.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/cp/call.c') diff --git a/gcc/cp/call.c b/gcc/cp/call.c index e18f0770614..e09cf97920b 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -3365,7 +3365,7 @@ build_this (tree obj) { /* In a template, we are only concerned about the type of the expression, so we can take a shortcut. */ - if (processing_nonlambda_template ()) + if (processing_template_decl) return build_address (obj); return cp_build_addr_expr (obj, tf_warning_or_error); -- cgit v1.2.1