Hi,

this fixes the remaining bit of 44516 - the wrong location, thus caret position - in the obvious way, that is by passing from cp_parser_assignment_expression the right one to build_x_modify_expr via an additional location_t parameter. The latter can simply forward it to build_new_op.

Tested x86_64-linux.

Thanks,
Paolo.

//////////////////////
/cp
2012-05-14  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/44516
        * typeck.c (build_x_modify_expr): Add location_t parameter.
        * parser.c (cp_parser_assignment_expression, cp_parser_omp_for_loop):
        Adjust callers.
        * pt.c (tsubst_omp_for_iterator, tsubst_copy_and_build): Likewise.
        * semantics.c (handle_omp_for_class_iterator): Likewise.
        * cp-tree.h (build_x_modify_expr): Update.

/testsuite
2012-05-14  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/44516
        * g++.dg/parse/error49.C: New.
Index: testsuite/g++.dg/parse/error49.C
===================================================================
--- testsuite/g++.dg/parse/error49.C    (revision 0)
+++ testsuite/g++.dg/parse/error49.C    (revision 0)
@@ -0,0 +1,10 @@
+// PR c++/44516
+
+struct WebService {  };
+struct Server {  };
+
+void addHTTPService(Server const &server,
+                   WebService const *http)
+{
+  server += http; // { dg-error "10:no match for 'operator\\+='" }
+}
Index: cp/typeck.c
===================================================================
--- cp/typeck.c (revision 187435)
+++ cp/typeck.c (working copy)
@@ -7105,8 +7105,8 @@ cp_build_modify_expr (tree lhs, enum tree_code mod
 }
 
 tree
