[cfe-dev] warn when ctor-initializer leaves uninitialized data?

Matt Beaumont-Gay matthewbg at google.com
Tue Apr 10 18:50:02 PDT 2012


On Tue, Apr 10, 2012 at 16:21, Gabor Greif <gabor at mac.com> wrote:
> Arthur O'Dwyer wrote:
>
>> Here's one more semi-common idiom that we ran into at the time:
>>
>> Foo::Foo() {
>>     memset(this, '\0', sizeof *this); // most of my fields should be
>> false or zero
>>     this->should_be_true = true; // initialize only the interesting
>> ones
>> }
>
>
> This should definitely warn if there is a vptr overwritten by the
> memset.

I believe -Wdynamic-class-memaccess complains about this.

-Matt




More information about the cfe-dev mailing list