public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: "Defaulted and deleting functions" with template members
       [not found] <b17c64ce0909151117g79136134w333347db6eb39d05@mail.gmail.com>
@ 2009-09-15 18:22 ` Mark Zweers
  2009-10-01 14:34   ` Jason Merrill
  2009-09-15 21:06 ` Lawrence Crowl
  1 sibling, 1 reply; 3+ messages in thread
From: Mark Zweers @ 2009-09-15 18:22 UTC (permalink / raw)
  To: gcc

On Tue, Sep 15, 2009 at 8:17 PM, Mark Zweers <zweers.mark@gmail.com> wrote:
>
> Hello,
>
> 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?
>
> Thank you a lot for your answer!
>
> Bests,
>
> Mark Zweers

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: "Defaulted and deleting functions" with template members
       [not found] <b17c64ce0909151117g79136134w333347db6eb39d05@mail.gmail.com>
  2009-09-15 18:22 ` "Defaulted and deleting functions" with template members Mark Zweers
@ 2009-09-15 21:06 ` Lawrence Crowl
  1 sibling, 0 replies; 3+ messages in thread
From: Lawrence Crowl @ 2009-09-15 21:06 UTC (permalink / raw)
  To: Mark Zweers; +Cc: crowl, gcc

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: "Defaulted and deleting functions" with template members
  2009-09-15 18:22 ` "Defaulted and deleting functions" with template members Mark Zweers
@ 2009-10-01 14:34   ` Jason Merrill
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2009-10-01 14:34 UTC (permalink / raw)
  To: Mark Zweers; +Cc: gcc

On 09/15/2009 02:22 PM, Mark Zweers 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.

I'm about to check in a fix for this, but in future please use 
http://gcc.gnu.org/bugzilla for bug reports.

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-10-01 14:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <b17c64ce0909151117g79136134w333347db6eb39d05@mail.gmail.com>
2009-09-15 18:22 ` "Defaulted and deleting functions" with template members Mark Zweers
2009-10-01 14:34   ` Jason Merrill
2009-09-15 21:06 ` Lawrence Crowl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).