[Bug c++/35147] ICE trying to expand an argument pack with zero arguments

dgregor at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Thu Feb 14 21:39:00 GMT 2008



------- Comment #1 from dgregor at gcc dot gnu dot org  2008-02-14 21:38 -------
This code is actually ill-formed. The problem is here:

  bind(h, forward<Args...>(args...))

For N arguments, the second argument expands to:

  bind(h, forward<Args1, Args2, ..., ArgsN>(args1, args2, ..., argsN))

However, that's ill-formed because forward() accepts one template argument and
one function argument. We should have given a better error message when we try
to instantiate it with 0 arguments (instead, we crash).

The intent of the example is for the second argument to expand into "N"
different arguments:

  bind(h, forward<Args1>(args1), forward<Args2>(args2), ...,
forward<ArgsN>(argsN>)

That can be expressed like so:

  bind(h, forward<Args>(args)...)

With that change, and replacing "h" (a function) with "c" (the Callable
function object given to this function), this program runs.

Here is a simpler test case that produces the same compile-time failure without
including any C++0x headers:

template<typename _Tp>
  inline _Tp&& forward(_Tp&& __t) { return __t; }


void f(...);

template<typename... Args>
void g(Args&&... args)
{
  f(forward<Args...>(args...));
}

void h()
{
  g();
}


-- 

dgregor at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |dgregor at gcc dot gnu dot
                   |dot org                     |org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
           Keywords|                            |ice-on-invalid-code
   Last reconfirmed|0000-00-00 00:00:00         |2008-02-14 21:38:40
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35147



More information about the Gcc-bugs mailing list