]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/55710 ([C++11] Linkage errors with lambdas)
authorJason Merrill <jason@redhat.com>
Fri, 15 Feb 2013 18:31:52 +0000 (13:31 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 15 Feb 2013 18:31:52 +0000 (13:31 -0500)
PR c++/55710
* semantics.c (maybe_add_lambda_conv_op): Mark static thunk
TREE_USED.

From-SVN: r196086

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv7.C [new file with mode: 0644]

index bd1d17ef2c9bf2fa469e01b82233dd5e12f1f2a8..794cc153d03f8cb80939a485d83d5ddaa3ce5744 100644 (file)
@@ -1,5 +1,9 @@
 2013-02-15  Jason Merrill  <jason@redhat.com>
 
+       PR c++/55710
+       * semantics.c (maybe_add_lambda_conv_op): Mark static thunk
+       TREE_USED.
+
        PR c++/56135
        * pt.c (tsubst_copy_and_build): Don't forget any new
        captures that arose from use of dependent names.
index da0b48faed17f4f4f2781499eb9415d963cf9cc7..13ea6a5c97634e108b4e07c9c97567fa5a60ec35 100644 (file)
@@ -9410,6 +9410,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));
 
   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 (file)
index 0000000..89e4e4b
--- /dev/null
@@ -0,0 +1,20 @@
+// PR c++/55710
+// { dg-do link { target c++11 } }
+
+template <class T>
+struct X {
+  static void (*code) ();
+};
+
+template <class T>
+void (*X<T>::code) () = []{};  // Line 7
+
+struct Y {
+  void (*code) () = []{} ; // Line 10
+  void operator()() { code(); }
+};
+
+int main () {
+  X<int>::code();
+  Y()();
+}