From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 603 invoked by alias); 26 Jul 2011 09:27:15 -0000 Received: (qmail 591 invoked by uid 22791); 26 Jul 2011 09:27:15 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_OV X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 26 Jul 2011 09:26:59 +0000 From: "gccbugs@andreas-borchert.de" To: gcc-bugs@gcc.gnu.org Subject: [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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gccbugs@andreas-borchert.de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Tue, 26 Jul 2011 09:27:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-07/txt/msg02226.txt.bz2 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 #include 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.