diff options
author | Jason Merrill <jason@redhat.com> | 2014-05-19 14:41:24 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2014-05-19 14:41:24 -0400 |
commit | 0f5b01358db7cce3cc3d224edd63ef8e8c9838a9 (patch) | |
tree | 45a497289f59024303bdeb0203c9cfaecad002ee /gcc | |
parent | 7fb80849cb4af6c1f90c2464a38f2b20a8e3d0fb (diff) | |
download | gcc-0f5b01358db7cce3cc3d224edd63ef8e8c9838a9.zip gcc-0f5b01358db7cce3cc3d224edd63ef8e8c9838a9.tar.gz gcc-0f5b01358db7cce3cc3d224edd63ef8e8c9838a9.tar.bz2 |
re PR c++/58761 (ICE with a lambda capturing this in a NSDMI)
PR c++/58761
* pt.c (tsubst_copy): Don't check at_function_scope_p.
(instantiate_class_template_1): Don't push_to_top_level in an nsdmi.
From-SVN: r210624
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/pt.c | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi6.C | 23 |
3 files changed, 33 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1b0916c..822f79b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2014-05-19 Jason Merrill <jason@redhat.com> + + PR c++/58761 + * pt.c (tsubst_copy): Don't check at_function_scope_p. + (instantiate_class_template_1): Don't push_to_top_level in an nsdmi. + 2014-05-19 Paolo Carlini <paolo.carlini@oracle.com> * typeck2.c (cxx_incomplete_type_diagnostic): Use inform. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index c9eddb8..d712583 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -8942,6 +8942,9 @@ instantiate_class_template_1 (tree type) push_deferring_access_checks (dk_no_deferred); fn_context = decl_function_context (TYPE_MAIN_DECL (type)); + /* Also avoid push_to_top_level for a lambda in an NSDMI. */ + if (!fn_context && LAMBDA_TYPE_P (type) && TYPE_CLASS_SCOPE_P (type)) + fn_context = error_mark_node; if (!fn_context) push_to_top_level (); /* Use #pragma pack from the template context. */ @@ -12531,7 +12534,7 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) { /* We get here for a use of 'this' in an NSDMI. */ if (DECL_NAME (t) == this_identifier - && at_function_scope_p () + && current_function_decl && DECL_CONSTRUCTOR_P (current_function_decl)) return current_class_ptr; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi6.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi6.C new file mode 100644 index 0000000..98cdbce --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nsdmi6.C @@ -0,0 +1,23 @@ +// PR c++/58761 +// { dg-do compile { target c++11 } } + +template <class T> +struct X +{ + int x = 42; + int y = [this](){return this->x;}(); +}; + +template <class T> +struct Y +{ + int x = 42; + int y = [this](){return this->x;}(); + Y(int) {} +}; + +int main() +{ + X<int> x; + Y<int> y(42); +} |