PR c++/50970
authoramker <amker@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 25 Sep 2012 06:37:29 +0000 (06:37 +0000)
committeramker <amker@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 25 Sep 2012 06:37:29 +0000 (06:37 +0000)
* typeck.c (cp_build_binary_op): Check side effects before generating
pfn and delta related expressions.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@191692 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/typeck.c

index c03f66a..ba1f775 100644 (file)
@@ -1,3 +1,9 @@
+2012-09-25  Zhenqiang Chen <zhenqiang.chen@linaro.org>
+
+       PR c++/50970
+       * typeck.c (cp_build_binary_op): Check side effects before generating
+       pfn and delta related expressions.
+
 2012-09-24  Lawrence Crowl  <crowl@google.com>
 
        * init.c (build_new_1): Change to new double_int API.
index ad4b090..884f7d0 100644 (file)
@@ -4159,18 +4159,23 @@ cp_build_binary_op (location_t location,
          if (TARGET_PTRMEMFUNC_VBIT_LOCATION
              == ptrmemfunc_vbit_in_delta)
            {
-             tree pfn0 = pfn_from_ptrmemfunc (op0);
-             tree delta0 = delta_from_ptrmemfunc (op0);
-             tree e1 = cp_build_binary_op (location,
-                                           EQ_EXPR,
-                                           pfn0,       
-                                           build_zero_cst (TREE_TYPE (pfn0)),
-                                           complain);
-             tree e2 = cp_build_binary_op (location,
-                                           BIT_AND_EXPR, 
-                                           delta0,
-                                           integer_one_node,
-                                           complain);
+             tree pfn0, delta0, e1, e2;
+
+             if (TREE_SIDE_EFFECTS (op0))
+               op0 = save_expr (op0);
+
+             pfn0 = pfn_from_ptrmemfunc (op0);
+             delta0 = delta_from_ptrmemfunc (op0);
+             e1 = cp_build_binary_op (location,
+                                      EQ_EXPR,
+                                      pfn0,
+                                      build_zero_cst (TREE_TYPE (pfn0)),
+                                      complain);
+             e2 = cp_build_binary_op (location,
+                                      BIT_AND_EXPR,
+                                      delta0,
+                                      integer_one_node,
+                                      complain);
              
              if ((complain & tf_warning)
                  && c_inhibit_evaluation_warnings == 0