[Bug c++/66786] [5/6 Regression] ICE: Segmentation fault

2016-03-07 Thread ppalka at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66786

--- Comment #8 from Patrick Palka  ---
Author: ppalka
Date: Mon Mar  7 17:09:53 2016
New Revision: 234038

URL: https://gcc.gnu.org/viewcvs?rev=234038=gcc=rev
Log:
Adjust fix for PR c++/66786

gcc/cp/ChangeLog:

PR c++/66786
* pt.c (get_template_info): Handle PARM_DECL.
(template_class_depth): Check DECL_P instead of
VAR_OR_FUNCTION_DECL_P.


Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/pt.c

[Bug c++/66786] [5/6 Regression] ICE: Segmentation fault

2016-03-04 Thread ppalka at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66786

Patrick Palka  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #7 from Patrick Palka  ---
Fixed for GCC 6.

[Bug c++/66786] [5/6 Regression] ICE: Segmentation fault

2016-03-04 Thread ppalka at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66786

--- Comment #6 from Patrick Palka  ---
Author: ppalka
Date: Sat Mar  5 01:59:04 2016
New Revision: 233997

URL: https://gcc.gnu.org/viewcvs?rev=233997=gcc=rev
Log:
Fix PR c++/66786 (ICE with nested lambdas in variable template)

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.


Added:
trunk/gcc/testsuite/g++.dg/cpp1y/var-templ48.C
trunk/gcc/testsuite/g++.dg/cpp1y/var-templ49.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/pt.c
trunk/gcc/testsuite/ChangeLog

[Bug c++/66786] [5/6 Regression] ICE: Segmentation fault

2016-02-07 Thread ppalka at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66786

Patrick Palka  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
 CC||ppalka at gcc dot gnu.org
   Assignee|unassigned at gcc dot gnu.org  |ppalka at gcc dot 
gnu.org

--- Comment #4 from Patrick Palka  ---
Slightly more simplified test case:

  template  auto list = [](T... xs) { [=](auto f) { f(xs...); };
};
  int main() { list; }


The problem ultimately seems to lie in template_class_depth, which returns the
number of enclosing templates in which the given type or decl is embedded.


In particular, given the RECORD_TYPE that corresponds to the outermost lambda
in the above test case, template_class_depth returns 0 instead of 1 since the
TYPE_CONTEXT of this RECORD_TYPE is the file's TRANSLATION_UNIT_DECL and not
the VAR_DECL so template_class_depth never sees it.

That the TYPE_CONTEXT doesn't point to the enclosing VAR_DECL doesn't seem like
a bug because according to the documentation, the TYPE_CONTEXT (and
DECL_CONTEXT) of a tree is never expected to be a VAR_DECL.  It can be a
FUNCTION_DECL however, which explains why the following test case, which just
replaces the enclosing variable template with a function template, compiles
successfully (the TYPE_CONTEXT points to the enclosing FUNCTION_DECL and so
template_class_depth appropriately returns 1):

  template 
  auto
  list ()
  {
return [](T... xs) { [=](auto f) { f(xs...); }; }; 
  }

  int main() { list (); }

So I wonder how to make template_class_depth be aware of the given type's
enclosing variable template...

[Bug c++/66786] [5/6 Regression] ICE: Segmentation fault

2016-02-07 Thread ppalka at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66786

--- Comment #5 from Patrick Palka  ---
Looks like the field LAMBDA_TYPE_EXTRA_SCOPE has what we need.  I am testing
this patch:

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 4d405cf..5c344c1 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -369,16 +369,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;

[Bug c++/66786] [5/6 Regression] ICE: Segmentation fault

2016-01-26 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66786

Marek Polacek  changed:

   What|Removed |Added

 Status|ASSIGNED|NEW
   Assignee|mpolacek at gcc dot gnu.org|unassigned at gcc dot 
gnu.org

--- Comment #3 from Marek Polacek  ---
Unfortunately, I'll have to give up on this one.

What happens here is that we ICE because we have a lambda expr, whose
LAMBDA_EXPR_CAPTURE_LIST has null TREE_PURPOSE.

10272   /* We need to instantiate the capture list from the template
10273  after we've instantiated the closure members, but before we
10274  consider adding the conversion op.  Also keep any captures
10275  that may have been added during instantiation of the op(). 
*/
10276   tree tmpl_expr = CLASSTYPE_LAMBDA_EXPR (pattern);
10277   tree tmpl_cap
10278 = tsubst_copy_and_build (LAMBDA_EXPR_CAPTURE_LIST
(tmpl_expr),
10279  args, tf_warning_or_error,
NULL_TREE,
10280  false, false);
10281 
10282   LAMBDA_EXPR_CAPTURE_LIST (expr)
10283 = chainon (tmpl_cap, nreverse (LAMBDA_EXPR_CAPTURE_LIST
(expr)));

but tsubst_copy_and_build returns tmpl_cap without TREE_PURPOSE, because

16621 /* Expand the argument expressions.  */
16622 if (TREE_PURPOSE (t))
16623   purposevec = tsubst_pack_expansion (TREE_PURPOSE (t), args,
16624  complain, in_decl);

returns null.  That is probably because we end up calling
13898   /* Otherwise return the full NONTYPE_ARGUMENT_PACK that
13899  tsubst_decl put in the hash table.  */
13900   return retrieve_specialization (t, args, 0);

which is where the null originates.  Alas, this pt.c maze is something I can't
figure out, so unassigning :(.

[Bug c++/66786] [5/6 Regression] ICE: Segmentation fault

2016-01-19 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66786

Marek Polacek  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
 CC||mpolacek at gcc dot gnu.org
   Assignee|unassigned at gcc dot gnu.org  |mpolacek at gcc dot 
gnu.org

--- Comment #2 from Marek Polacek  ---
I'll have a look...

[Bug c++/66786] [5/6 Regression] ICE: Segmentation fault

2016-01-13 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66786

Richard Biener  changed:

   What|Removed |Added

   Keywords||ice-on-valid-code
   Priority|P3  |P2
   Target Milestone|6.0 |5.4

[Bug c++/66786] [5/6 Regression] ICE: Segmentation fault

2015-08-31 Thread trippels at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66786

Markus Trippelsdorf  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2015-08-31
 CC||jason at gcc dot gnu.org
Summary|[6 Regression] ICE: |[5/6 Regression] ICE:
   |Segmentation fault  |Segmentation fault
 Ever confirmed|0   |1

--- Comment #1 from Markus Trippelsdorf  ---
Started with r214396.