Is there a compiler bug exposed by my implementation of an is_complete type trait?

后端 未结 1 1793
难免孤独
难免孤独 2020-11-28 13:20

I wrote this C++11 trait template to check whether a type is complete:

template 
using void_t = void;

template 

        
相关标签:
1条回答
  • 2020-11-28 14:12

    The problem appears to be with the definition of void_t. Defining it as

    template<typename... Ts>
    struct make_void { typedef void type;};
    
    template<typename... Ts>
    using void_t = typename make_void<Ts...>::type;
    

    instead yields the correct result (10) on both compilers (Demo).

    I believe this is the same issue noted in section 2.3 of N3911, the paper proposing void_t, and CWG issue 1558. Essentially, the standard was unclear whether unused arguments in alias template specializations could result in substitution failure or are simply ignored. The resolution of the CWG issue, adopted at the Committee's November 2014 meeting, clarifies that the shorter definition of void_t in the question should work, and GCC 5.0 implements the resolution.

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