public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "daniel.kruegler at googlemail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/49850] Implicit creation of a temporary object when a constant reference is passed as parameter and the actual and formal types are not identical Date: Tue, 26 Jul 2011 10:21:00 -0000 [thread overview] Message-ID: <bug-49850-4-xDQg7zFSvp@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-49850-4@http.gcc.gnu.org/bugzilla/> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49850 Daniel Krügler <daniel.kruegler at googlemail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |daniel.kruegler at | |googlemail dot com --- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2011-07-26 10:20:47 UTC --- (In reply to comment #0) > #include <sys/types.h> To make the definition of size_t available, you should better include a standard header, like <stddef.h> > Instead of passing the address of the global si variable, a temporary > object is created (at 20(%rbp)) whose address is passed. If you test > this program, the output shows the effect: > > address of si = 6295456 > address of ui = 140734739682956 > > The apparent problem is that "unsigned int" and "size_t" do not match, > at least not on this platform (size and signedness are different). But > then I would expect an error and not the implicit creation of a > temporary object of the appropriate type. You might expect this, but this would be in contradiction to what the C++ standard requires ([dcl.init.ref] p5 last bullet). GCC is required to accept this conversion. If you want to prevent this, use a pointer type or a non-const reference instead of a reference to const as function parameter. This does not look like a compiler defect to me.
next prev parent reply other threads:[~2011-07-26 10:21 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-07-26 9:27 [Bug c++/49850] New: " gccbugs@andreas-borchert.de 2011-07-26 10:21 ` daniel.kruegler at googlemail dot com [this message] 2011-07-26 12:29 ` [Bug c++/49850] " paolo.carlini at oracle dot com
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-49850-4-xDQg7zFSvp@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).