[cfe-commits] [Patch] Warn about self-initialization of reference variables

Hans Wennborg hans at chromium.org
Thu Aug 16 09:21:27 PDT 2012


On Thu, Aug 16, 2012 at 5:09 PM, Jordan Rose <jordan_rose at apple.com> wrote:
> I'm trying to wrap my head around what this means and failing. 'int *a = *a'?

That isn't as sneaky as the reference case, because "*a" on the
right-hand side has type int, so you'd get a warning about trying to
initialize a pointer with an int.

The self-initialized reference case is also extra bad because we know
it's going to be invalid forever since it cannot be changed. A badly
initialized pointer can at least be made valid later.

> I wouldn't worry about the 'a(b), b(a)' case. Or rather, the issue is that 'b' is uninitialized in 'a(b)', and it doesn't really matter if it's given a valid initialization later.

Yeah, you're right. The reason I've got both a(b) and b(a) in there is
because otherwise there'd be an error about one of them not getting
initialized in the constructor.

> I'm not so familiar with this part of Sema, but the diff looks reasonable.

Thanks! Anyone else who'd like to take a look?

 - Hans



More information about the cfe-commits mailing list