diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2019-12-18 19:23:01 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2019-12-18 19:23:01 +0000 |
commit | d3769410c65a7d3f2d58402c3ecf5c253e340c2e (patch) | |
tree | b4db956e077c48a691a959e453a8afb0aa65b4cf /gcc/cp | |
parent | a7389ce5d4505a7a3596539ad3a844a850e769d4 (diff) | |
download | gcc-d3769410c65a7d3f2d58402c3ecf5c253e340c2e.zip gcc-d3769410c65a7d3f2d58402c3ecf5c253e340c2e.tar.gz gcc-d3769410c65a7d3f2d58402c3ecf5c253e340c2e.tar.bz2 |
typeck.c (cxx_sizeof_or_alignof_type): Add location_t parameter and use it throughout.
/gcc/cp
2019-12-18 Paolo Carlini <paolo.carlini@oracle.com>
* typeck.c (cxx_sizeof_or_alignof_type): Add location_t parameter
and use it throughout.
(cxx_sizeof_expr): Likewise.
(cxx_alignof_expr): Likewise.
(cxx_sizeof_or_alignof_expr): Likewise.
(cxx_alignas_expr): Update call.
* decl.c (fold_sizeof_expr): Likewise.
* pt.c (tsubst_copy): Likewise.
(tsubst_copy_and_build): Likewise.
* except.c (build_throw): Add location_t parameter and use it.
(expand_end_catch_block): Update call.
* parser.c (cp_parser_unary_expression): Update
cxx_sizeof_or_alignof_type and cxx_sizeof_or_alignof_expr calls,
pass the compound location.
(cp_parser_throw_expression): Likewise pass the combined location
to build_throw.
* cp-tree.h: Update declarations.
* semantics.c (finish_handler_parms): Use DECL_SOURCE_LOCATION.
* decl2.c (check_classfn): Likewise.
* except.c (is_admissible_throw_operand_or_catch_parameter):
Exploit cp_expr_loc_or_input_loc in one place.
* except.c (create_try_catch_expr): Remove, unused.
/libcc1
2019-12-18 Paolo Carlini <paolo.carlini@oracle.com>
* libcp1plugin.cc (plugin_build_unary_expr): Update build_throw
and cxx_sizeof_or_alignof_expr calls.
(plugin_build_unary_type_expr): Likewise for
cxx_sizeof_or_alignof_type.
/gcc/testsuite
2019-12-18 Paolo Carlini <paolo.carlini@oracle.com>
* g++.dg/diagnostic/alignof2.C: New.
* g++.dg/diagnostic/alignof3.C: Likewise.
* g++.dg/diagnostic/incomplete-type-1.C: Likewise.
* g++.dg/warn/Wcatch-value-3b.C: Likewise.
* g++.dg/cpp0x/alignof3.C: Check location(s) too.
* g++.dg/cpp1z/decomp-bitfield1.C: Likewise.
* g++.dg/cpp1z/has-unique-obj-representations2.C: Likewise.
* g++.dg/expr/sizeof3.C: Likewise.
* g++.dg/ext/flexary6.C: Likewise.
* g++.dg/ext/vla4.C: Likewise.
* g++.dg/template/sizeof11.C: Likewise.
* g++.dg/warn/Wcatch-value-1.C: Likewise.
* g++.dg/warn/Wcatch-value-2.C: Likewise.
* g++.dg/warn/Wcatch-value-3.C: Likewise.
* g++.old-deja/g++.brendan/sizeof1.C: Likewise.
* g++.old-deja/g++.brendan/sizeof3.C: Likewise.
* g++.old-deja/g++.brendan/sizeof4.C: Likewise.
* g++.old-deja/g++.eh/ctor1.C: Likewise.
* g++.old-deja/g++.jason/ambig1.C: Likewise.
* g++.old-deja/g++.other/sizeof4.C: Likewise.
From-SVN: r279543
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 28 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 11 | ||||
-rw-r--r-- | gcc/cp/decl.c | 9 | ||||
-rw-r--r-- | gcc/cp/decl2.c | 3 | ||||
-rw-r--r-- | gcc/cp/except.c | 38 | ||||
-rw-r--r-- | gcc/cp/parser.c | 30 | ||||
-rw-r--r-- | gcc/cp/pt.c | 14 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 16 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 63 |
9 files changed, 123 insertions, 89 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8b1d4e0..90a6d18 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,31 @@ +2019-12-18 Paolo Carlini <paolo.carlini@oracle.com> + + * typeck.c (cxx_sizeof_or_alignof_type): Add location_t parameter + and use it throughout. + (cxx_sizeof_expr): Likewise. + (cxx_alignof_expr): Likewise. + (cxx_sizeof_or_alignof_expr): Likewise. + (cxx_alignas_expr): Update call. + * decl.c (fold_sizeof_expr): Likewise. + * pt.c (tsubst_copy): Likewise. + (tsubst_copy_and_build): Likewise. + * except.c (build_throw): Add location_t parameter and use it. + (expand_end_catch_block): Update call. + * parser.c (cp_parser_unary_expression): Update + cxx_sizeof_or_alignof_type and cxx_sizeof_or_alignof_expr calls, + pass the compound location. + (cp_parser_throw_expression): Likewise pass the combined location + to build_throw. + * cp-tree.h: Update declarations. + + * semantics.c (finish_handler_parms): Use DECL_SOURCE_LOCATION. + * decl2.c (check_classfn): Likewise. + + * except.c (is_admissible_throw_operand_or_catch_parameter): + Exploit cp_expr_loc_or_input_loc in one place. + + * except.c (create_try_catch_expr): Remove, unused. + 2019-12-17 Jason Merrill <jason@redhat.com> PR c++/12333 - X::~X() with implicit this->. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index c35ed9a..3d1d62c 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6657,7 +6657,7 @@ extern void init_exception_processing (void); extern tree expand_start_catch_block (tree); extern void expand_end_catch_block (void); extern tree build_exc_ptr (void); -extern tree build_throw (tree); +extern tree build_throw (location_t, tree); extern int nothrow_libfn_p (const_tree); extern void check_handlers (tree); extern tree finish_noexcept_expr (tree, tsubst_flags_t); @@ -6674,7 +6674,6 @@ extern tree begin_eh_spec_block (void); extern void finish_eh_spec_block (tree, tree); extern tree build_eh_type_type (tree); extern tree cp_protect_cleanup_actions (void); -extern tree create_try_catch_expr (tree, tree); extern tree template_parms_to_args (tree); extern tree template_parms_level_to_args (tree); extern tree generic_targs_for (tree); @@ -7487,8 +7486,10 @@ extern bool compparms (const_tree, const_tree); extern int comp_cv_qualification (const_tree, const_tree); extern int comp_cv_qualification (int, int); extern int comp_cv_qual_signature (tree, tree); -extern tree cxx_sizeof_or_alignof_expr (tree, enum tree_code, bool); -extern tree cxx_sizeof_or_alignof_type (tree, enum tree_code, bool, bool); +extern tree cxx_sizeof_or_alignof_expr (location_t, tree, + enum tree_code, bool); +extern tree cxx_sizeof_or_alignof_type (location_t, tree, + enum tree_code, bool, bool); extern tree cxx_alignas_expr (tree); extern tree cxx_sizeof_nowarn (tree); extern tree is_bitfield_expr_with_lowered_type (const_tree); @@ -7604,7 +7605,7 @@ extern tree cp_build_binary_op (const op_location_t &, extern tree build_x_vec_perm_expr (location_t, tree, tree, tree, tsubst_flags_t); -#define cxx_sizeof(T) cxx_sizeof_or_alignof_type (T, SIZEOF_EXPR, false, true) +#define cxx_sizeof(T) cxx_sizeof_or_alignof_type (input_location, T, SIZEOF_EXPR, false, true) extern tree build_simple_component_ref (tree, tree); extern tree build_ptrmemfunc_access_expr (tree, tree); extern tree build_address (tree); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 86717dc..7d4c947 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -10219,13 +10219,16 @@ fold_sizeof_expr (tree t) { tree r; if (SIZEOF_EXPR_TYPE_P (t)) - r = cxx_sizeof_or_alignof_type (TREE_TYPE (TREE_OPERAND (t, 0)), + r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t), + TREE_TYPE (TREE_OPERAND (t, 0)), SIZEOF_EXPR, false, false); else if (TYPE_P (TREE_OPERAND (t, 0))) - r = cxx_sizeof_or_alignof_type (TREE_OPERAND (t, 0), SIZEOF_EXPR, + r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t), + TREE_OPERAND (t, 0), SIZEOF_EXPR, false, false); else - r = cxx_sizeof_or_alignof_expr (TREE_OPERAND (t, 0), SIZEOF_EXPR, + r = cxx_sizeof_or_alignof_expr (EXPR_LOCATION (t), + TREE_OPERAND (t, 0), SIZEOF_EXPR, false); if (r == error_mark_node) r = size_one_node; diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index ea83210..0352954 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -698,7 +698,8 @@ check_classfn (tree ctype, tree function, tree template_parms) if (!matched) { if (!COMPLETE_TYPE_P (ctype)) - cxx_incomplete_type_error (function, ctype); + cxx_incomplete_type_error (DECL_SOURCE_LOCATION (function), + function, ctype); else { if (DECL_CONV_FN_P (function)) diff --git a/gcc/cp/except.c b/gcc/cp/except.c index 8bc831d..e385c67 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -507,7 +507,7 @@ expand_end_catch_block (void) && (DECL_CONSTRUCTOR_P (current_function_decl) || DECL_DESTRUCTOR_P (current_function_decl))) { - tree rethrow = build_throw (NULL_TREE); + tree rethrow = build_throw (input_location, NULL_TREE); TREE_NO_WARNING (rethrow) = true; finish_expr_stmt (rethrow); } @@ -627,7 +627,7 @@ wrap_cleanups_r (tree *tp, int *walk_subtrees, void * /*data*/) /* Build a throw expression. */ tree -build_throw (tree exp) +build_throw (location_t loc, tree exp) { if (exp == error_mark_node) return exp; @@ -637,12 +637,13 @@ build_throw (tree exp) if (cfun) current_function_returns_abnormally = 1; exp = build_min (THROW_EXPR, void_type_node, exp); - SET_EXPR_LOCATION (exp, input_location); + SET_EXPR_LOCATION (exp, loc); return exp; } if (exp && null_node_p (exp)) - warning (0, "throwing NULL, which has integral, not pointer type"); + warning_at (loc, 0, + "throwing NULL, which has integral, not pointer type"); if (exp != NULL_TREE) { @@ -758,6 +759,7 @@ build_throw (tree exp) { int flags = LOOKUP_NORMAL | LOOKUP_ONLYCONVERTING; bool converted = false; + location_t exp_loc = cp_expr_loc_or_loc (exp, loc); /* Under C++0x [12.8/16 class.copy], a thrown lvalue is sometimes treated as an rvalue for the purposes of overload resolution @@ -790,7 +792,7 @@ build_throw (tree exp) if (exp == error_mark_node) { - error (" in thrown expression"); + inform (exp_loc, " in thrown expression"); return error_mark_node; } } @@ -867,8 +869,7 @@ build_throw (tree exp) exp = cp_build_function_call_vec (rethrow_fn, NULL, tf_warning_or_error); } - exp = build1 (THROW_EXPR, void_type_node, exp); - SET_EXPR_LOCATION (exp, input_location); + exp = build1_loc (loc, THROW_EXPR, void_type_node, exp); return exp; } @@ -948,8 +949,9 @@ is_admissible_throw_operand_or_catch_parameter (tree t, bool is_throw) else if (variably_modified_type_p (type, NULL_TREE)) { if (is_throw) - error ("cannot throw expression of type %qT because it involves " - "types of variable size", type); + error_at (cp_expr_loc_or_input_loc (expr), + "cannot throw expression of type %qT because it involves " + "types of variable size", type); else error ("cannot catch type %qT because it involves types of " "variable size", type); @@ -1321,22 +1323,4 @@ build_noexcept_spec (tree expr, tsubst_flags_t complain) } } -/* Returns a TRY_CATCH_EXPR that will put TRY_LIST and CATCH_LIST in the - TRY and CATCH locations. CATCH_LIST must be a STATEMENT_LIST */ - -tree -create_try_catch_expr (tree try_expr, tree catch_list) -{ - location_t loc = EXPR_LOCATION (try_expr); - - append_to_statement_list (do_begin_catch (), &catch_list); - append_to_statement_list (build_throw (NULL_TREE), &catch_list); - tree catch_tf_expr = build_stmt (loc, TRY_FINALLY_EXPR, catch_list, - do_end_catch (NULL_TREE)); - catch_list = build2 (CATCH_EXPR, void_type_node, NULL_TREE, - catch_tf_expr); - tree try_catch_expr = build_stmt (loc, TRY_CATCH_EXPR, try_expr, catch_list); - return try_catch_expr; -} - #include "gt-cp-except.h" diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index de79283..1f7526e 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -8170,9 +8170,17 @@ cp_parser_unary_expression (cp_parser *parser, cp_id_kind * pidk, /* Parse the operand. */ operand = cp_parser_sizeof_operand (parser, keyword); + /* Construct a location e.g. : + alignof (expr) + ^~~~~~~~~~~~~~ + with start == caret at the start of the "alignof"/"sizeof" + token, with the endpoint at the final closing paren. */ + location_t compound_loc + = make_location (start_loc, start_loc, parser->lexer); + if (TYPE_P (operand)) - ret = cxx_sizeof_or_alignof_type (operand, op, std_alignof, - true); + ret = cxx_sizeof_or_alignof_type (compound_loc, operand, op, + std_alignof, true); else { /* ISO C++ defines alignof only with types, not with @@ -8183,7 +8191,8 @@ cp_parser_unary_expression (cp_parser *parser, cp_id_kind * pidk, "ISO C++ does not allow %<alignof%> " "with a non-type"); - ret = cxx_sizeof_or_alignof_expr (operand, op, true); + ret = cxx_sizeof_or_alignof_expr (compound_loc, + operand, op, true); } /* For SIZEOF_EXPR, just issue diagnostics, but keep SIZEOF_EXPR with the original operand. */ @@ -8202,19 +8211,11 @@ cp_parser_unary_expression (cp_parser *parser, cp_id_kind * pidk, ret = build_min (SIZEOF_EXPR, size_type_node, operand); TREE_SIDE_EFFECTS (ret) = 0; TREE_READONLY (ret) = 1; + SET_EXPR_LOCATION (ret, compound_loc); } } - /* Construct a location e.g. : - alignof (expr) - ^~~~~~~~~~~~~~ - with start == caret at the start of the "alignof"/"sizeof" - token, with the endpoint at the final closing paren. */ - location_t compound_loc - = make_location (start_loc, start_loc, parser->lexer); - - cp_expr ret_expr (ret); - ret_expr.set_location (compound_loc); + cp_expr ret_expr (ret, compound_loc); ret_expr = ret_expr.maybe_add_location_wrapper (); return ret_expr; } @@ -26066,8 +26067,7 @@ cp_parser_throw_expression (cp_parser* parser) the end at the end of the final token we consumed. */ location_t combined_loc = make_location (start_loc, start_loc, parser->lexer); - expression = build_throw (expression); - protected_set_expr_location (expression, combined_loc); + expression = build_throw (combined_loc, expression); return expression; } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index fe6cfc2..e9cf46c 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -16400,11 +16400,13 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) expanded = make_argument_pack (expanded); if (TYPE_P (expanded)) - return cxx_sizeof_or_alignof_type (expanded, SIZEOF_EXPR, + return cxx_sizeof_or_alignof_type (input_location, + expanded, SIZEOF_EXPR, false, complain & tf_error); else - return cxx_sizeof_or_alignof_expr (expanded, SIZEOF_EXPR, + return cxx_sizeof_or_alignof_expr (input_location, + expanded, SIZEOF_EXPR, complain & tf_error); } else @@ -19194,10 +19196,12 @@ tsubst_copy_and_build (tree t, --c_inhibit_evaluation_warnings; } if (TYPE_P (op1)) - r = cxx_sizeof_or_alignof_type (op1, TREE_CODE (t), std_alignof, + r = cxx_sizeof_or_alignof_type (input_location, + op1, TREE_CODE (t), std_alignof, complain & tf_error); else - r = cxx_sizeof_or_alignof_expr (op1, TREE_CODE (t), + r = cxx_sizeof_or_alignof_expr (input_location, + op1, TREE_CODE (t), complain & tf_error); if (TREE_CODE (t) == SIZEOF_EXPR && r != error_mark_node) { @@ -19959,7 +19963,7 @@ tsubst_copy_and_build (tree t, case THROW_EXPR: RETURN (build_throw - (RECUR (TREE_OPERAND (t, 0)))); + (input_location, RECUR (TREE_OPERAND (t, 0)))); case CONSTRUCTOR: { diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 4261168..1d664af 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1429,15 +1429,19 @@ finish_handler_parms (tree decl, tree handler) if (CLASS_TYPE_P (orig_type)) { if (TYPE_POLYMORPHIC_P (orig_type)) - warning (OPT_Wcatch_value_, - "catching polymorphic type %q#T by value", orig_type); + warning_at (DECL_SOURCE_LOCATION (decl), + OPT_Wcatch_value_, + "catching polymorphic type %q#T by value", + orig_type); else if (warn_catch_value > 1) - warning (OPT_Wcatch_value_, - "catching type %q#T by value", orig_type); + warning_at (DECL_SOURCE_LOCATION (decl), + OPT_Wcatch_value_, + "catching type %q#T by value", orig_type); } else if (warn_catch_value > 2) - warning (OPT_Wcatch_value_, - "catching non-reference type %q#T", orig_type); + warning_at (DECL_SOURCE_LOCATION (decl), + OPT_Wcatch_value_, + "catching non-reference type %q#T", orig_type); } } HANDLER_TYPE (handler) = type; diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 669ca83..41ef896 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -1662,8 +1662,8 @@ compparms (const_tree parms1, const_tree parms2) SIZEOF_EXPR. */ tree -cxx_sizeof_or_alignof_type (tree type, enum tree_code op, bool std_alignof, - bool complain) +cxx_sizeof_or_alignof_type (location_t loc, tree type, enum tree_code op, + bool std_alignof, bool complain) { gcc_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR); if (type == error_mark_node) @@ -1674,7 +1674,7 @@ cxx_sizeof_or_alignof_type (tree type, enum tree_code op, bool std_alignof, { if (complain) { - pedwarn (input_location, OPT_Wpointer_arith, + pedwarn (loc, OPT_Wpointer_arith, "invalid application of %qs to a member function", OVL_OP_INFO (false, op)->name); return size_one_node; @@ -1701,10 +1701,11 @@ cxx_sizeof_or_alignof_type (tree type, enum tree_code op, bool std_alignof, TREE_READONLY (value) = 1; if (op == ALIGNOF_EXPR && std_alignof) ALIGNOF_EXPR_STD_P (value) = true; + SET_EXPR_LOCATION (value, loc); return value; } - return c_sizeof_or_alignof_type (input_location, complete_type (type), + return c_sizeof_or_alignof_type (loc, complete_type (type), op == SIZEOF_EXPR, std_alignof, complain); } @@ -1723,13 +1724,14 @@ cxx_sizeof_nowarn (tree type) else if (!COMPLETE_TYPE_P (type)) return size_zero_node; else - return cxx_sizeof_or_alignof_type (type, SIZEOF_EXPR, false, false); + return cxx_sizeof_or_alignof_type (input_location, type, + SIZEOF_EXPR, false, false); } /* Process a sizeof expression where the operand is an expression. */ static tree -cxx_sizeof_expr (tree e, tsubst_flags_t complain) +cxx_sizeof_expr (location_t loc, tree e, tsubst_flags_t complain) { if (e == error_mark_node) return error_mark_node; @@ -1739,10 +1741,12 @@ cxx_sizeof_expr (tree e, tsubst_flags_t complain) e = build_min (SIZEOF_EXPR, size_type_node, e); TREE_SIDE_EFFECTS (e) = 0; TREE_READONLY (e) = 1; + SET_EXPR_LOCATION (e, loc); return e; } + location_t e_loc = cp_expr_loc_or_loc (e, loc); STRIP_ANY_LOCATION_WRAPPER (e); /* To get the size of a static data member declared as an array of @@ -1757,8 +1761,9 @@ cxx_sizeof_expr (tree e, tsubst_flags_t complain) && (complain & tf_warning)) { auto_diagnostic_group d; - if (warning (OPT_Wsizeof_array_argument, "%<sizeof%> on array function " - "parameter %qE will return size of %qT", e, TREE_TYPE (e))) + if (warning_at (e_loc, OPT_Wsizeof_array_argument, + "%<sizeof%> on array function parameter %qE " + "will return size of %qT", e, TREE_TYPE (e))) inform (DECL_SOURCE_LOCATION (e), "declared here"); } @@ -1767,7 +1772,7 @@ cxx_sizeof_expr (tree e, tsubst_flags_t complain) if (bitfield_p (e)) { if (complain & tf_error) - error_at (cp_expr_loc_or_input_loc (e), + error_at (e_loc, "invalid application of %<sizeof%> to a bit-field"); else return error_mark_node; @@ -1776,9 +1781,8 @@ cxx_sizeof_expr (tree e, tsubst_flags_t complain) else if (is_overloaded_fn (e)) { if (complain & tf_error) - permerror (cp_expr_loc_or_input_loc (e), - "ISO C++ forbids applying %<sizeof%> to an expression " - "of function type"); + permerror (e_loc, "ISO C++ forbids applying %<sizeof%> to " + "an expression of function type"); else return error_mark_node; e = char_type_node; @@ -1786,7 +1790,7 @@ cxx_sizeof_expr (tree e, tsubst_flags_t complain) else if (type_unknown_p (e)) { if (complain & tf_error) - cxx_incomplete_type_error (e, TREE_TYPE (e)); + cxx_incomplete_type_error (e_loc, e, TREE_TYPE (e)); else return error_mark_node; e = char_type_node; @@ -1794,7 +1798,8 @@ cxx_sizeof_expr (tree e, tsubst_flags_t complain) else e = TREE_TYPE (e); - return cxx_sizeof_or_alignof_type (e, SIZEOF_EXPR, false, complain & tf_error); + return cxx_sizeof_or_alignof_type (loc, e, SIZEOF_EXPR, false, + complain & tf_error); } /* Implement the __alignof keyword: Return the minimum required @@ -1803,7 +1808,7 @@ cxx_sizeof_expr (tree e, tsubst_flags_t complain) "aligned" __attribute__ specification). */ static tree -cxx_alignof_expr (tree e, tsubst_flags_t complain) +cxx_alignof_expr (location_t loc, tree e, tsubst_flags_t complain) { tree t; @@ -1815,15 +1820,17 @@ cxx_alignof_expr (tree e, tsubst_flags_t complain) e = build_min (ALIGNOF_EXPR, size_type_node, e); TREE_SIDE_EFFECTS (e) = 0; TREE_READONLY (e) = 1; + SET_EXPR_LOCATION (e, loc); return e; } + location_t e_loc = cp_expr_loc_or_loc (e, loc); STRIP_ANY_LOCATION_WRAPPER (e); e = mark_type_use (e); - if (!verify_type_context (input_location, TCTX_ALIGNOF, TREE_TYPE (e), + if (!verify_type_context (loc, TCTX_ALIGNOF, TREE_TYPE (e), !(complain & tf_error))) { if (!(complain & tf_error)) @@ -1835,7 +1842,7 @@ cxx_alignof_expr (tree e, tsubst_flags_t complain) else if (bitfield_p (e)) { if (complain & tf_error) - error_at (cp_expr_loc_or_input_loc (e), + error_at (e_loc, "invalid application of %<__alignof%> to a bit-field"); else return error_mark_node; @@ -1847,9 +1854,8 @@ cxx_alignof_expr (tree e, tsubst_flags_t complain) else if (is_overloaded_fn (e)) { if (complain & tf_error) - permerror (cp_expr_loc_or_input_loc (e), - "ISO C++ forbids applying %<__alignof%> to an expression " - "of function type"); + permerror (e_loc, "ISO C++ forbids applying %<__alignof%> to " + "an expression of function type"); else return error_mark_node; if (TREE_CODE (e) == FUNCTION_DECL) @@ -1860,28 +1866,30 @@ cxx_alignof_expr (tree e, tsubst_flags_t complain) else if (type_unknown_p (e)) { if (complain & tf_error) - cxx_incomplete_type_error (e, TREE_TYPE (e)); + cxx_incomplete_type_error (e_loc, e, TREE_TYPE (e)); else return error_mark_node; t = size_one_node; } else - return cxx_sizeof_or_alignof_type (TREE_TYPE (e), ALIGNOF_EXPR, false, + return cxx_sizeof_or_alignof_type (loc, TREE_TYPE (e), + ALIGNOF_EXPR, false, complain & tf_error); - return fold_convert (size_type_node, t); + return fold_convert_loc (loc, size_type_node, t); } /* Process a sizeof or alignof expression E with code OP where the operand is an expression. */ tree -cxx_sizeof_or_alignof_expr (tree e, enum tree_code op, bool complain) +cxx_sizeof_or_alignof_expr (location_t loc, tree e, enum tree_code op, + bool complain) { if (op == SIZEOF_EXPR) - return cxx_sizeof_expr (e, complain? tf_warning_or_error : tf_none); + return cxx_sizeof_expr (loc, e, complain? tf_warning_or_error : tf_none); else - return cxx_alignof_expr (e, complain? tf_warning_or_error : tf_none); + return cxx_alignof_expr (loc, e, complain? tf_warning_or_error : tf_none); } /* Build a representation of an expression 'alignas(E).' Return the @@ -1905,7 +1913,8 @@ cxx_alignas_expr (tree e) alignas(type-id ), it shall have the same effect as alignas(alignof(type-id )). */ - return cxx_sizeof_or_alignof_type (e, ALIGNOF_EXPR, true, false); + return cxx_sizeof_or_alignof_type (input_location, + e, ALIGNOF_EXPR, true, false); /* If we reach this point, it means the alignas expression if of the form "alignas(assignment-expression)", so we should follow |