From b216dc77133b17d5a4272b6a018977579daf75e5 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Tue, 3 Nov 2015 16:57:58 -0500
Subject: [PATCH 27/27] FIXME: more unary ops

---
 gcc/cp/cp-tree.h   |  4 ++--
 gcc/cp/parser.c    | 16 ++++++++++++++++
 gcc/cp/semantics.c | 11 ++++++++---
 gcc/cp/typeck.c    | 24 +++++++++++++++++++-----
 4 files changed, 45 insertions(+), 10 deletions(-)

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index b5bb2a0..9073a0c 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -6330,7 +6330,7 @@ extern cp_expr perform_koenig_lookup		(cp_expr, vec<tree, va_gc> *,
 extern tree finish_call_expr			(tree, vec<tree, va_gc> **, bool,
 						 bool, tsubst_flags_t);
 extern tree finish_template_variable		(tree, tsubst_flags_t = tf_warning_or_error);
-extern tree finish_increment_expr		(tree, enum tree_code);
+extern cp_expr finish_increment_expr		(cp_expr, enum tree_code);
 extern tree finish_this_expr			(void);
 extern tree finish_pseudo_destructor_expr       (tree, tree, tree, location_t);
 extern tree finish_unary_op_expr		(location_t, enum tree_code, cp_expr,
@@ -6609,7 +6609,7 @@ extern tree build_x_binary_op			(location_t,
 extern tree build_x_array_ref			(location_t, tree, tree,
 						 tsubst_flags_t);
 extern tree build_x_unary_op			(location_t,
-						 enum tree_code, tree,
+						 enum tree_code, cp_expr,
                                                  tsubst_flags_t);
 extern tree cp_build_addr_expr			(tree, tsubst_flags_t);
 extern tree cp_build_unary_op                   (enum tree_code, tree, int, 
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 1472d5d..3998552 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -6497,6 +6497,22 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
 							postfix_expression,
 							false,
 							decltype_p);
+#if 0
+          location_t close_square_loc = postfix_expression.get_location ();
+          source_range src_range;
+          src_range.m_start = start_loc;
+          src_range.m_finish = close_square_loc;
+#endif
+          postfix_expression.set_range (start_loc,
+                                        postfix_expression.get_location ());
+#if 0
+          location_t combined_loc = COMBINE_LOCATION_DATA (line_table,
+                                                           close_square_loc,
+                                                           src_range,
+                                                           NULL);
+          protected_set_expr_location (postfix_expression, combined_loc);
+#endif
+
 	  idk = CP_ID_KIND_NONE;
           is_member_access = false;
 	  break;
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index cf988c3..f5a7b1a 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2455,10 +2455,15 @@ finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
    is indicated by CODE, which should be POSTINCREMENT_EXPR or
    POSTDECREMENT_EXPR.)  */
 
-tree
-finish_increment_expr (tree expr, enum tree_code code)
+cp_expr
+finish_increment_expr (cp_expr expr, enum tree_code code)
 {
-  return build_x_unary_op (input_location, code, expr, tf_warning_or_error);
+  /* input_location holds the location of the trailing operator token.  */
+  cp_expr result = build_x_unary_op (input_location, code, expr,
+				     tf_warning_or_error);
+  result.set_range (expr.get_start (),
+		    get_range_from_loc (line_table, input_location).m_finish);
+  return result;
 }
 
 /* Finish a use of `this'.  Returns an expression for `this'.  */
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 483f493..07d4838 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -5255,7 +5255,7 @@ pointer_diff (tree op0, tree op1, tree ptrtype, tsubst_flags_t complain)
    and XARG is the operand.  */
 
 tree
-build_x_unary_op (location_t loc, enum tree_code code, tree xarg,
+build_x_unary_op (location_t loc, enum tree_code code, cp_expr xarg,
 		  tsubst_flags_t complain)
 {
   tree orig_expr = xarg;
@@ -5265,7 +5265,7 @@ build_x_unary_op (location_t loc, enum tree_code code, tree xarg,
   if (processing_template_decl)
     {
       if (type_dependent_expression_p (xarg))
-	return build_min_nt_loc (loc, code, xarg, NULL_TREE);
+	return build_min_nt_loc (loc, code, xarg.get_value (), NULL_TREE);
 
       xarg = build_non_dependent_expr (xarg);
     }
@@ -5300,7 +5300,7 @@ build_x_unary_op (location_t loc, enum tree_code code, tree xarg,
 		error (DECL_CONSTRUCTOR_P (fn)
 		       ? G_("taking address of constructor %qE")
 		       : G_("taking address of destructor %qE"),
-		       xarg);
+		       xarg.get_value ());
 	      return error_mark_node;
 	    }
 	}
@@ -5316,7 +5316,7 @@ build_x_unary_op (location_t loc, enum tree_code code, tree xarg,
 	      if (complain & tf_error)
 		{
 		  error ("invalid use of %qE to form a "
-			 "pointer-to-member-function", xarg);
+			 "pointer-to-member-function", xarg.get_value ());
 		  if (TREE_CODE (xarg) != OFFSET_REF)
 		    inform (input_location, "  a qualified-id is required");
 		}
@@ -5327,7 +5327,7 @@ build_x_unary_op (location_t loc, enum tree_code code, tree xarg,
 	      if (complain & tf_error)
 		error ("parentheses around %qE cannot be used to form a"
 		       " pointer-to-member-function",
-		       xarg);
+		       xarg.get_value ());
 	      else
 		return error_mark_node;
 	      PTRMEM_OK_P (xarg) = 1;
@@ -5358,6 +5358,20 @@ build_x_unary_op (location_t loc, enum tree_code code, tree xarg,
 			     /*For {PRE,POST}{INC,DEC}REMENT_EXPR*/NULL_TREE);
   if (TREE_CODE (exp) == ADDR_EXPR)
     PTRMEM_OK_P (exp) = ptrmem;
+
+  /* Update exp assuming a prefix operator at LOC.
+     TODO: This gets overwritten in finish_increment_expr for
+     postfix operators, which is rather clunky.  */
+  location_t pure_loc = get_pure_location (loc);
+  source_range src_range;
+  src_range.m_start = pure_loc;
+  src_range.m_finish = xarg.get_finish ();
+  location_t combined_loc = COMBINE_LOCATION_DATA (line_table,
+						   pure_loc,
+						   src_range,
+						   NULL);
+  protected_set_expr_location (exp, combined_loc);
+
   return exp;
 }
 
-- 
1.8.5.3

