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

Jordan Rose jordan_rose at apple.com
Thu Aug 16 09:09:35 PDT 2012


This does seem like a good idea. I'm trying to wrap my head around what this means and failing. 'int *a = *a'?

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. But the inline field initializer ('int &c = c' in a class) would be nice to handle.

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

Jordan


On Aug 16, 2012, at 2:36 , Hans Wennborg <hans at chromium.org> wrote:

> Hi all,
> 
> The attached patch makes Clang warn about self-initialization of
> references, like:
> 
>  int &a = a;
> 
> Because that seems like a bad thing to do, and I don't think we should
> suppress it like we do with "int x = x" which is a common way of
> avoiding warnings about unused variables.
> 
> Please take a look.
> 
> Thanks,
> Hans
> <self_init_refs.patch>_______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list