This failure was happening on all targets that don't use either CFI
assembler directives or asynchronous unwind tables: we were mistakenly
deciding that the _FUN thunk for returning from the lambda function
pointer conversion operator couldn't throw because build_call_a wasn't
setting cp_function_chain->can_throw. There seems to be no reason to
set that flag in build_cxx_call rather than build_call_a, so I've moved it.
Tested x86_64-pc-linux-gnu, applying to trunk. Will also apply to 4.6.2
once branch unfreezes.
commit 2d89beb80fa4656166d68c004d38b1087e8f12d5
Author: Jason Merrill <ja...@redhat.com>
Date: Wed Jun 22 10:48:16 2011 -0400
PR c++/49260
* call.c (build_call_a): Set cp_function_chain->can_throw here.
(build_cxx_call): Not here.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index dd4dced..cfaef7d 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -352,6 +352,9 @@ build_call_a (tree function, int n, tree *argarray)
nothrow = ((decl && TREE_NOTHROW (decl))
|| TYPE_NOTHROW_P (TREE_TYPE (TREE_TYPE (function))));
+ if (!nothrow && cfun && cp_function_chain)
+ cp_function_chain->can_throw = 1;
+
if (decl && TREE_THIS_VOLATILE (decl) && cfun && cp_function_chain)
current_function_returns_abnormally = 1;
@@ -6710,11 +6713,6 @@ build_cxx_call (tree fn, int nargs, tree *argarray)
/* If this call might throw an exception, note that fact. */
fndecl = get_callee_fndecl (fn);
- if ((!fndecl || !TREE_NOTHROW (fndecl))
- && at_function_scope_p ()
- && cfun
- && cp_function_chain)
- cp_function_chain->can_throw = 1;
/* Check that arguments to builtin functions match the expectations. */
if (fndecl
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-eh2.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-eh2.C
index 1490a25..0c94b55 100644
--- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-eh2.C
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-eh2.C
@@ -1,5 +1,6 @@
// PR c++/47263
-// { dg-options -std=c++0x }
+// PR c++/49260
+// { dg-options "-std=c++0x -fno-asynchronous-unwind-tables -fno-dwarf2-cfi-asm" }
// { dg-do run }
#include <exception>