Me too.  Implicit type conversion through one-arg constructors is the
source of subtle bugs.

-dave

On 05/12/2014 01:16 PM, Kyle Huey wrote:
> On Mon, May 12, 2014 at 1:07 PM, Boris Zbarsky <bzbar...@mit.edu> wrote:
>> Background: in C++, one-argument constructors are implicit.
>>
>> What this means is that given this class declaration:
>>
>>   class Foo {
>>   public:
>>     Foo(int arg);
>>
>>     passAFoo(const Foo& arg);
>>   };
>>
>> This bit of C++:
>>
>>   Foo foo(5);
>>   foo.passAFoo(10);
>>
>> will compile and construct a temporary Foo that it passes to passAFoo. This
>> can be a pretty serious footgun, especially in cases when the constructor is
>> passed a pointer and takes ownership of that pointer: accidentally passing a
>> pointer where an object of is expected will do bad things.
>>
>> So I'd like to propose that our C++ style require one-arg constructors to be
>> marked explicit unless there's a clear comment explaining why the
>> constructor is implicit.
>>
>> Thoughts?
>>
>> -Boris
>> _______________________________________________
>> dev-platform mailing list
>> dev-platform@lists.mozilla.org
>> https://lists.mozilla.org/listinfo/dev-platform
> 
> I support this!
> 
> - Kyle
> _______________________________________________
> dev-platform mailing list
> dev-platform@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
> 

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to