How is P0522R0 breaking code?

后端 未结 2 408
一生所求
一生所求 2020-12-01 23:53

Today I was reading the C++17 support page of clang. I\'ve notice something odd. The feature Matching template template parameters to compatible arguments (P0522R0)

2条回答
  •  再見小時候
    2020-12-02 00:26

    You can have code like this:

    template typename>
    struct Foo {};
    
    template
    struct Bar {};
    
    Foo unused;
    

    Without the defect resolution, unused would be ill-formed, because foo takes a template with only one template parameter, and not two. If you relied on this (maybe for SFINAE):

    template typename>
    void foo();
    
    template typename>
    void foo();
    
    template
    struct Bar {};
    
    int main() {
        foo(); // ambiguous after resolution!
    }
    

    Then the call would fail! The problem is that there was no corresponding change to partial ordering, and so both candidate functions have the same viability, and the call is ambiguous.

提交回复
热议问题