public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/18635] use of uninitialised reference accepted in C++ front end Date: Fri, 26 Nov 2010 11:23:00 -0000 [thread overview] Message-ID: <bug-18635-4-qiFGoj7j9s@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-18635-4@http.gcc.gnu.org/bugzilla/> 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.
next prev parent reply other threads:[~2010-11-26 10:59 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <bug-18635-4@http.gcc.gnu.org/bugzilla/> 2010-11-26 1:05 ` adam.rak at streamnovation dot com 2010-11-26 11:23 ` redi at gcc dot gnu.org [this message] 2010-11-26 11:29 ` manu at gcc dot gnu.org 2010-11-26 12:00 ` redi at gcc dot gnu.org 2010-11-26 17:28 ` pentek.imre at gmail dot com 2010-11-26 18:40 ` redi at gcc dot gnu.org 2010-11-27 14:53 ` adam.rak at streamnovation dot com 2011-05-22 19:11 ` redi at gcc dot gnu.org 2011-06-27 11:55 ` [Bug c++/18635] [DR 504] " redi at gcc dot gnu.org 2021-04-08 0:20 ` [Bug c++/18635] [DR 504] use of uninitialised reference accepted (without -Wuninitialized) " msebor at gcc dot gnu.org 2021-04-08 8:16 ` manu at gcc dot gnu.org 2021-04-08 14:24 ` msebor at gcc dot gnu.org 2021-08-10 19:46 ` redi at gcc dot gnu.org 2024-04-12 0:06 ` mpolacek at gcc dot gnu.org [not found] <bug-18635-9680@http.gcc.gnu.org/bugzilla/> 2005-11-27 21:18 ` [Bug c++/18635] use of uninitialised reference accepted " gdr at gcc dot gnu dot org 2009-05-29 14:36 ` pinskia at gcc dot gnu dot org 2004-11-23 23:11 [Bug c++/18635] New: " ajo at acm dot org 2004-11-23 23:19 ` [Bug c++/18635] " pinskia at gcc dot gnu dot org 2004-11-24 2:11 ` llib at computer dot org 2004-11-24 19:07 ` pinskia at gcc dot gnu dot org 2004-11-26 2:56 ` llib at computer dot org 2004-11-26 10:17 ` giovannibajo at libero dot it 2004-11-29 0:56 ` llib at computer dot org 2004-11-29 11:26 ` giovannibajo at libero dot it 2004-11-29 11:41 ` giovannibajo at libero dot it
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-18635-4-qiFGoj7j9s@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).