This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: "Defaulted and deleting functions" with template members


On 9/15/09, Mark Zweers <zweers.mark@gmail.com> wrote:
> While experimenting with "Defaulted and deleting functions" on my
> brand-newly downloaded gcc-4.5 compiler, I've noticed the following: the
> order of '=default' and '=delete' matters with template member functions.
>
> template<typename T>
> class NonCopyable {
> public:
>   NonCopyable();
>   ~NonCopyable();
>   NonCopyable(NonCopyable const&);
> };
>
> template<typename T>
> NonCopyable<T>::NonCopyable() = default;
>
> template<typename T>
> NonCopyable<T>::~NonCopyable() = default;
>
> template<>
> NonCopyable<double>::NonCopyable(NonCopyable<double> const&) = delete;
>
> template<typename T>
> NonCopyable<T>::NonCopyable(NonCopyable<T> const&) = default;
>
>
> int main()
> {
>   NonCopyable<int> nc_int;
>   NonCopyable<int> nc_int_cpy(nc_int);
>
>   NonCopyable<double> nc_dbl;
>   NonCopyable<double> nc_dbl_cpy(nc_dbl);
>
>   return 0;
> }
>
> The above example results in the sought behavior : only for a 'double'
> specialisation the copy constructor is prohibited.
>
> However, if I reverse the order of copy constructors, nothing is prohibited
> at all (deletion of the 'double' specialisation is useless) :
>
> template<typename T>
> NonCopyable<T>::NonCopyable(NonCopyable<T> const&) = default;
>
> template<>
> NonCopyable<double>::NonCopyable(NonCopyable<double> const&) = delete;
>
> although this would seem to me to be a more likely use case : the general
> case is provided ; in another, separate file, prohibition of the copy
> constructor is specialized.
>
> What is your opinion about this?

I think the compiler should use the specialization regardless of
the order.

-- 
Lawrence Crowl


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]