Patchwork C++ PATCH for c++/50424 (wrong code with throwing default argument)

login
register
mail settings
Submitter Jason Merrill
Date Sept. 16, 2011, 9:13 p.m.
Message ID <4E73BBF1.2050806@redhat.com>
Download mbox | patch
Permalink /patch/115061/
State New
Headers show

Comments

Jason Merrill - Sept. 16, 2011, 9:13 p.m.
We collect information about whether a function can throw as we compile 
the function: if we build up a call that can throw, then the current 
function can throw, too.  But we weren't doing the same for default 
arguments used in a call, which might themselves contain calls that can 
throw.

Tested x86_64-pc-linux-gnu, applying to trunk and a smaller patch to 4.6.

Patch

commit d4880772f234b9c86b0af79954ea88f2134fbaa4
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Sep 16 16:14:59 2011 -0400

    	PR c++/50424
    	* tree.c (bot_manip): Set cp_function_chain->can_throw.

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 1fa32a0..7e7b34b 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -1861,7 +1861,11 @@  bot_manip (tree* tp, int* walk_subtrees, void* data)
     }
 
   /* Make a copy of this node.  */
-  return copy_tree_r (tp, walk_subtrees, NULL);
+  t = copy_tree_r (tp, walk_subtrees, NULL);
+  if (TREE_CODE (*tp) == CALL_EXPR && !TREE_NOTHROW (*tp)
+      && cfun && cp_function_chain)
+    cp_function_chain->can_throw = 1;
+  return t;
 }
 
 /* Replace all remapped VAR_DECLs in T with their new equivalents.
diff --git a/gcc/testsuite/g++.dg/eh/defarg1.C b/gcc/testsuite/g++.dg/eh/defarg1.C
new file mode 100644
index 0000000..5c6e4df
--- /dev/null
+++ b/gcc/testsuite/g++.dg/eh/defarg1.C
@@ -0,0 +1,10 @@ 
+// PR c++/50424
+// { dg-do run }
+
+int f() { throw 1; }
+void g( int = f() ) { }
+void h() { g(); }
+int main()
+{
+  try { h(); } catch (int) { }
+}