Compiler discrepencies in deduction of template parameter of nested alias template

寵の児 提交于 2021-02-08 14:47:29

问题


Consider the following code snippet where we we're trying to deduce the template parameter to the function foobar():

struct Bar { static constexpr auto size = 5; };

template <class T, class=std::make_index_sequence<T::size>>
struct FooList;
template <class T, std::size_t... Idxs>
struct FooList<T, std::integer_sequence<std::size_t, Idxs...>> { };

struct Wrapper {
  template <class T>
  using list_type = FooList<T>;
};

template <class T>
void foobar(typename Wrapper::template list_type<T>) { }

void test() { 
  foobar(FooList<Bar>{});
}

The major compiler frontends disagree on whether this should compile (see this godbolt). If we give the template parameter explicitly, like this:

void test_explicit() { 
  foobar<Bar>(FooList<Bar>{});
}

all of the major frontends compile the code successfully (godbolt). Interestingly, if we make the deduction simpler:

struct Bar { };

struct Wrapper {
  template <class T>
  using my_type = T;
};

template <class T>
void foobar(typename Wrapper::template my_type<T>) { }

void test() { 
  foobar(Bar{});
}

a different subset of the frontends compile and fail to compile (MSVC being the only one that compiles both, see this godbolt).

Which implementation is conforming here, and which are buggy (and why)? Can anyone find the portion of the C++ standard that specifies how this should work?

来源:https://stackoverflow.com/questions/57206006/compiler-discrepencies-in-deduction-of-template-parameter-of-nested-alias-templa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!