public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "adam.rak at streamnovation dot com" <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 01:05:00 -0000 [thread overview] Message-ID: <bug-18635-4-oWSQOpgGoM@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 Ádám Rák <adam.rak at streamnovation dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |adam.rak at streamnovation | |dot com --- Comment #8 from Ádám Rák <adam.rak at streamnovation dot com> 2010-11-26 00:30:17 UTC --- 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 g++ main.cpp -O3 -Wall -pedantic -Wextra -Winit-self -Wuninitialized And in -O0 it prints some address, probably the address of the reference as suggested before. But in -O1..3 it prints a 0, which means we made an nullreference. The practical problem is that because of this, the code can be easily messed up like this: class AA { ...int &aaa; AA(int& aaaa) : aaa(aaa) {... A single typo and the compiled does really strange things, the segfault is best case, sometimes the reference points a valid address. It is very hard to debug too. And when the programmer checks the code he/she can naively think that the compiler should check it, so "why bother checking whether they are spelled exactly the same?" The old testcase was a bit harder to do accidentally, this one can happen more easily. A self-init warning might enough to clue the programmer if this happens. An error would be better if we are sure this is invalid.
next parent reply other threads:[~2010-11-26 0:30 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 [this message] 2010-11-26 11:23 ` redi at gcc dot gnu.org 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-oWSQOpgGoM@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).