Variadic template argument deduction - strange error and segfault in recent clang

Viewed 188

The following code-snipped produces an error message and a subsequent segfault with both clang 5.0.0 and the current master branch. It compiles fine with any c++11 compliant g++.

#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
}

The 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 does clang report an error here? The number of template arguments deduced for gf in the call to make_B<int> should be one.

  • Regarding the segfault following the error message I have now filed a bug report

0 Answers
Related