-build_x_modify_expr (tree lhs, enum tree_code modifycode, tree rhs,
-                    tsubst_flags_t complain)
+build_x_modify_expr (location_t loc, tree lhs, enum tree_code modifycode,
+                    tree rhs, tsubst_flags_t complain)
 {
   if (processing_template_decl)
     return build_min_nt (MODOP_EXPR, lhs,
@@ -7114,7 +7114,7 @@ tree
 
   if (modifycode != NOP_EXPR)
     {
-      tree rval = build_new_op (input_location, MODIFY_EXPR, LOOKUP_NORMAL,
+      tree rval = build_new_op (loc, MODIFY_EXPR, LOOKUP_NORMAL,
                                lhs, rhs, make_node (modifycode),
                                /*overload=*/NULL, complain);
       if (rval)
Index: cp/pt.c
===================================================================
--- cp/pt.c     (revision 187435)
+++ cp/pt.c     (working copy)
@@ -12672,7 +12672,8 @@ tsubst_omp_for_iterator (tree t, int i, tree declv
       cond = RECUR (TREE_VEC_ELT (OMP_FOR_COND (t), i));
       incr = TREE_VEC_ELT (OMP_FOR_INCR (t), i);
       if (TREE_CODE (incr) == MODIFY_EXPR)
-       incr = build_x_modify_expr (RECUR (TREE_OPERAND (incr, 0)), NOP_EXPR,
+       incr = build_x_modify_expr (input_location,
+                                   RECUR (TREE_OPERAND (incr, 0)), NOP_EXPR,
                                    RECUR (TREE_OPERAND (incr, 1)),
                                    complain);
       else
@@ -13692,7 +13693,8 @@ tsubst_copy_and_build (tree t,
     case MODOP_EXPR:
       {
        tree r = build_x_modify_expr
-         (RECUR (TREE_OPERAND (t, 0)),
+         (input_location,
+          RECUR (TREE_OPERAND (t, 0)),
           TREE_CODE (TREE_OPERAND (t, 1)),
           RECUR (TREE_OPERAND (t, 2)),
           complain);
Index: cp/semantics.c
===================================================================
--- cp/semantics.c      (revision 187435)
+++ cp/semantics.c      (working copy)
@@ -4520,7 +4520,8 @@ handle_omp_for_class_iterator (int i, location_t l
                incr = error_mark_node;
              else
                {
-                 iter_incr = build_x_modify_expr (iter, TREE_CODE (rhs),
+                 iter_incr = build_x_modify_expr (input_location,
+                                                  iter, TREE_CODE (rhs),
                                                   TREE_OPERAND (rhs, 1),
                                                   tf_warning_or_error);
                  if (error_operand_p (iter_incr))
@@ -4553,7 +4554,8 @@ handle_omp_for_class_iterator (int i, location_t l
                                                 tf_warning_or_error);
                  if (error_operand_p (iter_incr))
                    return true;
-                 iter_incr = build_x_modify_expr (iter, NOP_EXPR,
+                 iter_incr = build_x_modify_expr (input_location,
+                                                  iter, NOP_EXPR,
                                                   iter_incr,
                                                   tf_warning_or_error);
                  if (error_operand_p (iter_incr))
@@ -4604,18 +4606,22 @@ handle_omp_for_class_iterator (int i, location_t l
   if (orig_pre_body)
     add_stmt (orig_pre_body);
   if (init != NULL)
-    finish_expr_stmt (build_x_modify_expr (iter, NOP_EXPR, init,
+    finish_expr_stmt (build_x_modify_expr (input_location,
+                                          iter, NOP_EXPR, init,
                                           tf_warning_or_error));
   init = build_int_cst (TREE_TYPE (diff), 0);
   if (c && iter_incr == NULL)
     {
-      finish_expr_stmt (build_x_modify_expr (incr_var, NOP_EXPR,
+      finish_expr_stmt (build_x_modify_expr (input_location,
+                                            incr_var, NOP_EXPR,
                                             incr, tf_warning_or_error));
       incr = incr_var;
-      iter_incr = build_x_modify_expr (iter, PLUS_EXPR, incr,
+      iter_incr = build_x_modify_expr (input_location,
+                                      iter, PLUS_EXPR, incr,
                                       tf_warning_or_error);
     }
-  finish_expr_stmt (build_x_modify_expr (last, NOP_EXPR, init,
+  finish_expr_stmt (build_x_modify_expr (input_location,
+                                        last, NOP_EXPR, init,
                                         tf_warning_or_error));
   *pre_body = pop_stmt_list (*pre_body);
 
@@ -4628,11 +4634,13 @@ handle_omp_for_class_iterator (int i, location_t l
   orig_body = *body;
   *body = push_stmt_list ();
   iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last);
-  iter_init = build_x_modify_expr (iter, PLUS_EXPR, iter_init,
+  iter_init = build_x_modify_expr (input_location,
+                                  iter, PLUS_EXPR, iter_init,
                                   tf_warning_or_error);
   iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
   finish_expr_stmt (iter_init);
-  finish_expr_stmt (build_x_modify_expr (last, NOP_EXPR, decl,
+  finish_expr_stmt (build_x_modify_expr (input_location,
+                                        last, NOP_EXPR, decl,
                                         tf_warning_or_error));
   add_stmt (orig_body);
   *body = pop_stmt_list (*body);
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 187435)
+++ cp/parser.c (working copy)
@@ -7512,11 +7513,11 @@ cp_parser_assignment_expression (cp_parser* parser
        return cp_parser_question_colon_clause (parser, expr);
       else
        {
-         enum tree_code assignment_operator;
+         location_t loc = cp_lexer_peek_token (parser->lexer)->location;
 
          /* If it's an assignment-operator, we're using the second
             production.  */
-         assignment_operator
+         enum tree_code assignment_operator
            = cp_parser_assignment_operator_opt (parser);
          if (assignment_operator != ERROR_MARK)
            {
@@ -7534,7 +7535,7 @@ cp_parser_assignment_expression (cp_parser* parser
                                                              NIC_ASSIGNMENT))
                return error_mark_node;
              /* Build the assignment expression.  */
-             expr = build_x_modify_expr (expr,
+             expr = build_x_modify_expr (loc, expr,
                                          assignment_operator,
                                          rhs,
                                          tf_warning_or_error);
@@ -26350,7 +26356,8 @@ cp_parser_omp_for_loop (cp_parser *parser, tree cl
                  cp_parser_parse_definitely (parser);
                  cp_parser_require (parser, CPP_EQ, RT_EQ);
                  rhs = cp_parser_assignment_expression (parser, false, NULL);
-                 finish_expr_stmt (build_x_modify_expr (decl, NOP_EXPR,
+                 finish_expr_stmt (build_x_modify_expr (input_location,
+                                                        decl, NOP_EXPR,
                                                         rhs,
                                                         tf_warning_or_error));
                  add_private_clause = true;
Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h        (revision 187435)
+++ cp/cp-tree.h        (working copy)
@@ -5835,7 +5835,8 @@ extern tree build_reinterpret_cast                (tree, 
tree, t
 extern tree build_const_cast                   (tree, tree, tsubst_flags_t);
 extern tree build_c_cast                       (location_t, tree, tree);
 extern tree cp_build_c_cast                    (tree, tree, tsubst_flags_t);
-extern tree build_x_modify_expr                        (tree, enum tree_code, 
tree,
+extern tree build_x_modify_expr                        (location_t, tree,
+                                                enum tree_code, tree,
                                                 tsubst_flags_t);
 extern tree cp_build_modify_expr               (tree, enum tree_code, tree,
                                                 tsubst_flags_t);

Reply via email to