This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: missing ctor & initor for reference not detected
- To: David C Binderman <dcb at pncl dot co dot uk>
- Subject: Re: missing ctor & initor for reference not detected
- From: Ian Haggard <ian at shellus dot com>
- Date: Tue, 03 Mar 1998 14:49:47 -0600
- Cc: egcs-bugs at cygnus dot com
- Organization: Shell
- References: <199803031836.SAA19671@eiger.pncl.co.uk>
David C. Binderman wrote:
> Hello there,
>
> Given the following code on machine i486-pc-linux-gnulibc1, with
> compiler G++ in egcs-980302, I was surprised to find that it compiled ok.
>
> struct A
> {
> int & ri;
> };
>
> I even tried flags -O -Wall -ansi -pedantic, and the code still compiled !
Again, this is not an error. If you want an error, add these lines:
A a; // ERROR! Can't have a struct with uninitialized reference members.
A* pa;
A a2(*pa); // OK. The default copy c'tor inits a2.ri with pa->ri.
int i;
A a3={i}; // OK. Use array initializer to make a3.ri a reference to i.
--
Ian Haggard || ian@shellus.com (work) || IanHaggard@juno.com (home)
GNU/Linux -- "Oh, no, Mr Bill!" || #define employer_opinion !my_opinion