template aliases and sfinae

后端 未结 1 1372
臣服心动
臣服心动 2020-12-17 17:32

In the case of a substitution failure involving a template alias (e.g. a template alias on a missing member typename, as in the code snippet below), should an error

相关标签:
1条回答
  • 2020-12-17 18:32

    According to the Standards, it is clearly GCC that is correct, because the alias template must immediately be replaced and then normal/usual SFINAE is applied to typename T::member_type later when T is known.

    But there currently is an issue for this, see http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1554.

    According to the meetings outcome, it appears that clangs behavior is desired: The substitution of T will be done in the context of the alias template (even though at the time of substitution in typename T::member_type, there is no reference to the alias template anymore - it will still need to be referenced as the source of where the parameter type pattern originated from, if this is how it's implemented).


    This is similar to another situation where patterns are thrown away on definition time that could influence instantiation semantics

    template<int I>
    void f(int x[I]);
    
    int main() {
      f<0>(nullptr);
    }
    

    In this case too, in my opinion the Standard normatively is clear that the parameter is immediately being replaced by int* and thus the instantiation works. See http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1322 .

    0 讨论(0)
提交回复
热议问题