http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18635

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-11-26 
10:59:24 UTC ---
(In reply to comment #2)
> int &a = a;
> i don't believe this is valid code.  i believe g++ should reject the code.

I'm not convinced the compiler must reject it. EDG accepts it too.

> various comp.std.c++ people agree with me.

Working link to the thread:
http://groups.google.com/group/comp.std.c++/browse_thread/thread/fb732bbcd0fecec5/4e04facc65ebf2f5

> 8.3.2/4 states "[...] A reference shall be initialized to refer to a valid
> object or function."
>
> surely a (the right-hand-side) is not a valid object or function since it has
> not been initialised, so the code is ill-formed.

Right, but consider:

inline int& f(int& i) { return i; }

int& i = f(i);

And then consider if f(int&) is not inline and is defined in another
translation unit.  The compiler can warn that f(i) uses an uninitialized
variable but can't know that the initializer for i is invalid, because maybe
f() does return a reference to a valid object.

(In reply to comment #8)
> in g++-4.6 (and maybe all before) this bug can be even more troublesome:
> struct AA
> {
>  int &a;
>  AA() : a(a)
>  {
>  }
> };
> 
> int main()
> {
>         AA aa;
>         cout << &aa.a << endl;
>         return 0;
> }
> 
> compiled without a warning even with

That's simply because we don't do uninitialized warnings for data members,
that's a separate bug.

Reply via email to