From 9f613f06b0da4b11cde815351df31ad74e22f449 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 14 May 2018 14:55:21 +0000 Subject: [PATCH] cp-tree.h (TYPE_REF_P): New. 2018-05-14 Paolo Carlini * cp-tree.h (TYPE_REF_P): New. (TYPE_OBJ_P, TYPE_REF_OBJ_P, TYPE_REFFN_P): Update. * call.c (build_list_conv, build_aggr_conv, standard_conversion, direct_reference_binding, reference_binding, implicit_conversion, add_builtin_candidate, build_user_type_conversion_1, build_op_call_1, build_new_op_1, build_x_va_arg, conv_binds_ref_to_prvalue, build_over_call, perform_implicit_conversion_flags, extend_ref_init_temps, type_has_extended_temps): Use it. * class.c (one_inheriting_sig, check_field_decls, check_bases_and_members, find_flexarrays, finish_struct, fixed_type_or_null): Likewise. * constexpr.c (literal_type_p, cxx_bind_parameters_in_call, non_const_var_error, cxx_eval_constant_expression, potential_constant_expression_1): Likewise. * cp-gimplify.c (omp_var_to_track, omp_cxx_notice_variable, cp_genericize_r, cxx_omp_privatize_by_reference, cxx_omp_const_qual_no_mutable, cxx_omp_finish_clause, cp_fold_maybe_rvalue): Likewise. * cp-ubsan.c (cp_ubsan_maybe_instrument_downcast): Likewise. * cvt.c (build_up_reference, convert_to_reference, convert_from_reference, convert_to_void, noexcept_conv_p, fnptr_conv_p): Likewise. * decl.c (poplevel, check_for_uninitialized_const_var, check_initializer, initialize_local_var, cp_finish_decl, get_tuple_decomp_init, cp_finish_decomp, grokdeclarator, copy_fn_p, move_signature_fn_p, grok_op_properties, finish_function): Likewise. * decl2.c (grok_array_decl, cp_reconstruct_complex_type, decl_maybe_constant_var_p): Likewise. * error.c (dump_type_prefix, dump_expr): Likewise. * except.c (initialize_handler_parm, complete_ptr_ref_or_void_ptr_p, is_admissible_throw_operand_or_catch_parameter): Likewise. * expr.c (mark_use): Likewise. * init.c (build_zero_init_1, build_value_init_noctor, perform_member_init, diagnose_uninitialized_cst_or_ref_member_1, build_new, build_delete): Likewise. * lambda.c (build_lambda_object): Likewise. * mangle.c (write_expression, write_template_arg): Likewise. * method.c (forward_parm, do_build_copy_constructor, do_build_copy_assign, build_stub_object, constructible_expr, walk_field_subobs): Likewise. * parser.c (cp_parser_omp_for_loop_init, cp_parser_omp_declare_reduction_exprs, cp_parser_omp_declare_reduction): Likewise. * pt.c (convert_nontype_argument_function, convert_nontype_argument, convert_template_argument, tsubst_pack_expansion, tsubst_function_decl, tsubst_decl, tsubst, tsubst_copy_and_build, maybe_adjust_types_for_deduction, check_cv_quals_for_unify, unify, more_specialized_fn, invalid_nontype_parm_type_p, dependent_type_p_r, value_dependent_expression_p, build_deduction_guide): Likewise. * semantics.c (finish_handler_parms, finish_non_static_data_member, finish_compound_literal, omp_privatize_field, handle_omp_array_sections_1, handle_omp_array_sections, cp_check_omp_declare_reduction, finish_omp_reduction_clause, finish_omp_declare_simd_methods, cp_finish_omp_clause_depend_sink, finish_omp_clauses, finish_decltype_type, capture_decltype, finish_builtin_launder): Likewise. * tree.c (lvalue_kind, cp_build_reference_type, move, cp_build_qualified_type_real, stabilize_expr, stabilize_init): Likewise. * typeck.c (cxx_safe_arg_type_equiv_p, build_class_member_access_expr, cp_build_indirect_ref_1, convert_arguments, warn_for_null_address, cp_build_addr_expr_1, maybe_warn_about_useless_cast, build_static_cast_1, build_static_cast, build_reinterpret_cast_1, build_const_cast_1, cp_build_c_cast, cp_build_modify_expr, convert_for_initialization, maybe_warn_about_returning_address_of_local, check_return_expr, cp_type_quals, casts_away_constness, non_reference): Likewise. * typeck2.c (cxx_readonly_error, store_init_value, process_init_constructor_record, build_x_arrow, build_functional_cast, add_exception_specifier): Likewise. From-SVN: r260228 --- gcc/cp/ChangeLog | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/cp/call.c | 48 +++++++++++++++++------------------ gcc/cp/class.c | 18 ++++++------- gcc/cp/constexpr.c | 18 ++++++------- gcc/cp/cp-gimplify.c | 19 +++++++------- gcc/cp/cp-tree.h | 14 ++++++---- gcc/cp/cp-ubsan.c | 2 +- gcc/cp/cvt.c | 19 +++++++------- gcc/cp/decl.c | 46 ++++++++++++++++----------------- gcc/cp/decl2.c | 6 ++--- gcc/cp/error.c | 20 +++++++-------- gcc/cp/except.c | 6 ++--- gcc/cp/expr.c | 4 +-- gcc/cp/init.c | 14 +++++----- gcc/cp/lambda.c | 2 +- gcc/cp/mangle.c | 6 ++--- gcc/cp/method.c | 20 +++++++-------- gcc/cp/parser.c | 6 ++--- gcc/cp/pt.c | 52 ++++++++++++++++++------------------- gcc/cp/semantics.c | 71 +++++++++++++++++++++++++-------------------------- gcc/cp/tree.c | 14 +++++----- gcc/cp/typeck.c | 62 ++++++++++++++++++++++---------------------- gcc/cp/typeck2.c | 14 +++++----- 23 files changed, 312 insertions(+), 241 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7450598..c421471 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,75 @@ +2018-05-14 Paolo Carlini + + * cp-tree.h (TYPE_REF_P): New. + (TYPE_OBJ_P, TYPE_REF_OBJ_P, TYPE_REFFN_P): Update. + * call.c (build_list_conv, build_aggr_conv, standard_conversion, + direct_reference_binding, reference_binding, implicit_conversion, + add_builtin_candidate, build_user_type_conversion_1, build_op_call_1, + build_new_op_1, build_x_va_arg, conv_binds_ref_to_prvalue, + build_over_call, perform_implicit_conversion_flags, + extend_ref_init_temps, type_has_extended_temps): Use it. + * class.c (one_inheriting_sig, check_field_decls, + check_bases_and_members, find_flexarrays, finish_struct, + fixed_type_or_null): Likewise. + * constexpr.c (literal_type_p, cxx_bind_parameters_in_call, + non_const_var_error, cxx_eval_constant_expression, + potential_constant_expression_1): Likewise. + * cp-gimplify.c (omp_var_to_track, omp_cxx_notice_variable, + cp_genericize_r, cxx_omp_privatize_by_reference, + cxx_omp_const_qual_no_mutable, cxx_omp_finish_clause, + cp_fold_maybe_rvalue): Likewise. + * cp-ubsan.c (cp_ubsan_maybe_instrument_downcast): Likewise. + * cvt.c (build_up_reference, convert_to_reference, + convert_from_reference, convert_to_void, noexcept_conv_p, + fnptr_conv_p): Likewise. + * decl.c (poplevel, check_for_uninitialized_const_var, + check_initializer, initialize_local_var, cp_finish_decl, + get_tuple_decomp_init, cp_finish_decomp, grokdeclarator, copy_fn_p, + move_signature_fn_p, grok_op_properties, finish_function): Likewise. + * decl2.c (grok_array_decl, cp_reconstruct_complex_type, + decl_maybe_constant_var_p): Likewise. + * error.c (dump_type_prefix, dump_expr): Likewise. + * except.c (initialize_handler_parm, complete_ptr_ref_or_void_ptr_p, + is_admissible_throw_operand_or_catch_parameter): Likewise. + * expr.c (mark_use): Likewise. + * init.c (build_zero_init_1, build_value_init_noctor, + perform_member_init, diagnose_uninitialized_cst_or_ref_member_1, + build_new, build_delete): Likewise. + * lambda.c (build_lambda_object): Likewise. + * mangle.c (write_expression, write_template_arg): Likewise. + * method.c (forward_parm, do_build_copy_constructor, + do_build_copy_assign, build_stub_object, constructible_expr, + walk_field_subobs): Likewise. + * parser.c (cp_parser_omp_for_loop_init, + cp_parser_omp_declare_reduction_exprs, + cp_parser_omp_declare_reduction): Likewise. + * pt.c (convert_nontype_argument_function, convert_nontype_argument, + convert_template_argument, tsubst_pack_expansion, + tsubst_function_decl, tsubst_decl, tsubst, tsubst_copy_and_build, + maybe_adjust_types_for_deduction, check_cv_quals_for_unify, unify, + more_specialized_fn, invalid_nontype_parm_type_p, dependent_type_p_r, + value_dependent_expression_p, build_deduction_guide): Likewise. + * semantics.c (finish_handler_parms, finish_non_static_data_member, + finish_compound_literal, omp_privatize_field, + handle_omp_array_sections_1, handle_omp_array_sections, + cp_check_omp_declare_reduction, finish_omp_reduction_clause, + finish_omp_declare_simd_methods, cp_finish_omp_clause_depend_sink, + finish_omp_clauses, finish_decltype_type, capture_decltype, + finish_builtin_launder): Likewise. + * tree.c (lvalue_kind, cp_build_reference_type, move, + cp_build_qualified_type_real, stabilize_expr, stabilize_init): Likewise. + * typeck.c (cxx_safe_arg_type_equiv_p, build_class_member_access_expr, + cp_build_indirect_ref_1, convert_arguments, warn_for_null_address, + cp_build_addr_expr_1, maybe_warn_about_useless_cast, + build_static_cast_1, build_static_cast, build_reinterpret_cast_1, + build_const_cast_1, cp_build_c_cast, cp_build_modify_expr, + convert_for_initialization, + maybe_warn_about_returning_address_of_local, check_return_expr, + cp_type_quals, casts_away_constness, non_reference): Likewise. + * typeck2.c (cxx_readonly_error, store_init_value, + process_init_constructor_record, build_x_arrow, build_functional_cast, + add_exception_specifier): Likewise. + 2018-05-14 Jason Merrill * pt.c (tsubst) [ARRAY_TYPE]: Check valid_array_size_p. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 30fe682..f620c0d 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -814,7 +814,7 @@ build_list_conv (tree type, tree ctor, int flags, tsubst_flags_t complain) flags |= LOOKUP_NO_NARROWING; /* Can't make an array of these types. */ - if (TREE_CODE (elttype) == REFERENCE_TYPE + if (TYPE_REF_P (elttype) || TREE_CODE (elttype) == FUNCTION_TYPE || VOID_TYPE_P (elttype)) return NULL; @@ -915,7 +915,7 @@ build_aggr_conv (tree type, tree ctor, int flags, tsubst_flags_t complain) val = CONSTRUCTOR_ELT (ctor, i)->value; else if (DECL_INITIAL (field)) val = get_nsdmi (field, /*ctor*/false, complain); - else if (TREE_CODE (ftype) == REFERENCE_TYPE) + else if (TYPE_REF_P (ftype)) /* Value-initialization of reference is ill-formed. */ return NULL; else @@ -1105,7 +1105,7 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p, tree qualified_to; to = non_reference (to); - if (TREE_CODE (from) == REFERENCE_TYPE) + if (TYPE_REF_P (from)) { fromref = true; from = TREE_TYPE (from); @@ -1475,8 +1475,8 @@ direct_reference_binding (tree type, conversion *conv) { tree t; - gcc_assert (TREE_CODE (type) == REFERENCE_TYPE); - gcc_assert (TREE_CODE (conv->type) != REFERENCE_TYPE); + gcc_assert (TYPE_REF_P (type)); + gcc_assert (!TYPE_REF_P (conv->type)); t = TREE_TYPE (type); @@ -1567,7 +1567,7 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags, skip:; } - if (TREE_CODE (from) == REFERENCE_TYPE) + if (TYPE_REF_P (from)) { from = TREE_TYPE (from); if (!TYPE_REF_IS_RVALUE (rfrom) @@ -1633,7 +1633,7 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags, conv = build_identity_conv (tfrom, expr); conv = direct_reference_binding (rto, conv); - if (TREE_CODE (rfrom) == REFERENCE_TYPE) + if (TYPE_REF_P (rfrom)) /* Handle rvalue reference to function properly. */ conv->rvaluedness_matches_p = (TYPE_REF_IS_RVALUE (rto) == TYPE_REF_IS_RVALUE (rfrom)); @@ -1835,7 +1835,7 @@ implicit_conversion (tree to, tree from, tree expr, bool c_cast_p, from = TREE_TYPE (expr); } - if (TREE_CODE (to) == REFERENCE_TYPE) + if (TYPE_REF_P (to)) conv = reference_binding (to, from, expr, c_cast_p, flags, complain); else conv = standard_conversion (to, from, expr, c_cast_p, flags, complain); @@ -2845,7 +2845,7 @@ add_builtin_candidate (struct z_candidate **candidates, enum tree_code code, we need candidates for both of them. */ if (type2 && !same_type_p (type1, type2) && TREE_CODE (type1) == TREE_CODE (type2) - && (TREE_CODE (type1) == REFERENCE_TYPE + && (TYPE_REF_P (type1) || (TYPE_PTR_P (type1) && TYPE_PTR_P (type2)) || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2)) || TYPE_PTRMEMFUNC_P (type1) @@ -3007,11 +3007,11 @@ add_builtin_candidates (struct z_candidate **candidates, enum tree_code code, type = TREE_TYPE (convs); if (i == 0 && ref1 - && (TREE_CODE (type) != REFERENCE_TYPE + && (!TYPE_REF_P (type) || CP_TYPE_CONST_P (TREE_TYPE (type)))) continue; - if (code == COND_EXPR && TREE_CODE (type) == REFERENCE_TYPE) + if (code == COND_EXPR && TYPE_REF_P (type)) vec_safe_push (types[i], type); type = non_reference (type); @@ -3818,7 +3818,7 @@ build_user_type_conversion_1 (tree totype, tree expr, int flags, We represent this in the conversion sequence with an rvalue conversion, which means a constructor call. */ - if (TREE_CODE (totype) != REFERENCE_TYPE + if (!TYPE_REF_P (totype) && !(convflags & LOOKUP_NO_TEMP_BIND)) cand->second_conv = build_conv (ck_rvalue, totype, cand->second_conv); @@ -3842,7 +3842,7 @@ build_user_type_conversion_1 (tree totype, tree expr, int flags, find a direct binding, so don't even consider temporaries. If we don't find a direct binding, the caller will try again to look for a temporary binding. */ - if (TREE_CODE (totype) == REFERENCE_TYPE) + if (TYPE_REF_P (totype)) convflags |= LOOKUP_NO_TEMP_BIND; old_candidates = candidates; @@ -4514,7 +4514,7 @@ build_op_call_1 (tree obj, vec **args, tsubst_flags_t complain) if (TYPE_PTRFN_P (totype) || TYPE_REFFN_P (totype) - || (TREE_CODE (totype) == REFERENCE_TYPE + || (TYPE_REF_P (totype) && TYPE_PTRFN_P (TREE_TYPE (totype)))) for (ovl_iterator iter (TREE_VALUE (convs)); iter; ++iter) { @@ -5733,7 +5733,7 @@ build_new_op_1 (location_t loc, enum tree_code code, int flags, tree arg1, { parmtype = TREE_VALUE (parmlist); - if (TREE_CODE (parmtype) == REFERENCE_TYPE) + if (TYPE_REF_P (parmtype)) parmtype = TREE_TYPE (parmtype); if (TREE_CODE (TREE_TYPE (args[i])) == ENUMERAL_TYPE && (same_type_ignoring_top_level_qualifiers_p @@ -7246,7 +7246,7 @@ build_x_va_arg (source_location loc, tree expr, tree type) expr = mark_lvalue_use (expr); - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) { error ("cannot receive reference type %qT through %<...%>", type); return error_mark_node; @@ -7618,7 +7618,7 @@ conv_binds_ref_to_prvalue (conversion *c) if (c->kind == ck_rvalue) return true; - if (c->kind == ck_user && TREE_CODE (c->type) != REFERENCE_TYPE) + if (c->kind == ck_user && !TYPE_REF_P (c->type)) return true; if (c->kind == ck_identity && c->u.expr && TREE_CODE (c->u.expr) == TARGET_EXPR) @@ -7862,7 +7862,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) reference to the object’s type (possibly cv-qualified)...." */ gcc_assert (!(complain & tf_error)); tree ptype = convs[0]->type; - if (TREE_CODE (ptype) != REFERENCE_TYPE + if (!TYPE_REF_P (ptype) || !TYPE_REF_IS_RVALUE (ptype) || CONVERSION_RANK (convs[0]) > cr_exact) return error_mark_node; @@ -8097,7 +8097,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) /* For -Wformat undo the implicit passing by hidden reference done by convert_arg_to_ellipsis. */ if (TREE_CODE (argarray[j]) == ADDR_EXPR - && TREE_CODE (TREE_TYPE (argarray[j])) == REFERENCE_TYPE) + && TYPE_REF_P (TREE_TYPE (argarray[j]))) fargs[j] = TREE_OPERAND (argarray[j], 0); else fargs[j] = maybe_constant_value (argarray[j]); @@ -8153,12 +8153,12 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) targ = arg; /* Strip the reference binding for the constructor parameter. */ if (CONVERT_EXPR_P (targ) - && TREE_CODE (TREE_TYPE (targ)) == REFERENCE_TYPE) + && TYPE_REF_P (TREE_TYPE (targ))) targ = TREE_OPERAND (targ, 0); /* But don't strip any other reference bindings; binding a temporary to a reference prevents copy elision. */ while ((CONVERT_EXPR_P (targ) - && TREE_CODE (TREE_TYPE (targ)) != REFERENCE_TYPE) + && !TYPE_REF_P (TREE_TYPE (targ))) || TREE_CODE (targ) == NON_LVALUE_EXPR) targ = TREE_OPERAND (targ, 0); if (TREE_CODE (targ) == ADDR_EXPR) @@ -10672,7 +10672,7 @@ perform_implicit_conversion_flags (tree type, tree expr, void *p; location_t loc = EXPR_LOC_OR_LOC (expr, input_location); - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) expr = mark_lvalue_use (expr); else expr = mark_rvalue_use (expr); @@ -11094,7 +11094,7 @@ extend_ref_init_temps (tree decl, tree init, vec **cleanups) tree type = TREE_TYPE (init); if (processing_template_decl) return init; - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) init = extend_ref_init_temps_1 (decl, init, cleanups); else { @@ -11136,7 +11136,7 @@ bool type_has_extended_temps (tree type) { type = strip_array_types (type); - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) return true; if (CLASS_TYPE_P (type)) { diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 4616d8d..e51946d 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -3054,7 +3054,7 @@ one_inheriting_sig (tree t, tree ctor, tree *parms, int nparms) if (nparms == 0) return; if (nparms == 1 - && TREE_CODE (parms[0]) == REFERENCE_TYPE) + && TYPE_REF_P (parms[0])) { tree parm = TYPE_MAIN_VARIANT (TREE_TYPE (parms[0])); if (parm == t || parm == DECL_CONTEXT (ctor)) @@ -3463,7 +3463,7 @@ check_field_decls (tree t, tree *access_decls, "a member of a union", x); continue; } - if (TREE_CODE (type) == REFERENCE_TYPE + if (TYPE_REF_P (type) && TREE_CODE (x) == FIELD_DECL) { error ("non-static data member %q+D in a union may not " @@ -3517,7 +3517,7 @@ check_field_decls (tree t, tree *access_decls, CLASSTYPE_NON_STD_LAYOUT (t) = 1; /* If this is of reference type, check if it needs an init. */ - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) { CLASSTYPE_NON_LAYOUT_POD_P (t) = 1; CLASSTYPE_NON_STD_LAYOUT (t) = 1; @@ -3595,7 +3595,7 @@ check_field_decls (tree t, tree *access_decls, "and %", x); continue; } - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) { error ("member %q+D cannot be declared as a % " "reference", x); @@ -5594,7 +5594,7 @@ check_bases_and_members (tree t) continue; type = TREE_TYPE (field); - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) warning_at (DECL_SOURCE_LOCATION (field), OPT_Wuninitialized, "non-static reference %q#D " "in class without a constructor", field); @@ -6454,8 +6454,8 @@ find_flexarrays (tree t, flexmems_t *fmem, bool base_p, members if it hasn't been yet. */ tree eltype = fldtype; while (TREE_CODE (eltype) == ARRAY_TYPE - || TREE_CODE (eltype) == POINTER_TYPE - || TREE_CODE (eltype) == REFERENCE_TYPE) + || TYPE_PTR_P (eltype) + || TYPE_REF_P (eltype)) eltype = TREE_TYPE (eltype); if (RECORD_OR_UNION_TYPE_P (eltype)) @@ -7069,7 +7069,7 @@ finish_struct (tree t, tree attributes) if (processing_template_decl) { tree f = next_initializable_field (TYPE_FIELDS (t)); - if (f && TREE_CODE (TREE_TYPE (f)) == POINTER_TYPE) + if (f && TYPE_PTR_P (TREE_TYPE (f))) { f = next_initializable_field (DECL_CHAIN (f)); if (f && same_type_p (TREE_TYPE (f), size_type_node)) @@ -7214,7 +7214,7 @@ fixed_type_or_null (tree instance, int *nonnull, int *cdtorp) return TREE_TYPE (TREE_TYPE (instance)); } } - else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE) + else if (TYPE_REF_P (TREE_TYPE (instance))) { /* We only need one hash table because it is always left empty. */ if (!fixed_type_or_null_ref_ht) diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index d9a4cab..9ee37de 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -60,7 +60,7 @@ literal_type_p (tree t) { if (SCALAR_TYPE_P (t) || VECTOR_TYPE_P (t) - || TREE_CODE (t) == REFERENCE_TYPE + || TYPE_REF_P (t) || (VOID_TYPE_P (t) && cxx_dialect >= cxx14)) return true; if (CLASS_TYPE_P (t)) @@ -1328,7 +1328,7 @@ cxx_bind_parameters_in_call (const constexpr_ctx *ctx, tree t, arg = unshare_constructor (arg); /* Make sure the binding has the same type as the parm. But only for constant args. */ - if (TREE_CODE (type) != REFERENCE_TYPE) + if (!TYPE_REF_P (type)) arg = adjust_temp_type (type, arg); if (!TREE_CONSTANT (arg)) *non_constant_args = true; @@ -3394,7 +3394,7 @@ non_const_var_error (tree r) else gcc_unreachable (); } - else if (TREE_CODE (type) == REFERENCE_TYPE) + else if (TYPE_REF_P (type)) inform (DECL_SOURCE_LOCATION (r), "%qD was not initialized with a constant " "expression", r); @@ -4104,7 +4104,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, } if (TREE_CODE (t) == INTEGER_CST - && TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE + && TYPE_PTR_P (TREE_TYPE (t)) && !integer_zerop (t)) { if (!ctx->quiet) @@ -4185,13 +4185,13 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, return t; case PARM_DECL: - if (lval && TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE) + if (lval && !TYPE_REF_P (TREE_TYPE (t))) /* glvalue use. */; else if (tree *p = ctx->values->get (r)) r = *p; else if (lval) /* Defer in case this is only used for its type. */; - else if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE) + else if (TYPE_REF_P (TREE_TYPE (t))) /* Defer, there's no lvalue->rvalue conversion. */; else if (COMPLETE_TYPE_P (TREE_TYPE (t)) && is_really_empty_class (TREE_TYPE (t))) @@ -4619,7 +4619,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, { if (integer_zerop (op)) { - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) { if (!ctx->quiet) error_at (EXPR_LOC_OR_LOC (t, input_location), @@ -4627,7 +4627,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, *non_constant_p = true; return t; } - else if (TREE_CODE (TREE_TYPE (op)) == POINTER_TYPE) + else if (TYPE_PTR_P (TREE_TYPE (op))) { tree from = TREE_TYPE (op); @@ -5807,7 +5807,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, } return (RECUR (TREE_OPERAND (t, 0), - TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE)); + !TYPE_REF_P (TREE_TYPE (t)))); case BIND_EXPR: return RECUR (BIND_EXPR_BODY (t), want_rval); diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 317ba45..eda5f05 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -874,7 +874,7 @@ omp_var_to_track (tree decl) tree type = TREE_TYPE (decl); if (is_invisiref_parm (decl)) type = TREE_TYPE (type); - else if (TREE_CODE (type) == REFERENCE_TYPE) + else if (TYPE_REF_P (type)) type = TREE_TYPE (type); while (TREE_CODE (type) == ARRAY_TYPE) type = TREE_TYPE (type); @@ -928,7 +928,7 @@ omp_cxx_notice_variable (struct cp_genericize_omp_taskreg *omp_ctx, tree decl) tree type = TREE_TYPE (decl); if (is_invisiref_parm (decl)) type = TREE_TYPE (type); - else if (TREE_CODE (type) == REFERENCE_TYPE) + else if (TYPE_REF_P (type)) type = TREE_TYPE (type); while (TREE_CODE (type) == ARRAY_TYPE) type = TREE_TYPE (type); @@ -1091,7 +1091,7 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data) } if (TREE_CODE (stmt) == INTEGER_CST - && TREE_CODE (TREE_TYPE (stmt)) == REFERENCE_TYPE + && TYPE_REF_P (TREE_TYPE (stmt)) && (flag_sanitize & (SANITIZE_NULL | SANITIZE_ALIGNMENT)) && !wtd->no_sanitize_p) { @@ -1486,7 +1486,7 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data) case NOP_EXPR: if (!wtd->no_sanitize_p && sanitize_flags_p (SANITIZE_NULL | SANITIZE_ALIGNMENT) - && TREE_CODE (TREE_TYPE (stmt)) == REFERENCE_TYPE) + && TYPE_REF_P (TREE_TYPE (stmt))) ubsan_maybe_instrument_reference (stmt_p); break; @@ -1513,8 +1513,7 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data) else if (fn == NULL_TREE && CALL_EXPR_IFN (stmt) == IFN_UBSAN_NULL && TREE_CODE (CALL_EXPR_ARG (stmt, 0)) == INTEGER_CST - && (TREE_CODE (TREE_TYPE (CALL_EXPR_ARG (stmt, 0))) - == REFERENCE_TYPE)) + && TYPE_REF_P (TREE_TYPE (CALL_EXPR_ARG (stmt, 0)))) *walk_subtrees = 0; } /* Fall through. */ @@ -1907,7 +1906,7 @@ cxx_omp_clause_dtor (tree clause, tree decl) bool cxx_omp_privatize_by_reference (const_tree decl) { - return (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE + return (TYPE_REF_P (TREE_TYPE (decl)) || is_invisiref_parm (decl)); } @@ -1916,7 +1915,7 @@ bool cxx_omp_const_qual_no_mutable (tree decl) { tree type = TREE_TYPE (decl); - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) { if (!is_invisiref_parm (decl)) return false; @@ -2017,7 +2016,7 @@ cxx_omp_finish_clause (tree c, gimple_seq *) inner_type = TREE_TYPE (decl); if (decl == error_mark_node) make_shared = true; - else if (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE) + else if (TYPE_REF_P (TREE_TYPE (decl))) inner_type = TREE_TYPE (inner_type); /* We're interested in the base element, not arrays. */ @@ -2065,7 +2064,7 @@ cp_fold_maybe_rvalue (tree x, bool rval) { x = cp_fold (x); if (rval && DECL_P (x) - && TREE_CODE (TREE_TYPE (x)) != REFERENCE_TYPE) + && !TYPE_REF_P (TREE_TYPE (x))) { tree v = decl_constant_value (x); if (v != x && v != error_mark_node) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 353bc6a..4b4f882 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -3621,8 +3621,7 @@ struct GTY(()) lang_decl { #define REFERENCE_REF_P(NODE) \ (INDIRECT_REF_P (NODE) \ && TREE_TYPE (TREE_OPERAND (NODE, 0)) \ - && (TREE_CODE (TREE_TYPE (TREE_OPERAND ((NODE), 0))) \ - == REFERENCE_TYPE)) + && TYPE_REF_P (TREE_TYPE (TREE_OPERAND ((NODE), 0)))) /* True if NODE is a REFERENCE_TYPE which is OK to instantiate to be a reference to VLA type, because it's used for VLA capture. */ @@ -4227,10 +4226,15 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter) /* Returns true if NODE is a pointer-to-data-member. */ #define TYPE_PTRDATAMEM_P(NODE) \ (TREE_CODE (NODE) == OFFSET_TYPE) + /* Returns true if NODE is a pointer. */ #define TYPE_PTR_P(NODE) \ (TREE_CODE (NODE) == POINTER_TYPE) +/* Returns true if NODE is a reference. */ +#define TYPE_REF_P(NODE) \ + (TREE_CODE (NODE) == REFERENCE_TYPE) + /* Returns true if NODE is an object type: [basic.types] @@ -4240,7 +4244,7 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter) Keep these checks in ascending order, for speed. */ #define TYPE_OBJ_P(NODE) \ - (TREE_CODE (NODE) != REFERENCE_TYPE \ + (!TYPE_REF_P (NODE) \ && !VOID_TYPE_P (NODE) \ && TREE_CODE (NODE) != FUNCTION_TYPE \ && TREE_CODE (NODE) != METHOD_TYPE) @@ -4253,7 +4257,7 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter) /* Returns true if NODE is a reference to an object. Keep these checks in ascending tree code order. */ #define TYPE_REF_OBJ_P(NODE) \ - (TREE_CODE (NODE) == REFERENCE_TYPE && TYPE_OBJ_P (TREE_TYPE (NODE))) + (TYPE_REF_P (NODE) && TYPE_OBJ_P (TREE_TYPE (NODE))) /* Returns true if NODE is a pointer to an object, or a pointer to void. Keep these checks in ascending tree code order. */ @@ -4269,7 +4273,7 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter) /* Returns true if NODE is a reference to function type. */ #define TYPE_REFFN_P(NODE) \ - (TREE_CODE (NODE) == REFERENCE_TYPE \ + (TYPE_REF_P (NODE) \ && TREE_CODE (TREE_TYPE (NODE)) == FUNCTION_TYPE) /* Returns true if NODE is a pointer to member function type. */ diff --git a/gcc/cp/cp-ubsan.c b/gcc/cp/cp-ubsan.c index 97ac3d6..507433a 100644 --- a/gcc/cp/cp-ubsan.c +++ b/gcc/cp/cp-ubsan.c @@ -265,7 +265,7 @@ cp_ubsan_maybe_instrument_downcast (location_t loc, tree type, return NULL_TREE; return cp_ubsan_maybe_instrument_vptr (loc, op, TREE_TYPE (type), true, - TREE_CODE (type) == POINTER_TYPE + TYPE_PTR_P (type) ? UBSAN_DOWNCAST_POINTER : UBSAN_DOWNCAST_REFERENCE); } diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index 9494f29..30b44b7 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -322,7 +322,7 @@ build_up_reference (tree type, tree arg, int flags, tree decl, tree argtype = TREE_TYPE (arg); tree target_type = TREE_TYPE (type); - gcc_assert (TREE_CODE (type) == REFERENCE_TYPE); + gcc_assert (TYPE_REF_P (type)); if ((flags & DIRECT_BIND) && ! lvalue_p (arg)) { @@ -429,8 +429,8 @@ convert_to_reference (tree reftype, tree expr, int convtype, intype = TREE_TYPE (expr); - gcc_assert (TREE_CODE (intype) != REFERENCE_TYPE); - gcc_assert (TREE_CODE (reftype) == REFERENCE_TYPE); + gcc_assert (!TYPE_REF_P (intype)); + gcc_assert (TYPE_REF_P (reftype)); intype = TYPE_MAIN_VARIANT (intype); @@ -533,7 +533,7 @@ tree convert_from_reference (tree val) { if (TREE_TYPE (val) - && TREE_CODE (TREE_TYPE (val)) == REFERENCE_TYPE) + && TYPE_REF_P (TREE_TYPE (val))) { tree t = TREE_TYPE (TREE_TYPE (val)); tree ref = build1 (INDIRECT_REF, t, val); @@ -1163,8 +1163,7 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) case INDIRECT_REF: { tree type = TREE_TYPE (expr); - int is_reference = TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) - == REFERENCE_TYPE; + int is_reference = TYPE_REF_P (TREE_TYPE (TREE_OPERAND (expr, 0))); int is_volatile = TYPE_VOLATILE (type); int is_complete = COMPLETE_TYPE_P (complete_type (type)); @@ -2011,8 +2010,8 @@ noexcept_conv_p (tree to, tree from) t = TYPE_PTRMEMFUNC_FN_TYPE (t); f = TYPE_PTRMEMFUNC_FN_TYPE (f); } - if (TREE_CODE (t) == POINTER_TYPE - && TREE_CODE (f) == POINTER_TYPE) + if (TYPE_PTR_P (t) + && TYPE_PTR_P (f)) { t = TREE_TYPE (t); f = TREE_TYPE (f); @@ -2042,8 +2041,8 @@ fnptr_conv_p (tree to, tree from) t = TYPE_PTRMEMFUNC_FN_TYPE (t); f = TYPE_PTRMEMFUNC_FN_TYPE (f); } - if (TREE_CODE (t) == POINTER_TYPE - && TREE_CODE (f) == POINTER_TYPE) + if (TYPE_PTR_P (t) + && TYPE_PTR_P (f)) { t = TREE_TYPE (t); f = TREE_TYPE (f); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 20ca28f..59d6bad 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -674,7 +674,7 @@ poplevel (int keep, int reverse, int functionbody) } else if (DECL_CONTEXT (decl) == current_function_decl // For -Wunused-but-set-variable leave references alone. - && TREE_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE + && !TYPE_REF_P (TREE_TYPE (decl)) && errorcount == unused_but_set_errorcount) { if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl)) @@ -5562,7 +5562,7 @@ check_for_uninitialized_const_var (tree decl, bool constexpr_context_p, external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6 */ if (VAR_P (decl) - && TREE_CODE (type) != REFERENCE_TYPE + && !TYPE_REF_P (type) && (constexpr_context_p || CP_TYPE_CONST_P (type) || var_in_constexpr_fn (decl)) && !DECL_NONTRIVIALLY_INITIALIZED_P (decl)) @@ -6265,7 +6265,7 @@ check_initializer (tree decl, tree init, int flags, vec **cleanups) if (TREE_CODE (decl) == CONST_DECL) { - gcc_assert (TREE_CODE (type) != REFERENCE_TYPE); + gcc_assert (!TYPE_REF_P (type)); DECL_INITIAL (decl) = init; @@ -6275,9 +6275,9 @@ check_initializer (tree decl, tree init, int flags, vec **cleanups) else if (!init && DECL_REALLY_EXTERN (decl)) ; else if (init || type_build_ctor_call (type) - || TREE_CODE (type) == REFERENCE_TYPE) + || TYPE_REF_P (type)) { - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) { init = grok_reference_init (decl, type, init, flags); flags |= LOOKUP_ALREADY_DIGESTED; @@ -6616,7 +6616,7 @@ initialize_local_var (tree decl, tree init) gcc_assert (TREE_OPERAND (init, 0) == decl); DECL_INITIAL (decl) = rinit; - if (warn_init_self && TREE_CODE (type) == REFERENCE_TYPE) + if (warn_init_self && TYPE_REF_P (type)) { STRIP_NOPS (rinit); if (rinit == decl) @@ -6889,7 +6889,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, /* If DECL is a reference, then we want to know whether init is a reference constant; init_const_expr_p as passed tells us whether it's an rvalue constant. */ - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) init_const_expr_p = potential_constant_expression (init); if (init_const_expr_p) { @@ -6898,7 +6898,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1; if (decl_maybe_constant_var_p (decl) /* FIXME setting TREE_CONSTANT on refs breaks the back end. */ - && TREE_CODE (type) != REFERENCE_TYPE) + && !TYPE_REF_P (type)) TREE_CONSTANT (decl) = 1; } } @@ -6935,7 +6935,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, } else if (init && init_const_expr_p - && TREE_CODE (type) != REFERENCE_TYPE + && !TYPE_REF_P (type) && decl_maybe_constant_var_p (decl) && !(dep_init = value_dependent_init_p (init))) { @@ -7004,7 +7004,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, /* A reference will be modified here, as it is initialized. */ if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl) - && TREE_CODE (type) == REFERENCE_TYPE) + && TYPE_REF_P (type)) { was_readonly = 1; TREE_READONLY (decl) = 0; @@ -7345,7 +7345,7 @@ get_tuple_decomp_init (tree decl, unsigned i) /* [The id-expression] e is an lvalue if the type of the entity e is an lvalue reference and an xvalue otherwise. */ - if (TREE_CODE (etype) != REFERENCE_TYPE + if (!TYPE_REF_P (etype) || TYPE_REF_IS_RVALUE (etype)) e = move (e); @@ -7488,7 +7488,7 @@ cp_finish_decomp (tree decl, tree first, unsigned int count) tree type = TREE_TYPE (decl); tree dexp = decl; - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) { dexp = convert_from_reference (dexp); type = complete_type (TREE_TYPE (type)); @@ -11298,7 +11298,7 @@ grokdeclarator (const cp_declarator *declarator, /* Filter out pointers-to-references and references-to-references. We can get these if a TYPE_DECL is used. */ - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) { if (declarator->kind != cdk_reference) { @@ -11404,7 +11404,7 @@ grokdeclarator (const cp_declarator *declarator, */ if (VOID_TYPE_P (type)) /* We already gave an error. */; - else if (TREE_CODE (type) == REFERENCE_TYPE) + else if (TYPE_REF_P (type)) { if (declarator->u.reference.rvalue_ref) /* Leave type alone. */; @@ -11485,7 +11485,7 @@ grokdeclarator (const cp_declarator *declarator, /* DR1688 says that a `constexpr' specifier in combination with `volatile' is valid. */ - if (TREE_CODE (type) != REFERENCE_TYPE) + if (!TYPE_REF_P (type)) { type_quals |= TYPE_QUAL_CONST; type = cp_build_qualified_type (type, type_quals); @@ -11668,7 +11668,7 @@ grokdeclarator (const cp_declarator *declarator, error ("const %qs cannot be declared %", name); storage_class = sc_none; } - else if (TREE_CODE (type) == REFERENCE_TYPE) + else if (TYPE_REF_P (type)) { permerror (input_location, "reference %qs cannot be declared " "%", name); @@ -12894,7 +12894,7 @@ copy_fn_p (const_tree d) /* Pass by value copy assignment operator. */ result = -1; } - else if (TREE_CODE (arg_type) == REFERENCE_TYPE + else if (TYPE_REF_P (arg_type) && !TYPE_REF_IS_RVALUE (arg_type) && TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)) == DECL_CONTEXT (d)) { @@ -12962,7 +12962,7 @@ move_signature_fn_p (const_tree d) if (arg_type == error_mark_node) return 0; - if (TREE_CODE (arg_type) == REFERENCE_TYPE + if (TYPE_REF_P (arg_type) && TYPE_REF_IS_RVALUE (arg_type) && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)), DECL_CONTEXT (d))) @@ -13334,7 +13334,7 @@ grok_op_properties (tree decl, bool complain) && warn_conversion) { tree t = TREE_TYPE (name); - int ref = (TREE_CODE (t) == REFERENCE_TYPE); + int ref = TYPE_REF_P (t); if (ref) t = TYPE_MAIN_VARIANT (TREE_TYPE (t)); @@ -13388,14 +13388,14 @@ grok_op_properties (tree decl, bool complain) { tree arg = TREE_VALUE (argtypes); tree ret = TREE_TYPE (TREE_TYPE (decl)); - if (methodp || TREE_CODE (arg) == REFERENCE_TYPE) + if (methodp || TYPE_REF_P (arg)) arg = TREE_TYPE (arg); arg = TYPE_MAIN_VARIANT (arg); if (operator_code == PREINCREMENT_EXPR || operator_code == PREDECREMENT_EXPR) { - if (TREE_CODE (ret) != REFERENCE_TYPE + if (!TYPE_REF_P (ret) || !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), arg)) warning (OPT_Weffc__, "prefix %qD should return %qT", decl, build_reference_type (arg)); @@ -13414,7 +13414,7 @@ grok_op_properties (tree decl, bool complain) || operator_code == TRUNC_DIV_EXPR || operator_code == MULT_EXPR || operator_code == TRUNC_MOD_EXPR) - && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == REFERENCE_TYPE) + && TYPE_REF_P (TREE_TYPE (TREE_TYPE (decl)))) warning (OPT_Weffc__, "%qD should return by value", decl); return true; @@ -15822,7 +15822,7 @@ finish_function (bool inline_p) && !TREE_NO_WARNING (decl) && !DECL_IN_SYSTEM_HEADER (decl) && TREE_TYPE (decl) != error_mark_node - && TREE_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE + && !TYPE_REF_P (TREE_TYPE (decl)) && (!CLASS_TYPE_P (TREE_TYPE (decl)) || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))) warning_at (DECL_SOURCE_LOCATION (decl), diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 6f3ad4c..0a6cf91 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -462,7 +462,7 @@ grok_array_decl (location_t loc, tree array_expr, tree index_exp, if (array_expr == error_mark_node || index_exp == error_mark_node) error ("ambiguous conversion for array subscript"); - if (TREE_CODE (TREE_TYPE (array_expr)) == POINTER_TYPE) + if (TYPE_PTR_P (TREE_TYPE (array_expr))) array_expr = mark_rvalue_use (array_expr); else array_expr = mark_lvalue_use_nonread (array_expr); @@ -1345,7 +1345,7 @@ cp_reconstruct_complex_type (tree type, tree bottom) outer = build_pointer_type_for_mode (inner, TYPE_MODE (type), TYPE_REF_CAN_ALIAS_ALL (type)); } - else if (TREE_CODE (type) == REFERENCE_TYPE) + else if (TYPE_REF_P (type)) { inner = cp_reconstruct_complex_type (TREE_TYPE (type), bottom); outer = build_reference_type_for_mode (inner, TYPE_MODE (type), @@ -4275,7 +4275,7 @@ decl_maybe_constant_var_p (tree decl) if (DECL_HAS_VALUE_EXPR_P (decl)) /* A proxy isn't constant. */ return false; - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) /* References can be constant. */; else if (CP_TYPE_CONST_NON_VOLATILE_P (type) && INTEGRAL_OR_ENUMERATION_TYPE_P (type)) diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 95b8b84..374ab0d 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -784,13 +784,13 @@ dump_type_prefix (cxx_pretty_printer *pp, tree t, int flags) } if (TYPE_PTR_P (t)) pp_star (pp); - else if (TREE_CODE (t) == REFERENCE_TYPE) - { - if (TYPE_REF_IS_RVALUE (t)) - pp_ampersand_ampersand (pp); - else - pp_ampersand (pp); - } + else if (TYPE_REF_P (t)) + { + if (TYPE_REF_IS_RVALUE (t)) + pp_ampersand_ampersand (pp); + else + pp_ampersand (pp); + } pp->padding = pp_before; pp_cxx_cv_qualifier_seq (pp, t); } @@ -2271,7 +2271,7 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags) if (!is_this_parameter (ob)) { dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS); - if (TREE_CODE (TREE_TYPE (ob)) == REFERENCE_TYPE) + if (TYPE_REF_P (TREE_TYPE (ob))) pp_cxx_dot (pp); else pp_cxx_arrow (pp); @@ -2305,7 +2305,7 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags) shouldn't print the `&' doing so indicates to the user that the expression has pointer type. */ || (TREE_TYPE (t) - && TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)) + && TYPE_REF_P (TREE_TYPE (t)))) dump_expr (pp, TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS); else if (TREE_CODE (TREE_OPERAND (t, 0)) == LABEL_DECL) dump_unary_op (pp, "&&", t, flags); @@ -2417,7 +2417,7 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags) && same_type_p (TREE_TYPE (optype), TREE_TYPE (ttype))) { - if (TREE_CODE (ttype) == REFERENCE_TYPE) + if (TYPE_REF_P (ttype)) { STRIP_NOPS (op); if (TREE_CODE (op) == ADDR_EXPR) diff --git a/gcc/cp/except.c b/gcc/cp/except.c index 6dab6d6..4599619 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -306,7 +306,7 @@ initialize_handler_parm (tree decl, tree exp) /* Since pointers are passed by value, initialize a reference to pointer catch parm with the address of the temporary. */ - if (TREE_CODE (init_type) == REFERENCE_TYPE + if (TYPE_REF_P (init_type) && TYPE_PTR_P (TREE_TYPE (init_type))) exp = cp_build_addr_expr (exp, tf_warning_or_error); @@ -802,7 +802,7 @@ complete_ptr_ref_or_void_ptr_p (tree type, tree from) /* Or a pointer or ref to one, or cv void *. */ is_ptr = TYPE_PTR_P (type); - if (is_ptr || TREE_CODE (type) == REFERENCE_TYPE) + if (is_ptr || TYPE_REF_P (type)) { tree core = TREE_TYPE (type); @@ -846,7 +846,7 @@ is_admissible_throw_operand_or_catch_parameter (tree t, bool is_throw) else if (abstract_virtuals_error (is_throw ? ACU_THROW : ACU_CATCH, type)) return false; else if (!is_throw - && TREE_CODE (type) == REFERENCE_TYPE + && TYPE_REF_P (type) && TYPE_REF_IS_RVALUE (type)) { error ("cannot declare catch parameter to be of rvalue " diff --git a/gcc/cp/expr.c b/gcc/cp/expr.c index 15894fc..0d0a10ec 100644 --- a/gcc/cp/expr.c +++ b/gcc/cp/expr.c @@ -141,7 +141,7 @@ mark_use (tree expr, bool rvalue_p, bool read_p, } expr = process_outer_var_ref (expr, tf_warning_or_error, true); if (!(TREE_TYPE (oexpr) - && TREE_CODE (TREE_TYPE (oexpr)) == REFERENCE_TYPE)) + && TYPE_REF_P (TREE_TYPE (oexpr)))) expr = convert_from_reference (expr); } break; @@ -166,7 +166,7 @@ mark_use (tree expr, bool rvalue_p, bool read_p, { /* Look through capture by reference. */ tree cap = DECL_CAPTURED_VARIABLE (ref); - if (TREE_CODE (TREE_TYPE (cap)) != REFERENCE_TYPE + if (!TYPE_REF_P (TREE_TYPE (cap)) && decl_constant_var_p (cap)) { tree val = RECUR (cap); diff --git a/gcc/cp/init.c b/gcc/cp/init.c index b934a00..d9fb0ea 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -287,7 +287,7 @@ build_zero_init_1 (tree type, tree nelts, bool static_storage_p, init = build_zero_cst (type); else { - gcc_assert (TREE_CODE (type) == REFERENCE_TYPE); + gcc_assert (TYPE_REF_P (type)); init = build_zero_cst (type); } @@ -502,7 +502,7 @@ build_value_init_noctor (tree type, tsubst_flags_t complain) error ("value-initialization of function type %qT", type); return error_mark_node; } - else if (TREE_CODE (type) == REFERENCE_TYPE) + else if (TYPE_REF_P (type)) { if (complain & tf_error) error ("value-initialization of reference type %qT", type); @@ -751,7 +751,7 @@ perform_member_init (tree member, tree init) } } else if (init - && (TREE_CODE (type) == REFERENCE_TYPE + && (TYPE_REF_P (type) /* Pre-digested NSDMI. */ || (((TREE_CODE (init) == CONSTRUCTOR && TREE_TYPE (init) == type) @@ -856,7 +856,7 @@ perform_member_init (tree member, tree init) { tree core_type; /* member traversal: note it leaves init NULL */ - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) { if (permerror (DECL_SOURCE_LOCATION (current_function_decl), "uninitialized reference member in %q#T", type)) @@ -2368,7 +2368,7 @@ diagnose_uninitialized_cst_or_ref_member_1 (tree type, tree origin, if (type_has_user_provided_constructor (field_type)) continue; - if (TREE_CODE (field_type) == REFERENCE_TYPE) + if (TYPE_REF_P (field_type)) { ++ error_count; if (complain) @@ -3659,7 +3659,7 @@ build_new (vec **placement, tree type, tree nelts, /* ``A reference cannot be created by the new operator. A reference is not an object (8.2.2, 8.4.3), so a pointer to it could not be returned by new.'' ARM 5.3.3 */ - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) { if (complain & tf_error) error ("new cannot be applied to a reference type"); @@ -4586,7 +4586,7 @@ build_delete (tree otype, tree addr, special_function_kind auto_delete, if (type == error_mark_node) return error_mark_node; - if (TREE_CODE (type) == POINTER_TYPE) + if (TYPE_PTR_P (type)) type = TYPE_MAIN_VARIANT (TREE_TYPE (type)); if (TREE_CODE (type) == ARRAY_TYPE) diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index e3f22fc..cf7c380 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -90,7 +90,7 @@ build_lambda_object (tree lambda_expr) val = build_array_copy (val); else if (DECL_NORMAL_CAPTURE_P (field) && !DECL_VLA_CAPTURE_P (field) - && TREE_CODE (TREE_TYPE (field)) != REFERENCE_TYPE) + && !TYPE_REF_P (TREE_TYPE (field))) { /* "the entities that are captured by copy are used to direct-initialize each corresponding non-static data diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index 2f65709..58b3311 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -3071,7 +3071,7 @@ write_expression (tree expr) } else if (INDIRECT_REF_P (expr) && TREE_TYPE (TREE_OPERAND (expr, 0)) - && TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == REFERENCE_TYPE) + && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (expr, 0)))) { write_expression (TREE_OPERAND (expr, 0)); } @@ -3209,7 +3209,7 @@ write_expression (tree expr) don't actually want to output a mangling code for the `&'. */ if (TREE_CODE (expr) == ADDR_EXPR && TREE_TYPE (expr) - && TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE) + && TYPE_REF_P (TREE_TYPE (expr))) { expr = TREE_OPERAND (expr, 0); if (DECL_P (expr)) @@ -3473,7 +3473,7 @@ write_template_arg (tree node) if (REFERENCE_REF_P (node)) node = TREE_OPERAND (node, 0); if (TREE_CODE (node) == NOP_EXPR - && TREE_CODE (TREE_TYPE (node)) == REFERENCE_TYPE) + && TYPE_REF_P (TREE_TYPE (node))) { /* Template parameters can be of reference type. To maintain internal consistency, such arguments use a conversion from diff --git a/gcc/cp/method.c b/gcc/cp/method.c index eaa930f..e9add9a 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -468,7 +468,7 @@ forward_parm (tree parm) tree type = TREE_TYPE (parm); if (DECL_PACK_P (parm)) type = PACK_EXPANSION_PATTERN (type); - if (TREE_CODE (type) != REFERENCE_TYPE) + if (!TYPE_REF_P (type)) type = cp_build_reference_type (type, /*rval=*/true); warning_sentinel w (warn_useless_cast); exp = build_static_cast (type, exp, tf_warning_or_error); @@ -731,7 +731,7 @@ do_build_copy_constructor (tree fndecl) the field is "T", then the type will usually be "const T". (There are no cv-qualified variants of reference types.) */ - if (TREE_CODE (expr_type) != REFERENCE_TYPE) + if (!TYPE_REF_P (expr_type)) { int quals = cvquals; @@ -742,7 +742,7 @@ do_build_copy_constructor (tree fndecl) } init = build3 (COMPONENT_REF, expr_type, parm, field, NULL_TREE); - if (move_p && TREE_CODE (expr_type) != REFERENCE_TYPE + if (move_p && !TYPE_REF_P (expr_type) /* 'move' breaks bit-fields, and has no effect for scalars. */ && !scalarish_type_p (expr_type)) init = move (init); @@ -829,7 +829,7 @@ do_build_copy_assign (tree fndecl) "assignment operator", field); continue; } - else if (TREE_CODE (expr_type) == REFERENCE_TYPE) + else if (TYPE_REF_P (expr_type)) { error ("non-static reference member %q#D, can%'t use " "default assignment operator", field); @@ -858,7 +858,7 @@ do_build_copy_assign (tree fndecl) expr_type = cp_build_qualified_type (expr_type, quals); init = build3 (COMPONENT_REF, expr_type, init, field, NULL_TREE); - if (move_p && TREE_CODE (expr_type) != REFERENCE_TYPE + if (move_p && !TYPE_REF_P (expr_type) /* 'move' breaks bit-fields, and has no effect for scalars. */ && !scalarish_type_p (expr_type)) init = move (init); @@ -970,7 +970,7 @@ build_stub_type (tree type, int quals, bool rvalue) static tree build_stub_object (tree reftype) { - if (TREE_CODE (reftype) != REFERENCE_TYPE) + if (!TYPE_REF_P (reftype)) reftype = cp_build_reference_type (reftype, /*rval*/true); tree stub = build1 (CONVERT_EXPR, reftype, integer_one_node); return convert_from_reference (stub); @@ -1149,7 +1149,7 @@ constructible_expr (tree to, tree from) tree ctype = to; vec *args = NULL; cp_unevaluated cp_uneval_guard; - if (TREE_CODE (to) != REFERENCE_TYPE) + if (!TYPE_REF_P (to)) to = cp_build_reference_type (to, /*rval*/false); tree ob = build_stub_object (to); for (; from; from = TREE_CHAIN (from)) @@ -1324,7 +1324,7 @@ walk_field_subobs (tree fields, tree fnname, special_function_kind sfk, error ("non-static const member %q#D, can%'t use default " "assignment operator", field); } - else if (TREE_CODE (mem_type) == REFERENCE_TYPE) + else if (TYPE_REF_P (mem_type)) { if (diag) error ("non-static reference member %q#D, can%'t use " @@ -1372,7 +1372,7 @@ walk_field_subobs (tree fields, tree fnname, special_function_kind sfk, } bad = true; } - else if (TREE_CODE (mem_type) == REFERENCE_TYPE) + else if (TYPE_REF_P (mem_type)) { if (diag) { @@ -1403,7 +1403,7 @@ walk_field_subobs (tree fields, tree fnname, special_function_kind sfk, else if (sfk == sfk_copy_constructor) { /* 12.8p11b5 */ - if (TREE_CODE (mem_type) == REFERENCE_TYPE + if (TYPE_REF_P (mem_type) && TYPE_REF_IS_RVALUE (mem_type)) { if (diag) diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 82b8ef8..a06516b 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -34954,7 +34954,7 @@ cp_parser_omp_for_loop_init (cp_parser *parser, init = cp_parser_assignment_expression (parser); non_class: - if (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE) + if (TYPE_REF_P (TREE_TYPE (decl))) init = error_mark_node; else cp_finish_decl (decl, NULL_TREE, @@ -37417,7 +37417,7 @@ static bool cp_parser_omp_declare_reduction_exprs (tree fndecl, cp_parser *parser) { tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl))); - gcc_assert (TREE_CODE (type) == REFERENCE_TYPE); + gcc_assert (TYPE_REF_P (type)); type = TREE_TYPE (type); tree omp_out = build_lang_decl (VAR_DECL, get_identifier ("omp_out"), type); DECL_ARTIFICIAL (omp_out) = 1; @@ -37656,7 +37656,7 @@ cp_parser_omp_declare_reduction (cp_parser *parser, cp_token *pragma_tok, || TREE_CODE (type) == ARRAY_TYPE) error_at (loc, "function or array type %qT in " "%<#pragma omp declare reduction%>", type); - else if (TREE_CODE (type) == REFERENCE_TYPE) + else if (TYPE_REF_P (type)) error_at (loc, "reference type %qT in " "%<#pragma omp declare reduction%>", type); else if (TYPE_QUALS_NO_ADDR_SPACE (type)) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index cd9011b..ddfda2e 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -6277,7 +6277,7 @@ convert_nontype_argument_function (tree type, tree expr, } accept: - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) { if (REFERENCE_REF_P (fn)) fn = TREE_OPERAND (fn, 0); @@ -6686,7 +6686,7 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) } } - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) expr = mark_lvalue_use (expr); else expr = mark_rvalue_use (expr); @@ -6711,7 +6711,7 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) could actually change the type to something more cv-qualified, and this is not folded by convert_from_reference. */ tree addr = TREE_OPERAND (probe, 0); - if (TREE_CODE (probe_type) == REFERENCE_TYPE + if (TYPE_REF_P (probe_type) && TREE_CODE (addr) == ADDR_EXPR && TYPE_PTR_P (TREE_TYPE (addr)) && (same_type_ignoring_top_level_qualifiers_p @@ -8019,7 +8019,7 @@ convert_template_argument (tree parm, const_tree inner = TREE_OPERAND (val, 0); const_tree innertype = TREE_TYPE (inner); if (innertype - && TREE_CODE (innertype) == REFERENCE_TYPE + && TYPE_REF_P (innertype) && TREE_CODE (TREE_TYPE (innertype)) == FUNCTION_TYPE && TREE_OPERAND_LENGTH (inner) > 0 && reject_gcc_builtin (TREE_OPERAND (inner, 0))) @@ -12204,7 +12204,7 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain, /* Also optimize expression pack expansions if we can tell that the elements won't have reference type. */ tree type = TREE_TYPE (pattern); - if (type && TREE_CODE (type) != REFERENCE_TYPE + if (type && !TYPE_REF_P (type) && !PACK_EXPANSION_P (type) && !WILDCARD_TYPE_P (type)) return args; @@ -12941,7 +12941,7 @@ tsubst_function_decl (tree t, tree args, tsubst_flags_t complain, tree argtype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (t)))); argtype = tsubst (argtype, args, complain, in_decl); - if (TREE_CODE (argtype) == REFERENCE_TYPE) + if (TYPE_REF_P (argtype)) error_at (DECL_SOURCE_LOCATION (t), "reference type %qT in " "%<#pragma omp declare reduction%>", argtype); @@ -13723,7 +13723,7 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) /*constant_expression_p=*/false); if (REFERENCE_REF_P (ve)) { - gcc_assert (TREE_CODE (type) == REFERENCE_TYPE); + gcc_assert (TYPE_REF_P (type)); ve = TREE_OPERAND (ve, 0); } SET_DECL_VALUE_EXPR (r, ve); @@ -14620,7 +14620,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) Core issue 106 says that creating a reference to a reference during instantiation is no longer a cause for failure. We only enforce this check in strict C++98 mode. */ - if ((TREE_CODE (type) == REFERENCE_TYPE + if ((TYPE_REF_P (type) && (((cxx_dialect == cxx98) && flag_iso) || code != REFERENCE_TYPE)) || (code == REFERENCE_TYPE && VOID_TYPE_P (type))) { @@ -14664,7 +14664,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) if (TREE_CODE (type) == METHOD_TYPE) r = build_ptrmemfunc_type (r); } - else if (TREE_CODE (type) == REFERENCE_TYPE) + else if (TYPE_REF_P (type)) /* In C++0x, during template argument substitution, when there is an attempt to create a reference to a reference type, reference collapsing is applied as described in [14.3.1/4 temp.arg.type]: @@ -14704,7 +14704,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) error ("creating pointer to member of non-class type %qT", r); return error_mark_node; } - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) { if (complain & tf_error) error ("creating pointer to member reference type %qT", type); @@ -14776,7 +14776,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) || TREE_CODE (type) == FUNCTION_TYPE || (TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == NULL_TREE) - || TREE_CODE (type) == REFERENCE_TYPE) + || TYPE_REF_P (type)) { if (complain & tf_error) error ("creating array of %qT", type); @@ -18862,7 +18862,7 @@ tsubst_copy_and_build (tree t, else if (outer_automatic_var_p (r)) r = process_outer_var_ref (r, complain); - if (TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE) + if (!TYPE_REF_P (TREE_TYPE (t))) /* If the original type was a reference, we'll be wrapped in the appropriate INDIRECT_REF. */ r = convert_from_reference (r); @@ -19728,11 +19728,11 @@ maybe_adjust_types_for_deduction (unification_kind_t strict, /* Core issue #873: Do the DR606 thing (see below) for these cases, too, but here handle it by stripping the reference from PARM rather than by adding it to ARG. */ - if (TREE_CODE (*parm) == REFERENCE_TYPE + if (TYPE_REF_P (*parm) && TYPE_REF_IS_RVALUE (*parm) && TREE_CODE (TREE_TYPE (*parm)) == TEMPLATE_TYPE_PARM && cp_type_quals (TREE_TYPE (*parm)) == TYPE_UNQUALIFIED - && TREE_CODE (*arg) == REFERENCE_TYPE + && TYPE_REF_P (*arg) && !TYPE_REF_IS_RVALUE (*arg)) *parm = TREE_TYPE (*parm); /* Nothing else to do in this case. */ @@ -19742,7 +19742,7 @@ maybe_adjust_types_for_deduction (unification_kind_t strict, gcc_unreachable (); } - if (TREE_CODE (*parm) != REFERENCE_TYPE) + if (!TYPE_REF_P (*parm)) { /* [temp.deduct.call] @@ -19774,7 +19774,7 @@ maybe_adjust_types_for_deduction (unification_kind_t strict, deduction (13.3.1.8)). If P is a forwarding reference and the argument is an lvalue, the type "lvalue reference to A" is used in place of A for type deduction. */ - if (TREE_CODE (*parm) == REFERENCE_TYPE + if (TYPE_REF_P (*parm) && TYPE_REF_IS_RVALUE (*parm) && TREE_CODE (TREE_TYPE (*parm)) == TEMPLATE_TYPE_PARM && !TEMPLATE_TYPE_PARM_FOR_CLASS (TREE_TYPE (*parm)) @@ -19792,7 +19792,7 @@ maybe_adjust_types_for_deduction (unification_kind_t strict, reference type, the type referred to by P is used for type deduction. */ *parm = TYPE_MAIN_VARIANT (*parm); - if (TREE_CODE (*parm) == REFERENCE_TYPE) + if (TYPE_REF_P (*parm)) { *parm = TREE_TYPE (*parm); result |= UNIFY_ALLOW_OUTER_MORE_CV_QUAL; @@ -19800,7 +19800,7 @@ maybe_adjust_types_for_deduction (unification_kind_t strict, /* DR 322. For conversion deduction, remove a reference type on parm too (which has been swapped into ARG). */ - if (strict == DEDUCE_CONV && TREE_CODE (*arg) == REFERENCE_TYPE) + if (strict == DEDUCE_CONV && TYPE_REF_P (*arg)) *arg = TREE_TYPE (*arg); return result; @@ -20937,7 +20937,7 @@ check_cv_quals_for_unify (int strict, tree arg, tree parm) types are not of the form "cv-list T" [14.8.2.5 temp.deduct.type]. It is ok when we're allowing additional CV qualifiers at the outer level [14.8.2.1]/3,1st bullet. */ - if ((TREE_CODE (arg) == REFERENCE_TYPE + if ((TYPE_REF_P (arg) || TREE_CODE (arg) == FUNCTION_TYPE || TREE_CODE (arg) == METHOD_TYPE) && (parm_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE))) @@ -21744,7 +21744,7 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, } case REFERENCE_TYPE: - if (TREE_CODE (arg) != REFERENCE_TYPE) + if (!TYPE_REF_P (arg)) return unify_type_mismatch (explain_p, parm, arg); return unify (tparms, targs, TREE_TYPE (parm), TREE_TYPE (arg), strict & UNIFY_ALLOW_MORE_CV_QUAL, explain_p); @@ -22308,14 +22308,14 @@ more_specialized_fn (tree pat1, tree pat2, int len) && !uses_deducible_template_parms (arg2)) goto next; - if (TREE_CODE (arg1) == REFERENCE_TYPE) + if (TYPE_REF_P (arg1)) { ref1 = TYPE_REF_IS_RVALUE (arg1) + 1; arg1 = TREE_TYPE (arg1); quals1 = cp_type_quals (arg1); } - if (TREE_CODE (arg2) == REFERENCE_TYPE) + if (TYPE_REF_P (arg2)) { ref2 = TYPE_REF_IS_RVALUE (arg2) + 1; arg2 = TREE_TYPE (arg2); @@ -24400,7 +24400,7 @@ invalid_nontype_parm_type_p (tree type, tsubst_flags_t complain) return false; else if (TYPE_PTR_P (type)) return false; - else if (TREE_CODE (type) == REFERENCE_TYPE + else if (TYPE_REF_P (type) && !TYPE_REF_IS_RVALUE (type)) return false; else if (TYPE_PTRMEM_P (type)) @@ -24470,7 +24470,7 @@ dependent_type_p_r (tree type) || dependent_type_p (TYPE_PTRMEM_POINTED_TO_TYPE (type))); else if (TYPE_PTR_P (type) - || TREE_CODE (type) == REFERENCE_TYPE) + || TYPE_REF_P (type)) return dependent_type_p (TREE_TYPE (type)); else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) @@ -24719,7 +24719,7 @@ value_dependent_expression_p (tree expression) with an expression that is value-dependent. */ if (DECL_DEPENDENT_INIT_P (expression) /* FIXME cp_finish_decl doesn't fold reference initializers. */ - || TREE_CODE (TREE_TYPE (expression)) == REFERENCE_TYPE) + || TYPE_REF_P (TREE_TYPE (expression))) return true; if (DECL_HAS_VALUE_EXPR_P (expression)) { @@ -26281,7 +26281,7 @@ build_deduction_guide (tree ctor, tree outer_args, tsubst_flags_t complain) if (TYPE_P (ctor)) { type = ctor; - bool copy_p = TREE_CODE (type) == REFERENCE_TYPE; + bool copy_p = TYPE_REF_P (type); if (copy_p) { type = TREE_TYPE (type); diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 6557817..94e8f54 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1334,7 +1334,7 @@ finish_handler_parms (tree decl, tree handler) if (warn_catch_value && type != NULL_TREE && type != error_mark_node - && TREE_CODE (TREE_TYPE (decl)) != REFERENCE_TYPE) + && !TYPE_REF_P (TREE_TYPE (decl))) { tree orig_type = TREE_TYPE (decl); if (CLASS_TYPE_P (orig_type)) @@ -1835,7 +1835,7 @@ finish_non_static_data_member (tree decl, tree object, tree qualifying_scope) { tree type = TREE_TYPE (decl); - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) /* Quals on the object don't matter. */; else if (PACK_EXPANSION_P (type)) /* Don't bother trying to represent this. */ @@ -2729,7 +2729,7 @@ finish_compound_literal (tree type, tree compound_literal, if (type == error_mark_node) return error_mark_node; - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) { compound_literal = finish_compound_literal (TREE_TYPE (type), compound_literal, @@ -4465,7 +4465,7 @@ omp_privatize_field (tree t, bool shared) return error_mark_node; if (!omp_private_member_map && !shared) omp_private_member_map = new hash_map; - if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE) + if (TYPE_REF_P (TREE_TYPE (t))) { gcc_assert (INDIRECT_REF_P (m)); m = TREE_OPERAND (m, 0); @@ -4783,7 +4783,7 @@ handle_omp_array_sections_1 (tree c, tree t, vec &types, } } } - else if (TREE_CODE (type) == POINTER_TYPE) + else if (TYPE_PTR_P (type)) { if (length == NULL_TREE) { @@ -4997,7 +4997,7 @@ handle_omp_array_sections (tree c, enum c_omp_region_type ort) eltype = TREE_TYPE (eltype); tree type = build_array_type (eltype, index_type); tree ptype = build_pointer_type (eltype); - if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE + if (TYPE_REF_P (TREE_TYPE (t)) && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (t)))) t = convert_from_reference (t); else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) @@ -5084,7 +5084,7 @@ handle_omp_array_sections (tree c, enum c_omp_region_type ort) OMP_CLAUSE_CHAIN (c) = c2; ptr = OMP_CLAUSE_DECL (c2); if (OMP_CLAUSE_MAP_KIND (c2) != GOMP_MAP_FIRSTPRIVATE_POINTER - && TREE_CODE (TREE_TYPE (ptr)) == REFERENCE_TYPE + && TYPE_REF_P (TREE_TYPE (ptr)) && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (ptr)))) { tree c3 = build_omp_clause (OMP_CLAUSE_LOCATION (c), @@ -5351,7 +5351,7 @@ void cp_check_omp_declare_reduction (tree udr) { tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr))); - gcc_assert (TREE_CODE (type) == REFERENCE_TYPE); + gcc_assert (TYPE_REF_P (type)); type = TREE_TYPE (type); int i; location_t loc = DECL_SOURCE_LOCATION (udr); @@ -5402,7 +5402,7 @@ cp_check_omp_declare_reduction (tree udr) "%<#pragma omp declare reduction%>", type); return; } - else if (TREE_CODE (type) == REFERENCE_TYPE) + else if (TYPE_REF_P (type)) { error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>", type); @@ -5511,7 +5511,7 @@ finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor) tree type = TREE_TYPE (t); if (TREE_CODE (t) == MEM_REF) type = TREE_TYPE (type); - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) type = TREE_TYPE (type); if (TREE_CODE (type) == ARRAY_TYPE) { @@ -5651,8 +5651,7 @@ finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor) if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0]))) cxx_mark_addressable (placeholder); if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1])) - && TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c))) - != REFERENCE_TYPE) + && !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))) cxx_mark_addressable (decl_placeholder ? decl_placeholder : OMP_CLAUSE_DECL (c)); tree omp_out = placeholder; @@ -5770,8 +5769,7 @@ finish_omp_declare_simd_methods (tree t) if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR && integer_zerop (OMP_CLAUSE_DECL (c)) && OMP_CLAUSE_LINEAR_STEP (c) - && TREE_CODE (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c))) - == POINTER_TYPE) + && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c)))) { tree s = OMP_CLAUSE_LINEAR_STEP (c); s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s); @@ -5800,7 +5798,7 @@ cp_finish_omp_clause_depend_sink (tree sink_clause) for (; t; t = TREE_CHAIN (t)) { tree decl = TREE_VALUE (t); - if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE) + if (TYPE_PTR_P (TREE_TYPE (decl))) { tree offset = TREE_PURPOSE (t); bool neg = wi::neg_p (wi::to_wide (offset)); @@ -5923,7 +5921,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) tree type = TREE_TYPE (t); if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL) - && TREE_CODE (type) != REFERENCE_TYPE) + && !TYPE_REF_P (type)) { error ("linear clause with %qs modifier applied to " "non-reference variable with %qT type", @@ -5932,12 +5930,12 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) remove = true; break; } - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) type = TREE_TYPE (type); if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF) { if (!INTEGRAL_TYPE_P (type) - && TREE_CODE (type) != POINTER_TYPE) + && !TYPE_PTR_P (type)) { error ("linear clause applied to non-integral non-pointer" " variable with %qT type", TREE_TYPE (t)); @@ -5958,7 +5956,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) && !INTEGRAL_TYPE_P (TREE_TYPE (t)) && (ort != C_ORT_OMP_DECLARE_SIMD || TREE_CODE (t) != PARM_DECL - || TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE + || !TYPE_REF_P (TREE_TYPE (t)) || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t))))) { error ("linear step expression must be integral"); @@ -5991,7 +5989,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) } t = fold_build_cleanup_point_expr (TREE_TYPE (t), t); tree type = TREE_TYPE (OMP_CLAUSE_DECL (c)); - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) type = TREE_TYPE (type); if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF) { @@ -6009,7 +6007,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) break; } } - else if (TREE_CODE (type) == POINTER_TYPE + else if (TYPE_PTR_P (type) /* Can't multiply the step yet if *this is still incomplete type. */ && (ort != C_ORT_OMP_DECLARE_SIMD @@ -6533,9 +6531,9 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) remove = true; } else if (!type_dependent_expression_p (t) - && TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE + && !TYPE_PTR_P (TREE_TYPE (t)) && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE - && (TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE + && (!TYPE_REF_P (TREE_TYPE (t)) || (!POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (t))) && (TREE_CODE (TREE_TYPE (TREE_TYPE (t))) != ARRAY_TYPE)))) @@ -6765,7 +6763,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) break; } else if (!processing_template_decl - && TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE + && !TYPE_REF_P (TREE_TYPE (t)) && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP || (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FIRSTPRIVATE_POINTER)) @@ -6777,8 +6775,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) == GOMP_MAP_FIRSTPRIVATE_POINTER))) && t == OMP_CLAUSE_DECL (c) && !type_dependent_expression_p (t) - && !cp_omp_mappable_type ((TREE_CODE (TREE_TYPE (t)) - == REFERENCE_TYPE) + && !cp_omp_mappable_type (TYPE_REF_P (TREE_TYPE (t)) ? TREE_TYPE (TREE_TYPE (t)) : TREE_TYPE (t))) { @@ -6845,7 +6842,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) if (!remove && !processing_template_decl && (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP - && TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c))) == REFERENCE_TYPE) + && TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c)))) { t = OMP_CLAUSE_DECL (c); if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) @@ -7043,10 +7040,10 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) if (!type_dependent_expression_p (t)) { tree type = TREE_TYPE (t); - if (TREE_CODE (type) != POINTER_TYPE + if (!TYPE_PTR_P (type) && TREE_CODE (type) != ARRAY_TYPE - && (TREE_CODE (type) != REFERENCE_TYPE - || (TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE + && (!TYPE_REF_P (type) + || (!TYPE_PTR_P (TREE_TYPE (type)) && TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))) { error_at (OMP_CLAUSE_LOCATION (c), @@ -7287,7 +7284,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) t = require_complete_type (t); if (t == error_mark_node) remove = true; - else if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE + else if (TYPE_REF_P (TREE_TYPE (t)) && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t)) remove = true; } @@ -7328,7 +7325,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) if ((need_complete_type || need_copy_assignment || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION) - && TREE_CODE (inner_type) == REFERENCE_TYPE) + && TYPE_REF_P (inner_type)) inner_type = TREE_TYPE (inner_type); while (TREE_CODE (inner_type) == ARRAY_TYPE) inner_type = TREE_TYPE (inner_type); @@ -8878,7 +8875,7 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */ cp_lvalue_kind clk = lvalue_kind (expr); type = unlowered_expr_type (expr); - gcc_assert (TREE_CODE (type) != REFERENCE_TYPE); + gcc_assert (!TYPE_REF_P (type)); /* For vector types, pick a non-opaque variant. */ if (VECTOR_TYPE_P (type)) @@ -9258,14 +9255,14 @@ capture_decltype (tree decl) case CPLD_COPY: type = TREE_TYPE (decl); - if (TREE_CODE (type) == REFERENCE_TYPE + if (TYPE_REF_P (type) && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE) type = TREE_TYPE (type); break; case CPLD_REFERENCE: type = TREE_TYPE (decl); - if (TREE_CODE (type) != REFERENCE_TYPE) + if (!TYPE_REF_P (type)) type = build_reference_type (TREE_TYPE (decl)); break; @@ -9273,7 +9270,7 @@ capture_decltype (tree decl) gcc_unreachable (); } - if (TREE_CODE (type) != REFERENCE_TYPE) + if (!TYPE_REF_P (type)) { if (!LAMBDA_EXPR_MUTABLE_P (lam)) type = cp_build_qualified_type (type, (cp_type_quals (type) @@ -9363,7 +9360,7 @@ finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain) if (error_operand_p (arg)) return error_mark_node; if (!type_dependent_expression_p (arg) - && TREE_CODE (TREE_TYPE (arg)) != POINTER_TYPE) + && !TYPE_PTR_P (TREE_TYPE (arg))) { error_at (loc, "non-pointer argument to %<__builtin_launder%>"); return error_mark_node; diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 313ff90..b2efab6 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -65,7 +65,7 @@ lvalue_kind (const_tree ref) return lvalue_kind (TREE_OPERAND (ref, 0)); if (TREE_TYPE (ref) - && TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE) + && TYPE_REF_P (TREE_TYPE (ref))) { /* unnamed rvalue references are rvalues */ if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref)) @@ -1100,7 +1100,7 @@ cp_build_reference_type (tree to_type, bool rval) if (to_type == error_mark_node) return error_mark_node; - if (TREE_CODE (to_type) == REFERENCE_TYPE) + if (TYPE_REF_P (to_type)) { rval = rval && TYPE_REF_IS_RVALUE (to_type); to_type = TREE_TYPE (to_type); @@ -1148,7 +1148,7 @@ tree move (tree expr) { tree type = TREE_TYPE (expr); - gcc_assert (TREE_CODE (type) != REFERENCE_TYPE); + gcc_assert (!TYPE_REF_P (type)); type = cp_build_reference_type (type, /*rval*/true); return build_static_cast (type, expr, tf_warning_or_error); } @@ -1260,11 +1260,11 @@ cp_build_qualified_type_real (tree type, [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295 (in CD1) we always ignore extra cv-quals on functions. */ if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE) - && (TREE_CODE (type) == REFERENCE_TYPE + && (TYPE_REF_P (type) || TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)) { - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); } @@ -5126,7 +5126,7 @@ stabilize_expr (tree exp, tree* initp) } /* There are no expressions with REFERENCE_TYPE, but there can be call arguments with such a type; just treat it as a pointer. */ - else if (TREE_CODE (TREE_TYPE (exp)) == REFERENCE_TYPE + else if (TYPE_REF_P (TREE_TYPE (exp)) || SCALAR_TYPE_P (TREE_TYPE (exp)) || !glvalue_p (exp)) { @@ -5287,7 +5287,7 @@ stabilize_init (tree init, tree *initp) { tree type = TREE_TYPE (ce->value); tree subinit; - if (TREE_CODE (type) == REFERENCE_TYPE + if (TYPE_REF_P (type) || SCALAR_TYPE_P (type)) ce->value = stabilize_expr (ce->value, &subinit); else if (!stabilize_init (ce->value, &subinit)) diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 05ae00e..e5eb35d 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -1181,8 +1181,8 @@ cxx_safe_arg_type_equiv_p (tree t1, tree t2) t1 = TYPE_MAIN_VARIANT (t1); t2 = TYPE_MAIN_VARIANT (t2); - if (TREE_CODE (t1) == POINTER_TYPE - && TREE_CODE (t2) == POINTER_TYPE) + if (TYPE_PTR_P (t1) + && TYPE_PTR_P (t2)) return true; /* The signedness of the parameter matters only when an integral @@ -2509,7 +2509,7 @@ build_class_member_access_expr (cp_expr object, tree member, /* Compute the type of the field, as described in [expr.ref]. */ type_quals = TYPE_UNQUALIFIED; member_type = TREE_TYPE (member); - if (TREE_CODE (member_type) != REFERENCE_TYPE) + if (!TYPE_REF_P (member_type)) { type_quals = (cp_type_quals (member_type) | cp_type_quals (object_type)); @@ -3131,7 +3131,7 @@ cp_build_indirect_ref_1 (tree ptr, ref_operator errorstring, (TREE_TYPE (ptr), TREE_TYPE (current_class_ptr))))) return current_class_ref; - pointer = (TREE_CODE (TREE_TYPE (ptr)) == REFERENCE_TYPE + pointer = (TYPE_REF_P (TREE_TYPE (ptr)) ? ptr : decay_conversion (ptr, complain)); if (pointer == error_mark_node) return error_mark_node; @@ -3901,10 +3901,10 @@ convert_arguments (tree typelist, vec **values, tree fndecl, Strip such NOP_EXPRs, since VAL is used in non-lvalue context. */ if (TREE_CODE (val) == NOP_EXPR && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)) - && (type == 0 || TREE_CODE (type) != REFERENCE_TYPE)) + && (type == 0 || !TYPE_REF_P (type))) val = TREE_OPERAND (val, 0); - if (type == 0 || TREE_CODE (type) != REFERENCE_TYPE) + if (type == 0 || !TYPE_REF_P (type)) { if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE @@ -4176,7 +4176,7 @@ warn_for_null_address (location_t location, tree op, tsubst_flags_t complain) "be NULL", TREE_OPERAND (cop, 0)); if (CONVERT_EXPR_P (op) - && TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == REFERENCE_TYPE) + && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (op, 0)))) { tree inner_op = op; STRIP_NOPS (inner_op); @@ -5876,7 +5876,7 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain) } } - if (TREE_CODE (argtype) == REFERENCE_TYPE) + if (TYPE_REF_P (argtype)) { tree type = build_pointer_type (TREE_TYPE (argtype)); arg = build1 (CONVERT_EXPR, type, arg); @@ -5898,7 +5898,7 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain) if (INDIRECT_REF_P (arg)) { arg = TREE_OPERAND (arg, 0); - if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE) + if (TYPE_REF_P (TREE_TYPE (arg))) { tree type = build_pointer_type (TREE_TYPE (TREE_TYPE (arg))); arg = build1 (CONVERT_EXPR, type, arg); @@ -5943,7 +5943,7 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain) gcc_assert (PTRMEM_OK_P (arg)); t = TREE_OPERAND (arg, 1); - if (TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE) + if (TYPE_REF_P (TREE_TYPE (t))) { if (complain & tf_error) error ("cannot create pointer to reference member %qD", t); @@ -6805,7 +6805,7 @@ maybe_warn_about_useless_cast (tree type, tree expr, tsubst_flags_t complain) if (warn_useless_cast && complain & tf_warning) { - if ((TREE_CODE (type) == REFERENCE_TYPE + if ((TYPE_REF_P (type) && (TYPE_REF_IS_RVALUE (type) ? xvalue_p (expr) : lvalue_p (expr)) && same_type_p (TREE_TYPE (expr), TREE_TYPE (type))) @@ -6922,7 +6922,7 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p, we want to avoid constructing a new D. The standard is not completely clear about this issue, but our interpretation is consistent with other compilers. */ - if (TREE_CODE (type) == REFERENCE_TYPE + if (TYPE_REF_P (type) && CLASS_TYPE_P (TREE_TYPE (type)) && CLASS_TYPE_P (intype) && (TYPE_REF_IS_RVALUE (type) || lvalue_p (expr)) @@ -6991,7 +6991,7 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p, /* "A glvalue of type cv1 T1 can be cast to type rvalue reference to cv2 T2 if cv2 T2 is reference-compatible with cv1 T1 (8.5.3)." */ - if (TREE_CODE (type) == REFERENCE_TYPE + if (TYPE_REF_P (type) && TYPE_REF_IS_RVALUE (type) && (clk = real_lvalue_p (expr)) && reference_related_p (TREE_TYPE (type), intype) @@ -7055,7 +7055,7 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p, If T is a reference type, the result is an lvalue; otherwise, the result is an rvalue. */ - if (TREE_CODE (type) != REFERENCE_TYPE) + if (!TYPE_REF_P (type)) { result = rvalue (result); @@ -7221,7 +7221,7 @@ build_static_cast (tree type, tree oexpr, tsubst_flags_t complain) /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue. Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */ - if (TREE_CODE (type) != REFERENCE_TYPE + if (!TYPE_REF_P (type) && TREE_CODE (expr) == NOP_EXPR && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0))) expr = TREE_OPERAND (expr, 0); @@ -7330,7 +7330,7 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p, "reference to T2" if an expression of type "pointer to T1" can be explicitly converted to the type "pointer to T2" using a reinterpret_cast. */ - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TYPE_REF_P (type)) { if (! lvalue_p (expr)) { @@ -7582,7 +7582,7 @@ build_const_cast_1 (tree dst_type, tree expr, tsubst_flags_t complain, src_type = TREE_TYPE (expr); /* Expressions do not really have reference types. */ - if (TREE_CODE (src_type) == REFERENCE_TYPE) + if (TYPE_REF_P (src_type)) src_type = TREE_TYPE (src_type); /* [expr.const.cast] @@ -7600,7 +7600,7 @@ build_const_cast_1 (tree dst_type, tree expr, tsubst_flags_t complain, -- if T1 is a class type, a prvalue of type T1 can be explicitly converted to an xvalue of type T2 using the cast const_cast. */ - if (TREE_CODE (dst_type) == REFERENCE_TYPE) + if (TYPE_REF_P (dst_type)) { reference_type = dst_type; if (!TYPE_REF_IS_RVALUE (dst_type) @@ -7763,7 +7763,7 @@ cp_build_c_cast (tree type, tree expr, tsubst_flags_t complain) /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue. Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */ - if (TREE_CODE (type) != REFERENCE_TYPE + if (!TYPE_REF_P (type) && TREE_CODE (value) == NOP_EXPR && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0))) value = TREE_OPERAND (value, 0); @@ -7841,7 +7841,7 @@ cp_build_c_cast (tree type, tree expr, tsubst_flags_t complain) if (!CLASS_TYPE_P (type)) type = TYPE_MAIN_VARIANT (type); result_type = TREE_TYPE (result); - if (!CLASS_TYPE_P (result_type) && TREE_CODE (type) != REFERENCE_TYPE) + if (!CLASS_TYPE_P (result_type) && !TYPE_REF_P (type)) result_type = TYPE_MAIN_VARIANT (result_type); /* If the type of RESULT does not match TYPE, perform a const_cast to make it match. If the static_cast or @@ -8083,7 +8083,7 @@ cp_build_modify_expr (location_t loc, tree lhs, enum tree_code modifycode, /* A binary op has been requested. Combine the old LHS value with the RHS producing the value we should actually store into the LHS. */ - gcc_assert (!((TREE_CODE (lhstype) == REFERENCE_TYPE + gcc_assert (!((TYPE_REF_P (lhstype) && MAYBE_CLASS_TYPE_P (TREE_TYPE (lhstype))) || MAYBE_CLASS_TYPE_P (lhstype))); @@ -8122,8 +8122,8 @@ cp_build_modify_expr (location_t loc, tree lhs, enum tree_code modifycode, goto ret; } } - gcc_assert (TREE_CODE (lhstype) != REFERENCE_TYPE); - gcc_assert (TREE_CODE (TREE_TYPE (newrhs)) != REFERENCE_TYPE); + gcc_assert (!TYPE_REF_P (lhstype)); + gcc_assert (!TYPE_REF_P (TREE_TYPE (newrhs))); } /* The left-hand side must be an lvalue. */ @@ -8955,7 +8955,7 @@ convert_for_initialization (tree exp, tree type, tree rhs, int flags, ; else if ((TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE && TREE_CODE (type) != ARRAY_TYPE - && (TREE_CODE (type) != REFERENCE_TYPE + && (!TYPE_REF_P (type) || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE)) || (TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE && !TYPE_REFFN_P (type)) @@ -9037,7 +9037,7 @@ maybe_warn_about_returning_address_of_local (tree retval) || TREE_CODE (whats_returned) == ARRAY_REF) whats_returned = TREE_OPERAND (whats_returned, 0); - if (TREE_CODE (valtype) == REFERENCE_TYPE) + if (TYPE_REF_P (valtype)) { if (TREE_CODE (whats_returned) == AGGR_INIT_EXPR || TREE_CODE (whats_returned) == TARGET_EXPR) @@ -9061,7 +9061,7 @@ maybe_warn_about_returning_address_of_local (tree retval) && !(TREE_STATIC (whats_returned) || TREE_PUBLIC (whats_returned))) { - if (TREE_CODE (valtype) == REFERENCE_TYPE) + if (TYPE_REF_P (valtype)) warning_at (DECL_SOURCE_LOCATION (whats_returned), OPT_Wreturn_local_addr, "reference to local variable %qD returned", @@ -9263,7 +9263,7 @@ check_return_expr (tree retval, bool *no_warning) /* The function return type must be a reference to the current class. */ - if (TREE_CODE (valtype) == REFERENCE_TYPE + if (TYPE_REF_P (valtype) && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (valtype), TREE_TYPE (current_class_ref))) { @@ -9614,7 +9614,7 @@ cp_type_quals (const_tree type) quals = TYPE_QUALS (type); /* METHOD and REFERENCE_TYPEs should never have quals. */ gcc_assert ((TREE_CODE (type) != METHOD_TYPE - && TREE_CODE (type) != REFERENCE_TYPE) + && !TYPE_REF_P (type)) || ((quals & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE)) == TYPE_UNQUALIFIED)); return quals; @@ -9801,7 +9801,7 @@ casts_away_constness_r (tree *t1, tree *t2, tsubst_flags_t complain) static bool casts_away_constness (tree t1, tree t2, tsubst_flags_t complain) { - if (TREE_CODE (t2) == REFERENCE_TYPE) + if (TYPE_REF_P (t2)) { /* [expr.const.cast] @@ -9809,7 +9809,7 @@ casts_away_constness (tree t1, tree t2, tsubst_flags_t complain) using a reference cast casts away constness if a cast from an rvalue of type "pointer to T1" to the type "pointer to T2" casts away constness. */ - t1 = (TREE_CODE (t1) == REFERENCE_TYPE ? TREE_TYPE (t1) : t1); + t1 = (TYPE_REF_P (t1) ? TREE_TYPE (t1) : t1); return casts_away_constness (build_pointer_type (t1), build_pointer_type (TREE_TYPE (t2)), complain); @@ -9849,7 +9849,7 @@ casts_away_constness (tree t1, tree t2, tsubst_flags_t complain) tree non_reference (tree t) { - if (t && TREE_CODE (t) == REFERENCE_TYPE) + if (t && TYPE_REF_P (t)) t = TREE_TYPE (t); return t; } diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 444ebfd..682303a 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -111,7 +111,7 @@ cxx_readonly_error (tree arg, enum lvalue_use errstring) "constant field %qD"), arg); else if (INDIRECT_REF_P (arg) - && TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))) == REFERENCE_TYPE + && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (arg, 0))) && (VAR_P (TREE_OPERAND (arg, 0)) || TREE_CODE (TREE_OPERAND (arg, 0)) == PARM_DECL)) ERROR_FOR_ASSIGNMENT (G_("assignment of " @@ -845,7 +845,7 @@ store_init_value (tree decl, tree init, vec** cleanups, int flags) || error_operand_p (value)); DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = const_init; /* FIXME setting TREE_CONSTANT on refs breaks the back end. */ - if (TREE_CODE (type) != REFERENCE_TYPE) + if (!TYPE_REF_P (type)) TREE_CONSTANT (decl) = const_init && decl_maybe_constant_var_p (decl); } value = cp_fully_fold (value); @@ -1498,7 +1498,7 @@ process_init_constructor_record (tree type, tree init, int nested, else { const_tree fldtype = TREE_TYPE (field); - if (TREE_CODE (fldtype) == REFERENCE_TYPE) + if (TYPE_REF_P (fldtype)) { if (complain & tf_error) error ("member %qD is uninitialized reference", field); @@ -1823,7 +1823,7 @@ build_x_arrow (location_t loc, tree expr, tsubst_flags_t complain) if (processing_template_decl) { - if (type && TREE_CODE (type) == POINTER_TYPE + if (type && TYPE_PTR_P (type) && !dependent_scope_p (TREE_TYPE (type))) /* Pointer to current instantiation, don't treat as dependent. */; else if (type_dependent_expression_p (expr)) @@ -1873,7 +1873,7 @@ build_x_arrow (location_t loc, tree expr, tsubst_flags_t complain) return error_mark_node; } - if (TREE_CODE (TREE_TYPE (last_rval)) == REFERENCE_TYPE) + if (TYPE_REF_P (TREE_TYPE (last_rval))) last_rval = convert_from_reference (last_rval); } else @@ -2108,7 +2108,7 @@ build_functional_cast (tree exp, tree parms, tsubst_flags_t complain) /* Diagnose this even in a template. We could also try harder to give all the usual errors when the type and args are non-dependent... */ - if (TREE_CODE (type) == REFERENCE_TYPE && !parms) + if (TYPE_REF_P (type) && !parms) { if (complain & tf_error) error ("invalid value-initialization of reference type"); @@ -2206,7 +2206,7 @@ add_exception_specifier (tree list, tree spec, int complain) incomplete, or pointer or ref to incomplete other than pointer to cv void. */ is_ptr = TYPE_PTR_P (core); - if (is_ptr || TREE_CODE (core) == REFERENCE_TYPE) + if (is_ptr || TYPE_REF_P (core)) core = TREE_TYPE (core); if (complain < 0) ok = true; -- 2.7.4