Variadic deduction guide not taken by g++, taken by clang++ - who is correct?

前端 未结 1 2028
挽巷
挽巷 2020-11-27 23:01

Consider the following code:

template 
struct list
{
    template 
    list(Args...) 
    {
        static_a         


        
相关标签:
1条回答
  • 2020-11-27 23:24

    This is gcc bug 80871. The issue is, we end up with this set of candidates for deduction:

    template <class... Types, class... Args>
    list<Types...> __f(Args... ); // constructor
    
    template <class... Args>
    list<Args...>  __f(Args... ); // deduction-guide
    

    Both are valid (Types... can deduce as empty in the first case), but the call here should be ambiguous - neither is more specialized than the other. Types... does not participate in ordering here (similar to the example in [temp.deduct.partial]/12). So the correct behavior is to proceed to the next tiebreaker, which favors deduction-guides. Hence, this should be a list<int, double, char>.

    However, gcc's behavior is to favor the constructor, hence the static_assert triggers becuase Types... would indeed be empty in that situation.

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