diff options
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 24 | ||||
-rw-r--r-- | gcc/cp/call.c | 28 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 10 | ||||
-rw-r--r-- | gcc/cp/parser.c | 32 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 14 |
5 files changed, 84 insertions, 24 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0ebc366..beae265 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,29 @@ 2018-12-19 David Malcolm <dmalcolm@redhat.com> + PR c++/87504 + * call.c (op_error): Convert 1st param from location_t to + const op_location_t &. Use binary_op_rich_location for binary + ops. + (build_conditional_expr_1): Convert 1st param from location_t to + const op_location_t &. + (build_conditional_expr): Likewise. + (build_new_op_1): Likewise. + (build_new_op): Likewise. + * cp-tree.h (build_conditional_expr): Likewise. + (build_new_op): Likewise. + (build_x_binary_op): Likewise. + (cp_build_binary_op): Likewise. + * parser.c (cp_parser_primary_expression): Build a location + for id-expression nodes. + (cp_parser_binary_expression): Use an op_location_t when + calling build_x_binary_op. + (cp_parser_operator): Build a location for user-defined literals. + * typeck.c (build_x_binary_op): Convert 1st param from location_t + to const op_location_t &. + (cp_build_binary_op): Likewise. Use binary_op_rich_location. + +2018-12-19 David Malcolm <dmalcolm@redhat.com> + PR c++/43064 PR c++/43486 * call.c (build_conditional_expr_1): Strip location wrappers when diff --git a/gcc/cp/call.c b/gcc/cp/call.c index ef3a02c..e2f8fe1 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -166,8 +166,8 @@ static tree build_over_call (struct z_candidate *, int, tsubst_flags_t); /*c_cast_p=*/false, (COMPLAIN)) static tree convert_like_real (conversion *, tree, tree, int, bool, bool, tsubst_flags_t); -static void op_error (location_t, enum tree_code, enum tree_code, tree, - tree, tree, bool); +static void op_error (const op_location_t &, enum tree_code, enum tree_code, + tree, tree, tree, bool); static struct z_candidate *build_user_type_conversion_1 (tree, tree, int, tsubst_flags_t); static void print_z_candidate (location_t, const char *, struct z_candidate *); @@ -4713,7 +4713,8 @@ op_error_string (const char *errmsg, int ntypes, bool match) } static void -op_error (location_t loc, enum tree_code code, enum tree_code code2, +op_error (const op_location_t &loc, + enum tree_code code, enum tree_code code2, tree arg1, tree arg2, tree arg3, bool match) { bool assop = code == MODIFY_EXPR; @@ -4767,8 +4768,12 @@ op_error (location_t loc, enum tree_code code, enum tree_code code2, default: if (arg2) if (flag_diagnostics_show_caret) - error_at (loc, op_error_string (G_("%<operator%s%>"), 2, match), - opname, TREE_TYPE (arg1), TREE_TYPE (arg2)); + { + binary_op_rich_location richloc (loc, arg1, arg2, true); + error_at (&richloc, + op_error_string (G_("%<operator%s%>"), 2, match), + opname, TREE_TYPE (arg1), TREE_TYPE (arg2)); + } else error_at (loc, op_error_string (G_("%<operator%s%> in %<%E %s %E%>"), 2, match), @@ -4867,7 +4872,8 @@ conditional_conversion (tree e1, tree e2, tsubst_flags_t complain) arguments to the conditional expression. */ static tree -build_conditional_expr_1 (location_t loc, tree arg1, tree arg2, tree arg3, +build_conditional_expr_1 (const op_location_t &loc, + tree arg1, tree arg2, tree arg3, tsubst_flags_t complain) { tree arg2_type; @@ -5461,7 +5467,8 @@ build_conditional_expr_1 (location_t loc, tree arg1, tree arg2, tree arg3, /* Wrapper for above. */ tree -build_conditional_expr (location_t loc, tree arg1, tree arg2, tree arg3, +build_conditional_expr (const op_location_t &loc, + tree arg1, tree arg2, tree arg3, tsubst_flags_t complain) { tree ret; @@ -5650,8 +5657,9 @@ op_is_ordered (tree_code code) } static tree -build_new_op_1 (location_t loc, enum tree_code code, int flags, tree arg1, - tree arg2, tree arg3, tree *overload, tsubst_flags_t complain) +build_new_op_1 (const op_location_t &loc, enum tree_code code, int flags, + tree arg1, tree arg2, tree arg3, tree *overload, + tsubst_flags_t complain) { struct z_candidate *candidates = 0, *cand; vec<tree, va_gc> *arglist; @@ -6130,7 +6138,7 @@ build_new_op_1 (location_t loc, enum tree_code code, int flags, tree arg1, /* Wrapper for above. */ tree -build_new_op (location_t loc, enum tree_code code, int flags, +build_new_op (const op_location_t &loc, enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, tree *overload, tsubst_flags_t complain) { diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 1d806b7..8a95095 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6097,7 +6097,8 @@ extern int raw_dump_id; extern bool check_dtor_name (tree, tree); int magic_varargs_p (tree); -extern tree build_conditional_expr (location_t, tree, tree, tree, +extern tree build_conditional_expr (const op_location_t &, + tree, tree, tree, tsubst_flags_t); extern tree build_addr_func (tree, tsubst_flags_t); extern void set_flags_from_callee (tree); @@ -6122,7 +6123,8 @@ extern tree build_new_method_call (tree, tree, extern tree build_special_member_call (tree, tree, vec<tree, va_gc> **, tree, int, tsubst_flags_t); -extern tree build_new_op (location_t, enum tree_code, +extern tree build_new_op (const op_location_t &, + enum tree_code, int, tree, tree, tree, tree *, tsubst_flags_t); extern tree build_op_call (tree, vec<tree, va_gc> **, @@ -7339,7 +7341,7 @@ extern tree cp_build_function_call_nary (tree, tsubst_flags_t, ...) ATTRIBUTE_SENTINEL; extern tree cp_build_function_call_vec (tree, vec<tree, va_gc> **, tsubst_flags_t); -extern tree build_x_binary_op (location_t, +extern tree build_x_binary_op (const op_location_t &, enum tree_code, tree, enum tree_code, tree, enum tree_code, tree *, @@ -7406,7 +7408,7 @@ extern tree composite_pointer_type (tree, tree, tree, tree, extern tree merge_types (tree, tree); extern tree strip_array_domain (tree); extern tree check_return_expr (tree, bool *); -extern tree cp_build_binary_op (location_t, +extern tree cp_build_binary_op (const op_location_t &, enum tree_code, tree, tree, tsubst_flags_t); extern tree build_x_vec_perm_expr (location_t, diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index c0552b5..e5381b4 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -5710,8 +5710,21 @@ cp_parser_primary_expression (cp_parser *parser, id_expression.get_location ())); if (error_msg) cp_parser_error (parser, error_msg); - decl.set_location (id_expression.get_location ()); - decl.set_range (id_expr_token->location, id_expression.get_finish ()); + /* Build a location for an id-expression of the form: + ::ns::id + ~~~~~~^~ + or: + id + ^~ + i.e. from the start of the first token to the end of the final + token, with the caret at the start of the unqualified-id. */ + location_t caret_loc = get_pure_location (id_expression.get_location ()); + location_t start_loc = get_start (id_expr_token->location); + location_t finish_loc = get_finish (id_expression.get_location ()); + location_t combined_loc + = make_location (caret_loc, start_loc, finish_loc); + + decl.set_location (combined_loc); return decl; } @@ -9556,7 +9569,8 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p, } else { - current.lhs = build_x_binary_op (combined_loc, current.tree_type, + op_location_t op_loc (current.loc, combined_loc); + current.lhs = build_x_binary_op (op_loc, current.tree_type, current.lhs, current.lhs_type, rhs, rhs_type, &overload, complain_flags (decltype_p)); @@ -15391,8 +15405,16 @@ cp_parser_operator (cp_parser* parser, location_t start_loc) const char *name = IDENTIFIER_POINTER (id); id = cp_literal_operator_id (name); } - start_loc = make_location (start_loc, start_loc, get_finish (end_loc)); - return cp_expr (id, start_loc); + /* Generate a location of the form: + "" _suffix_identifier + ^~~~~~~~~~~~~~~~~~~~~ + with caret == start at the start token, finish at the end of the + suffix identifier. */ + location_t finish_loc + = get_finish (cp_lexer_previous_token (parser->lexer)->location); + location_t combined_loc + = make_location (start_loc, start_loc, finish_loc); + return cp_expr (id, combined_loc); } default: diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 519510d..94a33d4 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4128,7 +4128,7 @@ convert_arguments (tree typelist, vec<tree, va_gc> **values, tree fndecl, ARG2_CODE as ERROR_MARK. */ tree -build_x_binary_op (location_t loc, enum tree_code code, tree arg1, +build_x_binary_op (const op_location_t &loc, enum tree_code code, tree arg1, enum tree_code arg1_code, tree arg2, enum tree_code arg2_code, tree *overload_p, tsubst_flags_t complain) @@ -4317,7 +4317,7 @@ warn_for_null_address (location_t location, tree op, tsubst_flags_t complain) multiple inheritance, and deal with pointer to member functions. */ tree -cp_build_binary_op (location_t location, +cp_build_binary_op (const op_location_t &location, enum tree_code code, tree orig_op0, tree orig_op1, tsubst_flags_t complain) { @@ -5314,9 +5314,13 @@ cp_build_binary_op (location_t location, if (!result_type) { if (complain & tf_error) - error_at (location, - "invalid operands of types %qT and %qT to binary %qO", - TREE_TYPE (orig_op0), TREE_TYPE (orig_op1), code); + { + binary_op_rich_location richloc (location, + orig_op0, orig_op1, true); + error_at (&richloc, + "invalid operands of types %qT and %qT to binary %qO", + TREE_TYPE (orig_op0), TREE_TYPE (orig_op1), code); + } return error_mark_node; } |