Variadic template argument output - weird bug and segfault in recent clang

The following snipped code displays an error message and the subsequent segfault with both clang 5.0.0 and the current master branch. It compiles fine with any C ++ 11 g ++ compatible.

#include <initializer_list>

template <typename... T> struct B {};
template <typename T> struct gf {};
template <typename... A> B<A...> make_B(std::initializer_list<gf<A...>> const &V) { return {}; }

int main() {
  auto x = gf<int>{};
  auto b = make_B<int>({x, x, x}); // clang segfault
  //auto b = make_B({x, x, x}); // ok
}

Error message reads

test.cpp:5:26: error: too many template arguments for class template 'gf'
template <typename... A> B<A...> make_B(std::initializer_list<gf<A...>> const &V) { return {}; }
                                               ^
test.cpp:9:12: note: in instantiation of function template specialization 'make_B<int>' 
requested here
  auto b = make_B<int>({x, x, x}); // clang crash
                  ^
test.cpp:4:30: note: template is declared here
template <typename T> struct gf {};
  • Why is clang reporting an error here? The number of template arguments deduced for gfin the call make_B<int>should be as follows.

  • Regarding segfault after the error message, I now filed an error report

+6
source share

All Articles