[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 gcc-bugzilla@gcc.gnu.org
Tue Jul 26 09:27:00 GMT 2011


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.



More information about the Gcc-bugs mailing list