public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/49850] New: Implicit creation of a temporary object when a constant reference is passed as parameter and the actual and formal types are not identical @ 2011-07-26 9:27 gccbugs@andreas-borchert.de 2011-07-26 10:21 ` [Bug c++/49850] " daniel.kruegler at googlemail dot com 2011-07-26 12:29 ` paolo.carlini at oracle dot com 0 siblings, 2 replies; 3+ messages in thread From: gccbugs@andreas-borchert.de @ 2011-07-26 9:27 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49850 Summary: Implicit creation of a temporary object when a constant reference is passed as parameter and the actual and formal types are not identical Product: gcc Version: 4.4.5 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: gccbugs@andreas-borchert.de The following has been tested with g++ (Debian 4.4.5-8) 4.4.5 for the amd64 architecture as shipped with stable Debian 6.0. I do not have it tested for newer releases as I do not have them conveniently available. Following code demonstrates the problem: ---- code start ---- #include <iostream> #include <sys/types.h> using namespace std; size_t si; void foo(const unsigned int& ui) { cout << "address of ui = " << (long long int) &ui << endl; } int main() { cout << "address of si = " << (long long int) &si << endl; foo(si); } ---- code end ---- The code generated for the invocation of foo() in main() shows the problem: movq si(%rip), %rax movl %eax, -20(%rbp) leaq -20(%rbp), %rax movq %rax, %rdi call _Z3fooRKj 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. ^ permalink raw reply [flat|nested] 3+ messages in thread
* [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 2011-07-26 9:27 [Bug c++/49850] New: Implicit creation of a temporary object when a constant reference is passed as parameter and the actual and formal types are not identical gccbugs@andreas-borchert.de @ 2011-07-26 10:21 ` daniel.kruegler at googlemail dot com 2011-07-26 12:29 ` paolo.carlini at oracle dot com 1 sibling, 0 replies; 3+ messages in thread From: daniel.kruegler at googlemail dot com @ 2011-07-26 10:21 UTC (permalink / raw) To: gcc-bugs 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. ^ permalink raw reply [flat|nested] 3+ messages in thread
* [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 2011-07-26 9:27 [Bug c++/49850] New: Implicit creation of a temporary object when a constant reference is passed as parameter and the actual and formal types are not identical gccbugs@andreas-borchert.de 2011-07-26 10:21 ` [Bug c++/49850] " daniel.kruegler at googlemail dot com @ 2011-07-26 12:29 ` paolo.carlini at oracle dot com 1 sibling, 0 replies; 3+ messages in thread From: paolo.carlini at oracle dot com @ 2011-07-26 12:29 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49850 Paolo Carlini <paolo.carlini at oracle dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |INVALID --- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-07-26 12:27:33 UTC --- Let's close this. ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-07-26 12:29 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2011-07-26 9:27 [Bug c++/49850] New: Implicit creation of a temporary object when a constant reference is passed as parameter and the actual and formal types are not identical gccbugs@andreas-borchert.de 2011-07-26 10:21 ` [Bug c++/49850] " daniel.kruegler at googlemail dot com 2011-07-26 12:29 ` paolo.carlini at oracle dot com
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).