public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* (withdraw) GCC bug: Inappropriate implicit invocation of copy constructor when reference parameter is a temporary
@ 2009-02-11  9:23 Manfred von Willich (RapidM)
  0 siblings, 0 replies; only message in thread
From: Manfred von Willich (RapidM) @ 2009-02-11  9:23 UTC (permalink / raw)
  To: gcc-bugs

Please ignore my previously sent email below.  I see it is a "non bug",
despite the utter insanity behind the rationale for it...

Manfred von Willich 	
________________________________

Contractor 
RapidM
Fax
E-mail
Web 	: +27 (12) 349-0000
: +27 (12) 349-0010
: manfredvw@rapidm.com
: www.rapidm.com 	 



-----Original Message-----
From: Manfred von Willich (RapidM) [mailto:manfredvw@rapidm.com] 
Sent: 03 February 2009 14:17
To: 'gcc-bugs@gcc.gnu.org'
Subject: GCC bug: Inappropriate implicit invocation of copy constructor when
reference parameter is a temporary


I believe this is a genuine GCC compiler bug (in both GCC 4.1.1 and GCC
4.2.4).  I hope this report is of value, and certainly hope it can be
corrected.

Forgive me for not logging a bug via http://gcc.gnu.org/bugzilla/ - I don't
want to mess around with your system due to unfamiliarity with Bugzilla.

Please email me directly if you wish.

Manfred


======================================


Description of presumed bug:

When a temporary is passed as a reference parameter, the copy constructor of
the source object type is apparently invoked without reason.  This is
evidenced by a "no matching function" error message if there is no valid
copy constructor.  If the actual parameter is not a temporary, this does not
occur.


My take:

It should be possible to pass a reference of a temporary to a function even
when the class has no copy semantics, and there is no call for invoking a
copy constructor in this context. 


Additional observations:

If the function expects a reference to a base class, the message refers to
the class of the temporary, to the expected reference type.  This, if X is
publicly derived from B and f expects a reference to B, the message still
refers to 'X::X(X)' and not to B.

If the copy constructor is public and implicitly callable, the message no
longer appears.

This is not to be confused with the same message being generated when the
copy constructor must be available for returning an object from a function
(e.g. http://gcc.gnu.org/ml/gcc/2005-05/msg00916.html).



Example of code (test.cpp) that triggers the bug:


class X {
private: explicit X (X const &);  // suppress copy constructor
public: X () { }
};

void f (X const &) { }

void g () {
    f(X());   // error reported: "no matching function for call to
'X::X(X)'"
}


Compiler details:

$ gcc -v -save-temps test.cpp
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr
--enable-targets=all --enable-checking=release --build=i486-linux-gnu
--host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu3)
 /usr/lib/gcc/i486-linux-gnu/4.2.4/cc1plus -E -quiet -v -D_GNU_SOURCE
test.cpp -mtune=generic -fpch-preprocess -o test.ii
ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/i486-linux-gnu/4.2.4/../../../../i486-linux-gnu/include"
ignoring nonexistent directory "/usr/include/i486-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.2
 /usr/include/c++/4.2/i486-linux-gnu
 /usr/include/c++/4.2/backward
 /usr/local/include
 /usr/lib/gcc/i486-linux-gnu/4.2.4/include
 /usr/include
End of search list.
 /usr/lib/gcc/i486-linux-gnu/4.2.4/cc1plus -fpreprocessed test.ii -quiet
-dumpbase test.cpp -mtune=generic -auxbase test -version -fstack-protector
-fstack-protector -o test.s
GNU C++ version 4.2.4 (Ubuntu 4.2.4-1ubuntu3) (i486-linux-gnu)
            compiled by GNU C version 4.2.4 (Ubuntu 4.2.4-1ubuntu3).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: cca9b7b48c023363b938f208576b99cc
test.cpp: In function \u2018void g()\u2019:
test.cpp:9: error: no matching function for call to \u2018X::X(X)\u2019
$ 


Output files:

test.s:
            .file       "test.cpp"


test.ii:
# 1 "test.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.cpp"
class X {
private: explicit X (X const &);
public: X () { }
};

void f (X const &) { }

void g () {
    f(X());
}


Alternative compiler details (same problem):

>gcc -v
Using built-in specs.
Target: arm-unknown-elf
Configured with: ../gcc-2006q3/configure --target=arm-unknown-elf
--build=i686-pc-mingw32 --host=i686-pc-mingw32
--prefix=/c/gcc-build-2006q3-26/install
Thread model: single
gcc version 4.1.1
 



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-02-11  9:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-11  9:23 (withdraw) GCC bug: Inappropriate implicit invocation of copy constructor when reference parameter is a temporary Manfred von Willich (RapidM)

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).