diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9b15f555687..3ce68e8e75c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2013-10-17 Paolo Carlini + + PR c++/58596 + * lambda.c (lambda_expr_this_capture): Handle NSDMIs in the + cp_unevaluated_operand case. + 2013-10-16 Jason Merrill * pt.c (apply_late_template_attributes): Use diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index 2ecb17cfe91..62812a50c85 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -628,7 +628,14 @@ lambda_expr_this_capture (tree lambda) /* In unevaluated context this isn't an odr-use, so just return the nearest 'this'. */ if (cp_unevaluated_operand) - return lookup_name (this_identifier); + { + /* In an NSDMI the fake 'this' pointer that we're using for + parsing is in scope_chain. */ + if (LAMBDA_EXPR_EXTRA_SCOPE (lambda) + && TREE_CODE (LAMBDA_EXPR_EXTRA_SCOPE (lambda)) == FIELD_DECL) + return scope_chain->x_current_class_ptr; + return lookup_name (this_identifier); + } /* Try to default capture 'this' if we can. */ if (!this_capture diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a3bd224b63d..4c6c320c540 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-10-17 Paolo Carlini + + PR c++/58596 + * g++.dg/cpp0x/lambda/lambda-nsdmi5.C: New + 2013-10-17 Kyrylo Tkachov * gcc.target/aarch64/c-output-template.c: New testcase. diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi5.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi5.C new file mode 100644 index 00000000000..1d2778fb5ac --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi5.C @@ -0,0 +1,7 @@ +// PR c++/58596 +// { dg-do compile { target c++11 } } + +struct A +{ + int i = [] { return decltype(i)(); }(); +};