aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/call.c7
-rw-r--r--gcc/cp/semantics.c3
3 files changed, 16 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index bfd898d..6554cb7 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2017-01-20 Marek Polacek <polacek@redhat.com>
+
+ PR c/64279
+ * call.c (build_conditional_expr_1): Warn about duplicated branches.
+ * semantics.c (finish_expr_stmt): Build statement using the proper
+ location.
+
2017-01-19 Jason Merrill <jason@redhat.com>
US 20 - forwarding references and class template argument deduction
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 0059a395..a78e1a9 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -5302,6 +5302,13 @@ build_conditional_expr_1 (location_t loc, tree arg1, tree arg2, tree arg3,
valid_operands:
result = build3_loc (loc, COND_EXPR, result_type, arg1, arg2, arg3);
+ /* If the ARG2 and ARG3 are the same and don't have side-effects,
+ warn here, because the COND_EXPR will be turned into ARG2. */
+ if (warn_duplicated_branches
+ && (arg2 == arg3 || operand_equal_p (arg2, arg3, 0)))
+ warning_at (EXPR_LOCATION (result), OPT_Wduplicated_branches,
+ "this condition has identical branches");
+
/* We can't use result_type below, as fold might have returned a
throw_expr. */
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 4202475..55710e6 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -670,6 +670,7 @@ tree
finish_expr_stmt (tree expr)
{
tree r = NULL_TREE;
+ location_t loc = EXPR_LOCATION (expr);
if (expr != NULL_TREE)
{
@@ -694,7 +695,7 @@ finish_expr_stmt (tree expr)
if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
{
if (TREE_CODE (expr) != EXPR_STMT)
- expr = build_stmt (input_location, EXPR_STMT, expr);
+ expr = build_stmt (loc, EXPR_STMT, expr);
expr = maybe_cleanup_point_expr_void (expr);
}