https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65071

--- Comment #1 from Mikhail Maltsev <maltsevm at gmail dot com> ---
A few more comments. I wrote that GCC 5.0 segfaults. That's actually not true,
I could not reproduce segfault on checked builds (only release version of
4.9.2), but never the less it's still ICE.

So, here is a bit more minimized example:

$ cat ice_sizeof.cc
template<int> struct S { };

template<template<int> class... T, int N>
S<sizeof...(T)> foo(T<N>...);

auto x = foo(S<2>{});

==========================================

The problem occurs during name mangling. I defined
#define DEBUG_MANGLE 1
The debug output (before ICE happens) ends with this:

  identifier              : S
  ++ add_substitution (template_decl at 0x7fb804560100)
  ++ substitutions   S-1_ = foo (template_decl at 0x7fb804560400)
                     S0_ = S (template_decl at 0x7fb804560100)
  template-arg            : integer_cst              (0x7fb80441c570)
  type                    : integer_type             (0x7fb8043fe690)
  ++ find_substitution (integer_type at 0x7fb8043fe690)
  bare-function-type      : function_type            (0x7fb804552c78)
  type                    : record_type              (0x7fb804552930)
  ++ find_substitution (record_type at 0x7fb804552930)
  name                    : type_decl                (0x7fb80454e5f0)
  unscoped-template-name  : template_decl            (0x7fb804560100)
  ++ find_substitution (template_decl at 0x7fb804560100)
  substitution            :
  template-args           : tree_vec                 (0x7fb80455cca0)
  template-arg            : sizeof_expr              (0x7fb80455cc60)
  type                    : type_pack_expansion      (0x7fb804552888)
  ++ find_substitution (type_pack_expansion at 0x7fb804552888)
  type                    : template_decl            (0x7fb804560280)
  ++ find_substitution (template_decl at 0x7fb804560280)

If I understand correctly, tree_class_check fails when we attempt to mangle the
argument of sizeof...(T). It is (probably) represented through parameter pack
expansion (sizeof...(T) must have the same value as the number of parameters in
the pack "T<N>..."), which in turn depends on substitution of template template
parameter T. Template template parameters are represented using TEMPLATE_DECL:
...
  else if (code == TEMPLATE_DECL)
    /* A template appearing as a template arg is a template template arg. */
    write_template_template_arg (node);
...
And write_CV_qualifiers_for_type rejects it.

Reply via email to