This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Reference declaration with self-assignment. Is it legal? G++ says it is!
- From: Carlos Ferreira <carlosmf dot pt at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 15 May 2015 12:18:46 +0100
- Subject: Re: Reference declaration with self-assignment. Is it legal? G++ says it is!
- Authentication-results: sourceware.org; auth=none
- References: <CAJpYY6UtJKY8GoX87njvgzg4HZxtZZ0boaukp69Y3mmbBupT6w at mail dot gmail dot com> <alpine dot DEB dot 2 dot 02 dot 1505151253280 dot 19595 at stedding dot saclay dot inria dot fr>
Ok this is embarrassing... I discovered now that the compiling flags
for all warnings were not active.
Thank you for the help anyway.
Carlos
On 15 May 2015 at 11:55, Marc Glisse <marc.glisse@inria.fr> wrote:
> On Fri, 15 May 2015, Carlos Ferreira wrote:
>
>> Hello to all!
>>
>> I would like to make a quick question.
>>
>> G++ seems to allow this:
>>
>> int& x = x;
>>
>> which creates a null int reference. Why does G++ allows this? Is it a
>> standard thing? This doesn't even generates a warning, and such code can
>> easily cause a segfault.
>
>
> I am actually getting 2 warnings with g++-5 -Wall:
>
> x.c:2:7: warning: reference 'i' is initialized with itself [-Winit-self]
> int&i=i;
> ^
> x.c:2:9: warning: 'i' is used uninitialized in this function
> [-Wuninitialized]
> int&i=i;
> ^
>
> --
> Marc Glisse
--
Carlos Miguel Ferreira
Researcher at Telecommunications Institute
Aveiro - Portugal
Work E-mail - cmf@av.it.pt
Skype & GTalk -> carlosmf.pt@gmail.com
LinkedIn -> http://www.linkedin.com/in/carlosmferreira