aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2018-06-18 20:38:44 -0400
committerJason Merrill <jason@gcc.gnu.org>2018-06-18 20:38:44 -0400
commit6bdfada421e21cbeb4cfb29b2566ac6075be463a (patch)
tree74cc71c125d772adebe67c6d5bb27461e03218ae
parentc0e11c6afb448b0a9423b62c86c207945a0f5335 (diff)
downloadgcc-6bdfada421e21cbeb4cfb29b2566ac6075be463a.zip
gcc-6bdfada421e21cbeb4cfb29b2566ac6075be463a.tar.gz
gcc-6bdfada421e21cbeb4cfb29b2566ac6075be463a.tar.bz2
tree.c (cp_expr_location): New.
* tree.c (cp_expr_location): New. * cp-tree.h (cp_expr_loc_or_loc): New. * call.c, cvt.c, constexpr.c, constraint.cc, cp-gimplify.c, decl.c, error.c, init.c, lex.c, parser.c, pt.c, semantics.c, typeck.c, typeck2.c: Use it instead of EXPR_LOC_OR_LOC. From-SVN: r261728
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/call.c20
-rw-r--r--gcc/cp/constexpr.c20
-rw-r--r--gcc/cp/constraint.cc4
-rw-r--r--gcc/cp/cp-gimplify.c4
-rw-r--r--gcc/cp/cp-tree.h16
-rw-r--r--gcc/cp/cvt.c12
-rw-r--r--gcc/cp/decl.c10
-rw-r--r--gcc/cp/error.c2
-rw-r--r--gcc/cp/init.c14
-rw-r--r--gcc/cp/lex.c2
-rw-r--r--gcc/cp/parser.c4
-rw-r--r--gcc/cp/pt.c30
-rw-r--r--gcc/cp/semantics.c4
-rw-r--r--gcc/cp/tree.c24
-rw-r--r--gcc/cp/typeck.c14
-rw-r--r--gcc/cp/typeck2.c6
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/lambda/lambda-variadic7.C4
18 files changed, 117 insertions, 79 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 3e3b610..7c903c5 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,11 @@
2018-06-18 Jason Merrill <jason@redhat.com>
+ * tree.c (cp_expr_location): New.
+ * cp-tree.h (cp_expr_loc_or_loc): New.
+ * call.c, cvt.c, constexpr.c, constraint.cc, cp-gimplify.c, decl.c,
+ error.c, init.c, lex.c, parser.c, pt.c, semantics.c, typeck.c,
+ typeck2.c: Use it instead of EXPR_LOC_OR_LOC.
+
* parser.c (cp_parser_lambda_expression): Use a range for
LAMBDA_EXPR_LOCATION.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index d222b41..e417590 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4025,7 +4025,7 @@ build_converted_constant_expr (tree type, tree expr, tsubst_flags_t complain)
conversion *conv;
void *p;
tree t;
- location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
+ location_t loc = cp_expr_loc_or_loc (expr, input_location);
if (error_operand_p (expr))
return error_mark_node;
@@ -5003,12 +5003,12 @@ build_conditional_expr_1 (location_t loc, tree arg1, tree arg2, tree arg3,
if (complain & tf_error)
{
if (VOID_TYPE_P (arg2_type))
- error_at (EXPR_LOC_OR_LOC (arg3, loc),
+ error_at (cp_expr_loc_or_loc (arg3, loc),
"second operand to the conditional operator "
"is of type %<void%>, but the third operand is "
"neither a throw-expression nor of type %<void%>");
else
- error_at (EXPR_LOC_OR_LOC (arg2, loc),
+ error_at (cp_expr_loc_or_loc (arg2, loc),
"third operand to the conditional operator "
"is of type %<void%>, but the second operand is "
"neither a throw-expression nor of type %<void%>");
@@ -6622,7 +6622,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
tree totype = convs->type;
diagnostic_t diag_kind;
int flags;
- location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
+ location_t loc = cp_expr_loc_or_loc (expr, input_location);
if (convs->bad_p && !(complain & tf_error))
return error_mark_node;
@@ -7127,7 +7127,7 @@ tree
convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain)
{
tree arg_type;
- location_t loc = EXPR_LOC_OR_LOC (arg, input_location);
+ location_t loc = cp_expr_loc_or_loc (arg, input_location);
/* [expr.call]
@@ -7434,7 +7434,7 @@ convert_for_arg_passing (tree type, tree val, tsubst_flags_t complain)
"argument of function call might be a candidate "
"for a format attribute");
}
- maybe_warn_parm_abi (type, EXPR_LOC_OR_LOC (val, input_location));
+ maybe_warn_parm_abi (type, cp_expr_loc_or_loc (val, input_location));
}
return val;
}
@@ -8228,7 +8228,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
tree type = TREE_TYPE (to);
tree as_base = CLASSTYPE_AS_BASE (type);
tree arg = argarray[1];
- location_t loc = EXPR_LOC_OR_LOC (arg, input_location);
+ location_t loc = cp_expr_loc_or_loc (arg, input_location);
if (is_really_empty_class (type))
{
@@ -8788,7 +8788,7 @@ build_cxx_call (tree fn, int nargs, tree *argarray,
tree fndecl;
/* Remember roughly where this call is. */
- location_t loc = EXPR_LOC_OR_LOC (fn, input_location);
+ location_t loc = cp_expr_loc_or_loc (fn, input_location);
fn = build_call_a (fn, nargs, argarray);
SET_EXPR_LOCATION (fn, loc);
@@ -10679,7 +10679,7 @@ perform_implicit_conversion_flags (tree type, tree expr,
{
conversion *conv;
void *p;
- location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
+ location_t loc = cp_expr_loc_or_loc (expr, input_location);
if (TYPE_REF_P (type))
expr = mark_lvalue_use (expr);
@@ -11013,7 +11013,7 @@ initialize_reference (tree type, tree expr,
{
conversion *conv;
void *p;
- location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
+ location_t loc = cp_expr_loc_or_loc (expr, input_location);
if (type == error_mark_node || error_operand_p (expr))
return error_mark_node;
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 4670076..0e6f357 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1412,7 +1412,7 @@ cxx_eval_internal_function (const constexpr_ctx *ctx, tree t,
default:
if (!ctx->quiet)
- error_at (EXPR_LOC_OR_LOC (t, input_location),
+ error_at (cp_expr_loc_or_loc (t, input_location),
"call to internal function %qE", t);
*non_constant_p = true;
return t;
@@ -1427,7 +1427,7 @@ cxx_eval_internal_function (const constexpr_ctx *ctx, tree t,
if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
{
- location_t loc = EXPR_LOC_OR_LOC (t, input_location);
+ location_t loc = cp_expr_loc_or_loc (t, input_location);
tree type = TREE_TYPE (TREE_TYPE (t));
tree result = fold_binary_loc (loc, opcode, type,
fold_convert_loc (loc, type, arg0),
@@ -1469,7 +1469,7 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
bool lval,
bool *non_constant_p, bool *overflow_p)
{
- location_t loc = EXPR_LOC_OR_LOC (t, input_location);
+ location_t loc = cp_expr_loc_or_loc (t, input_location);
tree fun = get_function_named_in_call (t);
constexpr_call new_call = { NULL, NULL, NULL, 0 };
bool depth_ok;
@@ -3981,7 +3981,7 @@ cxx_eval_loop_expr (const constexpr_ctx *ctx, tree t,
if (++count >= constexpr_loop_limit)
{
if (!ctx->quiet)
- error_at (EXPR_LOC_OR_LOC (t, input_location),
+ error_at (cp_expr_loc_or_loc (t, input_location),
"%<constexpr%> loop iteration count exceeds limit of %d "
"(use -fconstexpr-loop-limit= to increase the limit)",
constexpr_loop_limit);
@@ -4597,7 +4597,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
if (REINTERPRET_CAST_P (t))
{
if (!ctx->quiet)
- error_at (EXPR_LOC_OR_LOC (t, input_location),
+ error_at (cp_expr_loc_or_loc (t, input_location),
"a reinterpret_cast is not a constant expression");
*non_constant_p = true;
return t;
@@ -4634,7 +4634,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
if (TYPE_REF_P (type))
{
if (!ctx->quiet)
- error_at (EXPR_LOC_OR_LOC (t, input_location),
+ error_at (cp_expr_loc_or_loc (t, input_location),
"dereferencing a null pointer");
*non_constant_p = true;
return t;
@@ -4646,7 +4646,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
if (!can_convert (type, from, tf_none))
{
if (!ctx->quiet)
- error_at (EXPR_LOC_OR_LOC (t, input_location),
+ error_at (cp_expr_loc_or_loc (t, input_location),
"conversion of %qT null pointer to %qT "
"is not a constant expression",
from, type);
@@ -4661,7 +4661,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
reinterpret_cast<void*>(sizeof 0)
*/
if (!ctx->quiet)
- error_at (EXPR_LOC_OR_LOC (t, input_location),
+ error_at (cp_expr_loc_or_loc (t, input_location),
"%<reinterpret_cast<%T>(%E)%> is not "
"a constant expression",
type, op);
@@ -4726,7 +4726,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
case BASELINK:
case OFFSET_REF:
if (!ctx->quiet)
- error_at (EXPR_LOC_OR_LOC (t, input_location),
+ error_at (cp_expr_loc_or_loc (t, input_location),
"expression %qE is not a constant expression", t);
*non_constant_p = true;
break;
@@ -5327,7 +5327,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
return false;
if (t == NULL_TREE)
return true;
- location_t loc = EXPR_LOC_OR_LOC (t, input_location);
+ location_t loc = cp_expr_loc_or_loc (t, input_location);
if (TREE_THIS_VOLATILE (t) && !DECL_P (t))
{
if (flags & tf_error)
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 37eded1..9f9fb52 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -804,7 +804,7 @@ check_for_logical_overloads (tree t)
if (DECL_OVERLOADED_OPERATOR_P (fn))
{
- location_t loc = EXPR_LOC_OR_LOC (t, input_location);
+ location_t loc = cp_expr_loc_or_loc (t, input_location);
error_at (loc, "constraint %qE, uses overloaded operator", t);
return true;
}
@@ -2012,7 +2012,7 @@ satisfy_predicate_constraint (tree t, tree args,
tree type = cv_unqualified (TREE_TYPE (expr));
if (!same_type_p (type, boolean_type_node))
{
- error_at (EXPR_LOC_OR_LOC (expr, input_location),
+ error_at (cp_expr_loc_or_loc (expr, input_location),
"constraint %qE does not have type %qT",
expr, boolean_type_node);
return boolean_false_node;
diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 4567365..16831fc 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -217,7 +217,7 @@ genericize_cp_loop (tree *stmt_p, location_t start_locus, tree cond, tree body,
{
/* If COND is constant, don't bother building an exit. If it's false,
we won't build a loop. If it's true, any exits are in the body. */
- location_t cloc = EXPR_LOC_OR_LOC (cond, start_locus);
+ location_t cloc = cp_expr_loc_or_loc (cond, start_locus);
exit = build1_loc (cloc, GOTO_EXPR, void_type_node,
get_bc_label (bc_break));
exit = fold_build3_loc (cloc, COND_EXPR, void_type_node, cond,
@@ -579,7 +579,7 @@ int
cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
{
int saved_stmts_are_full_exprs_p = 0;
- location_t loc = EXPR_LOC_OR_LOC (*expr_p, input_location);
+ location_t loc = cp_expr_loc_or_loc (*expr_p, input_location);
enum tree_code code = TREE_CODE (*expr_p);
enum gimplify_status ret;
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index b870954..ba6cc1a 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -47,6 +47,8 @@ c-common.h, not after.
but not all node kinds do (e.g. constants, and references to
params, locals, etc), so we stash a copy here. */
+extern location_t cp_expr_location (const_tree);
+
class cp_expr
{
public:
@@ -54,7 +56,7 @@ public:
m_value (NULL), m_loc (UNKNOWN_LOCATION) {}
cp_expr (tree value) :
- m_value (value), m_loc (EXPR_LOCATION (m_value)) {}
+ m_value (value), m_loc (cp_expr_location (m_value)) {}
cp_expr (tree value, location_t loc):
m_value (value), m_loc (loc) {}
@@ -7317,11 +7319,21 @@ extern tree finish_binary_fold_expr (tree, tree, int);
extern void require_complete_eh_spec_types (tree, tree);
extern void cxx_incomplete_type_diagnostic (location_t, const_tree,
const_tree, diagnostic_t);
+
+inline location_t
+cp_expr_loc_or_loc (const_tree t, location_t or_loc)
+{
+ location_t loc = cp_expr_location (t);
+ if (loc == UNKNOWN_LOCATION)
+ loc = or_loc;
+ return loc;
+}
+
inline void
cxx_incomplete_type_diagnostic (const_tree value, const_tree type,
diagnostic_t diag_kind)
{
- cxx_incomplete_type_diagnostic (EXPR_LOC_OR_LOC (value, input_location),
+ cxx_incomplete_type_diagnostic (cp_expr_loc_or_loc (value, input_location),
value, type, diag_kind);
}
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index bca9d05..da98414 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -77,7 +77,7 @@ cp_convert_to_pointer (tree type, tree expr, bool dofold,
tree intype = TREE_TYPE (expr);
enum tree_code form;
tree rval;
- location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
+ location_t loc = cp_expr_loc_or_loc (expr, input_location);
if (intype == error_mark_node)
return error_mark_node;
@@ -419,7 +419,7 @@ convert_to_reference (tree reftype, tree expr, int convtype,
tree rval = NULL_TREE;
tree rval_as_conversion = NULL_TREE;
bool can_convert_intype_to_type;
- location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
+ location_t loc = cp_expr_loc_or_loc (expr, input_location);
if (TREE_CODE (type) == FUNCTION_TYPE
&& TREE_TYPE (expr) == unknown_type_node)
@@ -667,7 +667,7 @@ cp_convert_and_check (tree type, tree expr, tsubst_flags_t complain)
folded_result = fold_simple (folded_result);
if (!TREE_OVERFLOW_P (folded)
&& folded_result != error_mark_node)
- warnings_for_convert_and_check (EXPR_LOC_OR_LOC (expr, input_location),
+ warnings_for_convert_and_check (cp_expr_loc_or_loc (expr, input_location),
type, folded, folded_result);
}
@@ -686,7 +686,7 @@ ocp_convert (tree type, tree expr, int convtype, int flags,
enum tree_code code = TREE_CODE (type);
const char *invalid_conv_diag;
tree e1;
- location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
+ location_t loc = cp_expr_loc_or_loc (expr, input_location);
bool dofold = (convtype & CONV_FOLD);
if (error_operand_p (e) || type == error_mark_node)
@@ -1001,7 +1001,7 @@ maybe_warn_nodiscard (tree expr, impl_conv_void implicit)
tree call = expr;
if (TREE_CODE (expr) == TARGET_EXPR)
call = TARGET_EXPR_INITIAL (expr);
- location_t loc = EXPR_LOC_OR_LOC (call, input_location);
+ location_t loc = cp_expr_loc_or_loc (call, input_location);
tree callee = cp_get_callee (call);
if (!callee)
return;
@@ -1078,7 +1078,7 @@ maybe_warn_nodiscard (tree expr, impl_conv_void implicit)
tree
convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
{
- location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
+ location_t loc = cp_expr_loc_or_loc (expr, input_location);
if (expr == error_mark_node
|| TREE_TYPE (expr) == error_mark_node)
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 6d802c9..90714cce 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -3480,7 +3480,7 @@ pop_switch (void)
location_t switch_location;
/* Emit warnings as needed. */
- switch_location = EXPR_LOC_OR_LOC (cs->switch_stmt, input_location);
+ switch_location = cp_expr_loc_or_loc (cs->switch_stmt, input_location);
const bool bool_cond_p
= (SWITCH_STMT_TYPE (cs->switch_stmt)
&& TREE_CODE (SWITCH_STMT_TYPE (cs->switch_stmt)) == BOOLEAN_TYPE);
@@ -5410,7 +5410,7 @@ maybe_deduce_size_from_array_init (tree decl, tree init)
do_default);
if (failure == 1)
{
- error_at (EXPR_LOC_OR_LOC (initializer,
+ error_at (cp_expr_loc_or_loc (initializer,
DECL_SOURCE_LOCATION (decl)),
"initializer fails to determine size of %qD", decl);
}
@@ -6266,7 +6266,7 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
}
else if (init_len != 1 && TREE_CODE (type) != COMPLEX_TYPE)
{
- error_at (EXPR_LOC_OR_LOC (init, DECL_SOURCE_LOCATION (decl)),
+ error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
"scalar object %qD requires one element in "
"initializer", decl);
TREE_TYPE (decl) = error_mark_node;
@@ -6311,7 +6311,7 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
{
/* Don't reshape if the class has constructors. */
if (cxx_dialect == cxx98)
- error_at (EXPR_LOC_OR_LOC (init, DECL_SOURCE_LOCATION (decl)),
+ error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
"in C++98 %qD must be initialized by "
"constructor, not by %<{...}%>",
decl);
@@ -6407,7 +6407,7 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
&& DECL_INITIAL (decl)
&& TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
&& PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
- warning_at (EXPR_LOC_OR_LOC (DECL_INITIAL (decl),
+ warning_at (cp_expr_loc_or_loc (DECL_INITIAL (decl),
DECL_SOURCE_LOCATION (decl)),
0, "array %qD initialized by parenthesized "
"string literal %qE",
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index f567c52..6a26113 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -3031,7 +3031,7 @@ location_of (tree t)
return DECL_SOURCE_LOCATION (t);
if (TREE_CODE (t) == DEFAULT_ARG)
return defarg_location (t);
- return EXPR_LOC_OR_LOC (t, input_location);
+ return cp_expr_loc_or_loc (t, input_location);
}
/* Now the interfaces from error et al to dump_type et al. Each takes an
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index acf9c9b..57697d6 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -553,7 +553,7 @@ get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain)
{
init = DECL_INITIAL (DECL_TI_TEMPLATE (member));
location_t expr_loc
- = EXPR_LOC_OR_LOC (init, DECL_SOURCE_LOCATION (member));
+ = cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (member));
tree *slot;
if (TREE_CODE (init) == DEFAULT_ARG)
/* Unparsed. */;
@@ -742,7 +742,7 @@ maybe_warn_list_ctor (tree member, tree init)
if (!begin)
return;
- location_t loc = EXPR_LOC_OR_LOC (init, input_location);
+ location_t loc = cp_expr_loc_or_loc (init, input_location);
warning_at (loc, OPT_Winit_list_lifetime,
"initializing %qD from %qE does not extend the lifetime "
"of the underlying array", member, begin);
@@ -1740,7 +1740,7 @@ build_aggr_init (tree exp, tree init, int flags, tsubst_flags_t complain)
return error_mark_node;
location_t init_loc = (init
- ? EXPR_LOC_OR_LOC (init, input_location)
+ ? cp_expr_loc_or_loc (init, input_location)
: location_of (exp));
TREE_READONLY (exp) = 0;
@@ -2571,7 +2571,7 @@ find_flexarray_init (tree t, tree init)
static void
warn_placement_new_too_small (tree type, tree nelts, tree size, tree oper)
{
- location_t loc = EXPR_LOC_OR_LOC (oper, input_location);
+ location_t loc = cp_expr_loc_or_loc (oper, input_location);
/* The number of bytes to add to or subtract from the size of the provided
buffer based on an offset into an array or an array element reference.
@@ -2963,7 +2963,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
{
if (complain & tf_error)
{
- error_at (EXPR_LOC_OR_LOC (inner_nelts, input_location),
+ error_at (cp_expr_loc_or_loc (inner_nelts, input_location),
"array size in new-expression must be constant");
cxx_constant_value(inner_nelts);
}
@@ -2992,7 +2992,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
{
if (complain & tf_warning_or_error)
{
- pedwarn (EXPR_LOC_OR_LOC (outer_nelts, input_location), OPT_Wvla,
+ pedwarn (cp_expr_loc_or_loc (outer_nelts, input_location), OPT_Wvla,
typedef_variant_p (orig_type)
? G_("non-constant array new length must be specified "
"directly, not by typedef")
@@ -4109,7 +4109,7 @@ build_vec_init (tree base, tree maxindex, tree init,
tree obase = base;
bool xvalue = false;
bool errors = false;
- location_t loc = (init ? EXPR_LOC_OR_LOC (init, input_location)
+ location_t loc = (init ? cp_expr_loc_or_loc (init, input_location)
: location_of (base));
if (TREE_CODE (atype) == ARRAY_TYPE && TYPE_DOMAIN (atype))
diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c
index 4d30eb5..c47ae1dd 100644
--- a/gcc/cp/lex.c
+++ b/gcc/cp/lex.c
@@ -491,7 +491,7 @@ tree
unqualified_name_lookup_error (tree name, location_t loc)
{
if (loc == UNKNOWN_LOCATION)
- loc = EXPR_LOC_OR_LOC (name, input_location);
+ loc = cp_expr_loc_or_loc (name, input_location);
if (IDENTIFIER_ANY_OP_P (name))
error_at (loc, "%qD not defined", name);
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index ae9267e..c6206fc 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -22350,7 +22350,7 @@ cp_parser_initializer_list (cp_parser* parser, bool* non_constant_p)
{
if (IDENTIFIER_MARKED (designator))
{
- error_at (EXPR_LOC_OR_LOC (val, input_location),
+ error_at (cp_expr_loc_or_loc (val, input_location),
"%<.%s%> designator used multiple times in "
"the same initializer list",
IDENTIFIER_POINTER (designator));
@@ -34812,7 +34812,7 @@ cp_parser_omp_for_cond (cp_parser *parser, tree decl)
|| CLASS_TYPE_P (TREE_TYPE (decl))))
return cond;
- return build_x_binary_op (EXPR_LOC_OR_LOC (cond, input_location),
+ return build_x_binary_op (cp_expr_loc_or_loc (cond, input_location),
TREE_CODE (cond),
TREE_OPERAND (cond, 0), ERROR_MARK,
TREE_OPERAND (cond, 1), ERROR_MARK,
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index b783b5e..1ecc6fb 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -4058,7 +4058,7 @@ check_for_bare_parameter_packs (tree t, location_t loc /* = UNKNOWN_LOCATION */)
if (parameter_packs)
{
if (loc == UNKNOWN_LOCATION)
- loc = EXPR_LOC_OR_LOC (t, input_location);
+ loc = cp_expr_loc_or_loc (t, input_location);
error_at (loc, "parameter packs not expanded with %<...%>:");
while (parameter_packs)
{
@@ -6297,7 +6297,7 @@ static bool
check_valid_ptrmem_cst_expr (tree type, tree expr,
tsubst_flags_t complain)
{
- location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
+ location_t loc = cp_expr_loc_or_loc (expr, input_location);
tree orig_expr = expr;
STRIP_NOPS (expr);
if (null_ptr_cst_p (expr))
@@ -6516,7 +6516,7 @@ unify_arg_conversion (bool explain_p, tree to_type,
tree from_type, tree arg)
{
if (explain_p)
- inform (EXPR_LOC_OR_LOC (arg, input_location),
+ inform (cp_expr_loc_or_loc (arg, input_location),
" cannot convert %qE (type %qT) to type %qT",
arg, from_type, to_type);
return unify_invalid (explain_p);
@@ -6593,7 +6593,7 @@ static tree
convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
{
tree expr_type;
- location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
+ location_t loc = cp_expr_loc_or_loc (expr, input_location);
tree orig_expr = expr;
/* Detect immediately string literals as invalid non-type argument.
@@ -16580,8 +16580,8 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
return t;
loc = input_location;
- if (EXPR_HAS_LOCATION (t))
- input_location = EXPR_LOCATION (t);
+ if (location_t eloc = cp_expr_location (t))
+ input_location = eloc;
if (STATEMENT_CODE_P (TREE_CODE (t)))
current_stmt_tree ()->stmts_are_full_exprs_p = STMT_IS_FULL_EXPR_P (t);
@@ -17693,8 +17693,8 @@ tsubst_copy_and_build (tree t,
return t;
loc = input_location;
- if (EXPR_HAS_LOCATION (t))
- input_location = EXPR_LOCATION (t);
+ if (location_t eloc = cp_expr_location (t))
+ input_location = eloc;
/* N3276 decltype magic only applies to calls at the top level or on the
right side of a comma. */
@@ -18351,10 +18351,10 @@ tsubst_copy_and_build (tree t,
bool diag = true;
if (in_lambda)
- error_at (EXPR_LOC_OR_LOC (t, input_location),
+ error_at (cp_expr_loc_or_loc (t, input_location),
msg, function);
else
- diag = permerror (EXPR_LOC_OR_LOC (t, input_location),
+ diag = permerror (cp_expr_loc_or_loc (t, input_location),
msg, function);
if (diag)
{
@@ -18369,7 +18369,7 @@ tsubst_copy_and_build (tree t,
/* Can't say anything more. */;
else if (DECL_CLASS_SCOPE_P (fn))
{
- location_t loc = EXPR_LOC_OR_LOC (t,
+ location_t loc = cp_expr_loc_or_loc (t,
input_location);
inform (loc,
"declarations in dependent base %qT are "
@@ -18425,13 +18425,13 @@ tsubst_copy_and_build (tree t,
gcc_assert (nargs == 1);
if (vec_safe_length (call_args) != 1)
{
- error_at (EXPR_LOC_OR_LOC (t, input_location),
+ error_at (cp_expr_loc_or_loc (t, input_location),
"wrong number of arguments to "
"%<__builtin_launder%>");
ret = error_mark_node;
}
else
- ret = finish_builtin_launder (EXPR_LOC_OR_LOC (t,
+ ret = finish_builtin_launder (cp_expr_loc_or_loc (t,
input_location),
(*call_args)[0], complain);
break;
@@ -23590,7 +23590,7 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain)
else if (!(added = !fns->add (fn)))
{
/* If hash_set::add returns true, the element was already there. */
- location_t loc = EXPR_LOC_OR_LOC (DEFERRED_NOEXCEPT_PATTERN (noex),
+ location_t loc = cp_expr_loc_or_loc (DEFERRED_NOEXCEPT_PATTERN (noex),
DECL_SOURCE_LOCATION (fn));
error_at (loc,
"exception specification of %qD depends on itself",
@@ -25780,7 +25780,7 @@ resolve_typename_type (tree type, bool only_current_p)
[temp.names]: In a qualified-id of a declarator-id, the keyword
template shall not appear at the top level. */
- pedwarn (EXPR_LOC_OR_LOC (fullname, input_location), OPT_Wpedantic,
+ pedwarn (cp_expr_loc_or_loc (fullname, input_location), OPT_Wpedantic,
"keyword %<template%> not allowed in declarator-id");
tmpl = decl;
}
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 5579189..2356940 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -658,7 +658,7 @@ maybe_convert_cond (tree cond)
&& !TREE_NO_WARNING (cond)
&& warn_parentheses)
{
- warning_at (EXPR_LOC_OR_LOC (cond, input_location), OPT_Wparentheses,
+ warning_at (cp_expr_loc_or_loc (cond, input_location), OPT_Wparentheses,
"suggest parentheses around assignment used as truth value");
TREE_NO_WARNING (cond) = 1;
}
@@ -2382,7 +2382,7 @@ finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
|| any_type_dependent_arguments_p (*args))
{
result = build_min_nt_call_vec (orig_fn, *args);
- SET_EXPR_LOCATION (result, EXPR_LOC_OR_LOC (fn, input_location));
+ SET_EXPR_LOCATION (result, cp_expr_loc_or_loc (fn, input_location));
KOENIG_LOOKUP_P (result) = koenig_p;
if (is_overloaded_fn (fn))
{
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index a88481d..4e91dbb 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -479,8 +479,8 @@ build_target_expr (tree decl, tree value, tsubst_flags_t complain)
return error_mark_node;
}
t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE);
- if (EXPR_HAS_LOCATION (value))
- SET_EXPR_LOCATION (t, EXPR_LOCATION (value));
+ if (location_t eloc = cp_expr_location (value))
+ SET_EXPR_LOCATION (t, eloc);
/* We always set TREE_SIDE_EFFECTS so that expand_expr does not
ignore the TARGET_EXPR. If there really turn out to be no
side-effects, then the optimizer should be able to get rid of
@@ -5454,6 +5454,26 @@ cp_tree_code_length (enum tree_code code)
}
}
+/* Like EXPR_LOCATION, but also handle some tcc_exceptional that have
+ locations. */
+
+location_t
+cp_expr_location (const_tree t_)
+{
+ tree t = CONST_CAST_TREE (t_);
+ if (t == NULL_TREE)
+ return UNKNOWN_LOCATION;
+ switch (TREE_CODE (t))
+ {
+ case LAMBDA_EXPR:
+ return LAMBDA_EXPR_LOCATION (t);
+ case STATIC_ASSERT:
+ return STATIC_ASSERT_SOURCE_LOCATION (t);
+ default:
+ return EXPR_LOCATION (t);
+ }
+}
+
/* Implement -Wzero_as_null_pointer_constant. Return true if the
conditions for the warning hold, false otherwise. */
bool
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index b033afd..936de9f 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -1990,7 +1990,7 @@ decay_conversion (tree exp,
{
tree type;
enum tree_code code;
- location_t loc = EXPR_LOC_OR_LOC (exp, input_location);
+ location_t loc = cp_expr_loc_or_loc (exp, input_location);
type = TREE_TYPE (exp);
if (type == error_mark_node)
@@ -2254,7 +2254,7 @@ static tree
rationalize_conditional_expr (enum tree_code code, tree t,
tsubst_flags_t complain)
{
- location_t loc = EXPR_LOC_OR_LOC (t, input_location);
+ location_t loc = cp_expr_loc_or_loc (t, input_location);
/* For MIN_EXPR or MAX_EXPR, fold-const.c has arranged things so that
the first operand is always the one to be used if both operands
@@ -6041,7 +6041,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, bool noconvert,
{
/* No default_conversion here. It causes trouble for ADDR_EXPR. */
tree arg = xarg;
- location_t location = EXPR_LOC_OR_LOC (arg, input_location);
+ location_t location = cp_expr_loc_or_loc (arg, input_location);
tree argtype = 0;
const char *errstring = NULL;
tree val;
@@ -6593,7 +6593,7 @@ build_x_compound_expr_from_list (tree list, expr_list_kind exp,
&& !CONSTRUCTOR_IS_DIRECT_INIT (expr))
{
if (complain & tf_error)
- pedwarn (EXPR_LOC_OR_LOC (expr, input_location), 0,
+ pedwarn (cp_expr_loc_or_loc (expr, input_location), 0,
"list-initializer for non-class type must not "
"be parenthesized");
else
@@ -8802,7 +8802,7 @@ convert_for_assignment (tree type, tree rhs,
}
else if (fndecl)
{
- error_at (EXPR_LOC_OR_LOC (rhs, input_location),
+ error_at (cp_expr_loc_or_loc (rhs, input_location),
"cannot convert %qH to %qI",
rhstype, type);
inform (get_fndecl_argument_location (fndecl, parmnum),
@@ -8904,7 +8904,7 @@ convert_for_assignment (tree type, tree rhs,
&& TREE_CODE (TREE_TYPE (rhs)) != BOOLEAN_TYPE
&& (complain & tf_warning))
{
- location_t loc = EXPR_LOC_OR_LOC (rhs, input_location);
+ location_t loc = cp_expr_loc_or_loc (rhs, input_location);
warning_at (loc, OPT_Wparentheses,
"suggest parentheses around assignment used as truth value");
@@ -9016,7 +9016,7 @@ maybe_warn_about_returning_address_of_local (tree retval)
{
tree valtype = TREE_TYPE (DECL_RESULT (current_function_decl));
tree whats_returned = fold_for_warn (retval);
- location_t loc = EXPR_LOC_OR_LOC (retval, input_location);
+ location_t loc = cp_expr_loc_or_loc (retval, input_location);
for (;;)
{
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 40233e6..ca87b43 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -959,7 +959,7 @@ check_narrowing (tree type, tree init, tsubst_flags_t complain)
if (!ok)
{
- location_t loc = EXPR_LOC_OR_LOC (init, input_location);
+ location_t loc = cp_expr_loc_or_loc (init, input_location);
if (cxx_dialect == cxx98)
{
if (complain & tf_warning)
@@ -1032,7 +1032,7 @@ digest_init_r (tree type, tree init, int nested, int flags,
if (TREE_CODE (init) == NON_LVALUE_EXPR)
init = TREE_OPERAND (init, 0);
- location_t loc = EXPR_LOC_OR_LOC (init, input_location);
+ location_t loc = cp_expr_loc_or_loc (init, input_location);
/* Initialization of an array of chars from a string constant. The initializer
can be optionally enclosed in braces, but reshape_init has already removed
@@ -1293,7 +1293,7 @@ process_init_constructor_array (tree type, tree init, int nested,
if (nested == 2 && !domain && !vec_safe_is_empty (v))
{
if (complain & tf_error)
- error_at (EXPR_LOC_OR_LOC (init, input_location),
+ error_at (cp_expr_loc_or_loc (init, input_location),
"initialization of flexible array member "
"in a nested context");
return PICFLAG_ERRONEOUS;
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-variadic7.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-variadic7.C
index c5355b0..c8ed0f6 100644
--- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-variadic7.C
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-variadic7.C
@@ -4,9 +4,9 @@
template<typename ... Args>
static void foo()
{
- [](Args, int x) {
+ [](Args, int x) { // { dg-error "packs not expanded" }
x;
- }; // { dg-error "packs not expanded" }
+ };
}
int main()
{