+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.
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. */
{
/* 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;
--- /dev/null
+// 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);
+}