From: Marek Polacek Date: Thu, 23 Apr 2015 13:21:22 +0000 (+0000) Subject: re PR c++/65727 (Segfault With Decltype In Lambda Expression Used To Initialize Stati... X-Git-Tag: releases/gcc-4.9.3~190 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b6f7ca079590efc665f220b09f4e1d4b6a51fc2;p=thirdparty%2Fgcc.git re PR c++/65727 (Segfault With Decltype In Lambda Expression Used To Initialize Static Class Member) PR c++/65727 * lambda.c (maybe_resolve_dummy): Handle null return. From-SVN: r222368 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 27fd9a9de024..1f029ad09e84 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2015-04-23 Marek Polacek + + PR c++/65727 + * lambda.c (maybe_resolve_dummy): Handle null return. + 2015-04-23 Jason Merrill PR c++/65695 diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index 6acbdd9ee2ba..7391dd9b1d1b 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -764,8 +764,9 @@ maybe_resolve_dummy (tree object) /* In a lambda, need to go through 'this' capture. */ tree lam = CLASSTYPE_LAMBDA_EXPR (current_class_type); tree cap = lambda_expr_this_capture (lam); - object = build_x_indirect_ref (EXPR_LOCATION (object), cap, - RO_NULL, tf_warning_or_error); + if (cap && cap != error_mark_node) + object = build_x_indirect_ref (EXPR_LOCATION (object), cap, + RO_NULL, tf_warning_or_error); } return object; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-decltype2.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-decltype2.C new file mode 100644 index 000000000000..51bf0ec33528 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-decltype2.C @@ -0,0 +1,25 @@ +// PR c++/65727 +// { dg-do compile { target c++11 } } + +struct type_a { void(*cb)(); }; + +struct type_b +{ + type_b(type_a p); + void dummy(); +}; + +template +constexpr T function_c(T**t) {return **t;} + +class type_d { + public: + static void dummy(); +}; +class type_e { + public: + static type_b b; + type_d *d[1]; +}; + +type_b type_e::b = {{[](){decltype(function_c(type_e::d))::dummy();}}}; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice3.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice3.C index 03a7a4bb60d0..09e046fbe852 100644 --- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice3.C +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice3.C @@ -3,7 +3,7 @@ class Klass { - unsigned int local; + unsigned int local; // { dg-message "" } public: bool dostuff(); }; @@ -11,7 +11,7 @@ public: bool Klass::dostuff() { auto f = []() -> bool { - if (local & 1) { return true; } // { dg-error "not captured" } + if (local & 1) { return true; } // { dg-error "" } return false; }; }