re PR c++/58063 (default arguments evaluated twice per call)
authorJason Merrill <jason@redhat.com>
Tue, 16 Jun 2015 19:29:09 +0000 (15:29 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 16 Jun 2015 19:29:09 +0000 (15:29 -0400)
PR c++/58063
* tree.c (bot_manip): Remap SAVE_EXPR.

From-SVN: r224533

gcc/cp/ChangeLog
gcc/cp/tree.c
gcc/testsuite/g++.dg/overload/defarg10.C [new file with mode: 0644]

index 1ab5e8f2c3f3fe4e49f3f7cedec1d22fe70a1ded..5c85c5d152425d8f5113575282a3b1e5509f3626 100644 (file)
@@ -1,5 +1,8 @@
 2015-06-16  Jason Merrill  <jason@redhat.com>
 
+       PR c++/58063
+       * tree.c (bot_manip): Remap SAVE_EXPR.
+
        PR c++/66387
        * pt.c (tsubst_copy) [VAR_DECL]: Use process_outer_var_ref.
 
index 3553d7c2c9d73690e40107de9cf84c05521b6f32..a52e6f4367f4b53cc52c14f396d543125ac9880f 100644 (file)
@@ -2423,6 +2423,29 @@ bot_manip (tree* tp, int* walk_subtrees, void* data)
       *walk_subtrees = 0;
       return NULL_TREE;
     }
+  if (TREE_CODE (*tp) == SAVE_EXPR)
+    {
+      t = *tp;
+      splay_tree_node n = splay_tree_lookup (target_remap,
+                                            (splay_tree_key) t);
+      if (n)
+       {
+         *tp = (tree)n->value;
+         *walk_subtrees = 0;
+       }
+      else
+       {
+         copy_tree_r (tp, walk_subtrees, NULL);
+         splay_tree_insert (target_remap,
+                            (splay_tree_key)t,
+                            (splay_tree_value)*tp);
+         /* Make sure we don't remap an already-remapped SAVE_EXPR.  */
+         splay_tree_insert (target_remap,
+                            (splay_tree_key)*tp,
+                            (splay_tree_value)*tp);
+       }
+      return NULL_TREE;
+    }
 
   /* Make a copy of this node.  */
   t = copy_tree_r (tp, walk_subtrees, NULL);
diff --git a/gcc/testsuite/g++.dg/overload/defarg10.C b/gcc/testsuite/g++.dg/overload/defarg10.C
new file mode 100644 (file)
index 0000000..b8275d6
--- /dev/null
@@ -0,0 +1,28 @@
+// PR c++/58063
+// { dg-do run }
+
+struct basic_ios
+{
+  bool operator!() const { return false; }
+};
+
+struct ostream : virtual basic_ios
+{
+};
+
+int i;
+
+ostream& operator<<(ostream& os, const char* s) {
+  ++i;
+  return os;
+}
+
+ostream cout;
+
+void f(bool x = !(cout << "hi!\n")) { }
+
+int main() {
+  f();
+  if (i != 1)
+    __builtin_abort();
+}