This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[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
- From: "daniel.kruegler at googlemail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 26 Jul 2011 10:20:52 +0000
- 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
- Auto-submitted: auto-generated
- References: <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.