diff mbox

C++ PATCH for c++/56947

Message ID 53889F15.9020808@redhat.com
State New
Headers show

Commit Message

Jason Merrill May 30, 2014, 3:09 p.m. UTC
Here the change to look up static/const vars from the enclosing context 
of a lambda again at instantiation time was breaking on 4.7 because we 
weren't instantiating the lambda op() until EOF.  Fixed this way in 4.7; 
in later versions we already instantiate it early as part of the 
TAG_DEFN.  Added the testcase and an assert to the trunk.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.7.
diff mbox

Patch

commit 86b12872ec09b670b9be689d5c87c245b1745941
Author: Jason Merrill <jason@redhat.com>
Date:   Thu May 29 17:22:36 2014 -0400

    	PR c++/56947
    	* pt.c (instantiate_decl): Check that defer_ok is not set for
    	local class members.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index a24e044..0d22fae 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -19696,6 +19696,11 @@  instantiate_decl (tree d, int defer_ok,
   if (external_p && !always_instantiate_p (d))
     return d;
 
+  /* Any local class members should be instantiated from the TAG_DEFN
+     with defer_ok == 0.  */
+  gcc_checking_assert (!defer_ok || !decl_function_context (d)
+		       || LAMBDA_TYPE_P (DECL_CONTEXT (d)));
+
   gen_tmpl = most_general_template (tmpl);
   gen_args = DECL_TI_ARGS (d);
 
diff --git a/gcc/testsuite/g++.dg/template/local8.C b/gcc/testsuite/g++.dg/template/local8.C
new file mode 100644
index 0000000..006bd8c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/local8.C
@@ -0,0 +1,18 @@ 
+// PR c++/56947
+
+struct A
+{
+    A (int);
+};
+
+template < typename >
+void Fn ()
+{
+    const int kCapacity = 0;
+    struct Q:A
+    {
+        Q ():A (kCapacity) { }
+    };
+    Q q;
+}
+template void Fn < int >();