]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix PR c++/66786 (ICE with nested lambdas in variable template)
authorPatrick Palka <ppalka@gcc.gnu.org>
Sat, 5 Mar 2016 01:59:04 +0000 (01:59 +0000)
committerPatrick Palka <ppalka@gcc.gnu.org>
Sat, 5 Mar 2016 01:59:04 +0000 (01:59 +0000)
gcc/cp/ChangeLog:

PR c++/66786
* pt.c (template_class_depth): Given a lambda type, iterate
into its LAMBDA_TYPE_EXTRA_SCOPE field instead of its
TYPE_CONTEXT.  Given a VAR_DECL, iterate into its
CP_DECL_CONTEXT.

gcc/testsuite/ChangeLog:

PR c++/66786
* g++.dg/cpp1y/var-templ48.C: New test.
* g++.dg/cpp1y/var-templ49.C: New test.

From-SVN: r233997

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1y/var-templ48.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/var-templ49.C [new file with mode: 0644]

index f4c8744eb60ebf1ae8fdb875bcea8315210da743..0ef1ac744addbcd85988c029fd8a08ab9ca098d6 100644 (file)
@@ -1,3 +1,11 @@
+2016-03-05  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR c++/66786
+       * pt.c (template_class_depth): Given a lambda type, iterate
+       into its LAMBDA_TYPE_EXTRA_SCOPE field instead of its
+       TYPE_CONTEXT.  Given a VAR_DECL, iterate into its
+       CP_DECL_CONTEXT.
+
 2016-03-04  Jason Merrill  <jason@redhat.com>
 
        PR c++/69203
index e8cd7367f5635058098fae553730b2dcc01fbc33..f6dd75a89aadcf9abfa113b59f2f4a171018fe80 100644 (file)
@@ -370,16 +370,20 @@ template_class_depth (tree type)
 {
   int depth;
 
-  for (depth = 0;
-       type && TREE_CODE (type) != NAMESPACE_DECL;
-       type = (TREE_CODE (type) == FUNCTION_DECL)
-        ? CP_DECL_CONTEXT (type) : CP_TYPE_CONTEXT (type))
+  for (depth = 0; type && TREE_CODE (type) != NAMESPACE_DECL; )
     {
       tree tinfo = get_template_info (type);
 
       if (tinfo && PRIMARY_TEMPLATE_P (TI_TEMPLATE (tinfo))
          && uses_template_parms (INNERMOST_TEMPLATE_ARGS (TI_ARGS (tinfo))))
        ++depth;
+
+      if (VAR_OR_FUNCTION_DECL_P (type))
+       type = CP_DECL_CONTEXT (type);
+      else if (LAMBDA_TYPE_P (type))
+       type = LAMBDA_TYPE_EXTRA_SCOPE (type);
+      else
+       type = CP_TYPE_CONTEXT (type);
     }
 
   return depth;
index 03ee5293700d5b8e82190652f498bac7dbd571ab..ca65abf63389416fb7b69ffed45beb7034aa1a9c 100644 (file)
@@ -1,3 +1,9 @@
+2016-03-05  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR c++/66786
+       * g++.dg/cpp1y/var-templ48.C: New test.
+       * g++.dg/cpp1y/var-templ49.C: New test.
+
 2016-03-04  Eric Botcazou  <ebotcazou@adacore.com>
 
        * g++.dg/Wno-frame-address.C: Skip on IA-64.
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ48.C b/gcc/testsuite/g++.dg/cpp1y/var-templ48.C
new file mode 100644 (file)
index 0000000..f0c7693
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c++/66786
+// { dg-do compile { target c++14 } }
+
+template <typename... T> auto list = [](T... xs) { [=](auto f) { f(xs...); }; };
+int main() { list<int>(0); }
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ49.C b/gcc/testsuite/g++.dg/cpp1y/var-templ49.C
new file mode 100644 (file)
index 0000000..7ac5744
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/66786
+// { dg-do compile { target c++14 } }
+
+int f (int, bool);
+
+template <typename>
+auto list = [](auto... xs) { return [=](auto f, auto... ys) { return f(xs..., ys...); }; };
+
+const int &a = list<int>(0)(f, true);