From: Lawrence Crowl <Lawrence@Crowl.org>
To: Mark Zweers <zweers.mark@gmail.com>
Cc: crowl@google.com, gcc@gcc.gnu.org
Subject: Re: "Defaulted and deleting functions" with template members
Date: Tue, 15 Sep 2009 21:06:00 -0000 [thread overview]
Message-ID: <90228e530909151406r32b60802s3d8d51a14f71ffa6@mail.gmail.com> (raw)
In-Reply-To: <b17c64ce0909151117g79136134w333347db6eb39d05@mail.gmail.com>
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
prev parent reply other threads:[~2009-09-15 21:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[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 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=90228e530909151406r32b60802s3d8d51a14f71ffa6@mail.gmail.com \
--to=lawrence@crowl.org \
--cc=crowl@google.com \
--cc=gcc@gcc.gnu.org \
--cc=zweers.mark@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).