From patchwork Wed Feb 13 18:12:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: C++ PATCH for c++/55720 (link error with lambda conversion) Date: Wed, 13 Feb 2013 08:12:09 -0000 From: Jason Merrill X-Patchwork-Id: 220223 Message-Id: <511BD779.2090404@redhat.com> To: gcc-patches List Most of the G++ linkage code really needs to be torn out in favor of just using cgraph. Until that happens, we need to set TREE_USED here so that decl_needed_p will return true and allow cgraph to consider the function. Tested x86_64-pc-linux-gnu, applying to trunk and 4.7. commit 701e03d86ffb5c36e1c907e84b8b0dc504ebe5b2 Author: Jason Merrill Date: Wed Feb 13 12:52:51 2013 -0500 PR c++/55720 * semantics.c (maybe_add_lambda_conv_op): Mark static thunk TREE_USED. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 46c2e64..95158a5 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -9559,6 +9559,8 @@ maybe_add_lambda_conv_op (tree type) body = begin_function_body (); compound_stmt = begin_compound_stmt (0); + /* decl_needed_p needs to see that it's used. */ + TREE_USED (statfn) = 1; finish_return_stmt (decay_conversion (statfn, tf_warning_or_error)); finish_compound_stmt (compound_stmt); diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv7.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv7.C new file mode 100644 index 0000000..861c91c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv7.C @@ -0,0 +1,20 @@ +// PR c++/55720 +// { dg-do link { target c++11 } } + +template +struct X { + static void (*code) (); +}; + +template +void (*X::code) () = []{}; // Line 7 + +struct Y { + void (*code) () = []{} ; // Line 10 + void operator()() { code(); } +}; + +int main () { + X::code(); + Y()(); +}