Constrained member functions and explicit template instantiation

前端 未结 2 506
予麋鹿
予麋鹿 2021-02-14 16:58

G++ and Clang++ agree that the following snippet is not valid C++:

template
struct Tensor {};

template
double InnerProduc         


        
2条回答
  •  余生分开走
    2021-02-14 17:26

    This is a bug of the c++20 experimental implementation of both GCC and Clang.

    This is reported as GCC bug #77595.

    In the c++20 paragraph [temp.explicit]/11:

    An explicit instantiation that names a class template specialization is also an explicit instantiation of the same kind (declaration or definition) of each of its members (not including members inherited from base classes and members that are templates) that has not been previously explicitly specialized in the translation unit containing the explicit instantiation, provided that the associated constraints, if any, of that member are satisfied by the template arguments of the explicit instantiation ([temp.constr.decl], [temp.constr.constr]), except as described below. [...]

    According to this c++20 adendum "provided that the associated constraints, if any, of that member are satisfied" means that only one of the two Dot overload shall be explicitly instantiated.

    The bolded clause "except as described below" was there in the c++17 standard. It does apply to the first clause "An explicit instantiation that names a class template specialization is also an explicit instantiation of the same kind (declaration or definition) of each of its members". The interpretation of this exception has not changed with c++20. Probably that the commitee overlooked that, grammaticaly, it could be correct to apply the exception to the c++20 adendum.

    Below is the c++17 version of this paragraph:

    An explicit instantiation that names a class template specialization is also an explicit instantiation of the same kind (declaration or definition) of each of its members (not including members inherited from base classes and members that are templates) that has not been previously explicitly specialized in the translation unit containing the explicit instantiation, except as described below.

    In this shorter sentence the meaning is clear.

提交回复
热议问题