Multiple SFINAE class template specialisations using void_t

后端 未结 2 1439
-上瘾入骨i
-上瘾入骨i 2020-12-10 10:45

Are multiple class template specialisations valid, when each is distinct only between patterns involving template parameters in non-deduced contexts?

A common exampl

2条回答
  •  情深已故
    2020-12-10 11:30

    There is a rule that partial specializations have to be more specialized than the primary template - both of your specializations follow that rule. But there isn't a rule that states that partial specializations can never be ambiguous. It's more that - if instantiation leads to ambiguous specialization, the program is ill-formed. But that ambiguous instantiation has to happen first!

    It appears that clang is suffering from CWG 1558 here and is overly eager about substituting in void for std::void_t.

    This is CWG 1980 almost exactly:

    In an example like

    template using X = T;
    template X f();
    template X f();
    

    it appears that the second declaration of f is a redeclaration of the first but distinguishable by SFINAE, i.e., equivalent but not functionally equivalent.

    If you use the non-alias implementation of void_t:

    template  struct make_void { using type = void; };
    template  using void_t = typename make_void::type;
    

    then clang allows the two different specializations. Sure, instantiating has_members on a type that has both type1 and type2 typedefs errors, but that's expected.

提交回复
热议问题