This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Reference declaration with self-assignment. Is it legal? G++ says it is!


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]