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

Matthieu Monrocq matthieu.monrocq at gmail.com
Tue Apr 10 10:38:03 PDT 2012

Le 10 avril 2012 19:20, Arthur O'Dwyer <arthur at push.am> a écrit :

> On Mon, Apr 9, 2012 at 17:04 PM, Nico Weber <thakis at chromium.org> wrote:
> >
> > this sounds like a really cool warning. I tried building chromium with
> > it, here are a few examples where it warns but probably shouldn't:
> [initializing a char array with strlcpy or strcpy]
> [calling a helper method to initialize the members]
> [using assignment statements in the body of the constructor]
> This warning has the potential to get really messy if you try to
> handle all possible cases.</stating-the-obvious> I know because I
> implemented something exactly like this in (a proprietary fork of) the
> EDG front-end a few years ago. Not saying you shouldn't try, just
> saying it wasn't fun trying (and failing) to make it foolproof.
> 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
> }
> -Arthur

Perhaps that as a first approach it would be simpler to just not warn
whenever there is at least one statement in the constructor's body ?

This is also a common pattern in C++03 because of the absence of delegating

class A {
   A() { this->init(0); }
   A(int x) { this->init(x); }

And the definition of "init" might not be available.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120410/54e71989/attachment.html>

More information about the cfe-dev mailing list