格式错误的调用的零长度可变参数扩展

zero length variadic expansion of ill-formed call

标准大师的问题。

试图回应 another question,我开始怀疑代码的格式是否正确。

据我所知,以下代码格式不正确

int main ()
 {
   std::tuple<>  a;

   std::get<0>(a);
 }

因为当 tstd::tuple<Ts...> 时,对 std::get<I>(t) 的调用在 I 超出范围 [0, sizeof...(Ts)[ 时格式错误。

在这种情况下 sizeof...(Ts) 为零,因此范围 [0, 0[ 为空,因此 std::get<I>(a) 对于每个索引 I.

但是当 std::get<I>(a) 通过一个空的可变参数包展开时?

我的意思是:下面的代码

#include <tuple>

template <typename ... Args>
void bar (Args const & ...)
 { }

template <std::size_t ... I>
void foo ()
 {
   std::tuple<> a;

   bar( std::get<I>(a) ... );
 }

int main ()
 {
   foo<>();
 }

使用格式错误的 (?) 调用 (std::get<I>(a)) 但零时间可变参数扩展(sizeof...(I) 为零),格式正确还是格式错误?

[temp.res]/8:

The program is ill-formed, no diagnostic required, if:

  • [...]
  • every valid specialization of a variadic template requires an empty template parameter pack, or
  • [...]