Can't assign a `std::unique_ptr` to a base class in clang when using an alias template

前端 未结 1 607
予麋鹿
予麋鹿 2021-01-17 15:14

The following code compiles and runs just fine on gcc 4.9.3 and clang 3.7.1

// std::unique_ptr
#include 

// Template class for template-templa         


        
相关标签:
1条回答
  • 2021-01-17 15:56

    This is CWG issue 1244:

    The example in 14.4 [temp.type] paragraph 1 reads in significant part,

    template<template<class> class TT> struct X { };
    template<class> struct Y { };
    template<class T> using Z = Y<T>;
    X<Y> y;
    X<Z> z;
    

    and says that y and z have the same type.

    This would only be true if alias template Z were considered to be equivalent to class template Y. However, 14.5.7 [temp.alias] describes equivalence only for specializations of alias templates, not for the alias templates themselves. Either such rules should be specified, which could be tricky, or the example should be deleted.

    We can reduce your example down to:

    std::unique_ptr<Base<double, Buz>> f = 
        std::make_unique<Base<double, Bar>>();
    

    This is well formed if and only if Buz and Bar are considered equivalent. gcc thinks they are, clang thinks they aren't. It's still an open question as to what the actual answer is.

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