[PATCH] Warn on explicit copy constructors.
Arthur O'Dwyer
arthur.j.odwyer at gmail.com
Tue Apr 29 10:32:17 PDT 2014
On Tue, Apr 29, 2014 at 8:38 AM, Alexander Kornienko <alexfh at google.com> wrote:
> On Tue, Apr 29, 2014 at 5:28 PM, Arthur O'Dwyer <arthur.j.odwyer at gmail.com> wrote:
>> On Tue, Apr 29, 2014 at 6:58 AM, Alexander Kornienko <alexfh at google.com> wrote:
>> >
>> > http://reviews.llvm.org/D3541
>>
>> There are corner cases such as
>>
>> C(const C&&);
>> C(const C&, int i = 0);
>> template<typename T> C(const T&);
>>
>> that would be interesting to test.
>
> [Diagnostic on the template one; no diagnostics on the other two]
>
> Is this what you expected? To me it seems reasonable.
I have no stake in Google's coding style guide, but my personal
(mental) coding standard shuns the first two constructors with even
more vehemence than the template one. Although on grounds unrelated to
"explicit" — so the lack of diagnostic here is fine by me.
The template example is the only one of those three that I've actually
seen in real code (although the "const&&" version might well appear in
our codebase and nobody's noticed yet). The subtlety with the template
one is that "C::C<T>(const T&) [with T=C]" is **NOT** a
copy-constructor, even though you might naively expect it to be. And
yes, this caused a real bug, when the compiler called the defaulted
copy constructor instead of the template version.
my $.02,
–Arthur
More information about the cfe-commits
mailing list