public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/44409]  New: explicit call of a defined copy constructor does not work
@ 2010-06-03 22:33 gcc at razorcam dot com
  2010-06-03 22:38 ` [Bug c++/44409] " pinskia at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gcc at razorcam dot com @ 2010-06-03 22:33 UTC (permalink / raw)
  To: gcc-bugs

the following command always outputs 1 instead of the expected 0
g++ bug_report.cpp && ./a.out ;echo $?
g++ does not output anything during the compilation
the output of g++ -v -save-temps follows the source file bug_report.cpp
the preprocessed file bug_report.ii is at the end of this report

struct A{
        const int i;
        A():i(1){}
        A(const A& a):i(0){}
};
int main(){
        return A(A()).i;
}


g++ -v -save-temps
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.4-3'
--with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--enable-multiarch --enable-linker-build-id --with-system-zlib
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc
--with-arch-32=i486 --with-tune=generic --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.4 (Debian 4.4.4-3) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
 /usr/lib/gcc/x86_64-linux-gnu/4.4.4/cc1plus -E -quiet -v -D_GNU_SOURCE
bug_report.cpp -mtune=generic -fpch-preprocess -o bug_report.ii
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/4.4.4/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/usr/include/x86_64-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.4
 /usr/include/c++/4.4/x86_64-linux-gnu
 /usr/include/c++/4.4/backward
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.4.4/include
 /usr/lib/gcc/x86_64-linux-gnu/4.4.4/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
 /usr/lib/gcc/x86_64-linux-gnu/4.4.4/cc1plus -fpreprocessed bug_report.ii
-quiet -dumpbase bug_report.cpp -mtune=generic -auxbase bug_report -version -o
bug_report.s
GNU C++ (Debian 4.4.4-3) version 4.4.4 (x86_64-linux-gnu)
        compiled by GNU C version 4.4.4, GMP version 4.3.2, MPFR version
2.4.2-p1.
GGC heuristics: --param ggc-min-expand=57 --param ggc-min-heapsize=51739
GNU C++ (Debian 4.4.4-3) version 4.4.4 (x86_64-linux-gnu)
        compiled by GNU C version 4.4.4, GMP version 4.3.2, MPFR version
2.4.2-p1.
GGC heuristics: --param ggc-min-expand=57 --param ggc-min-heapsize=51739
Compiler executable checksum: a92c574e76687c18572fdbea97434cec
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
 as --traditional-format -V -Qy -o bug_report.o bug_report.s
GNU assembler version 2.20.1 (x86_64-linux-gnu) using BFD version (GNU Binutils
for Debian) 2.20.1-system.20100303
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.4.4/:/usr/lib/gcc/x86_64-linux-gnu/4.4.4/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.4.4/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.4.4/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.4.4/:/usr/lib/gcc/x86_64-linux-gnu/4.4.4/:/usr/lib/gcc/x86_64-linux-gnu/4.4.4/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.4.4/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
 /usr/lib/gcc/x86_64-linux-gnu/4.4.4/collect2 --build-id --eh-frame-hdr -m
elf_x86_64 --hash-style=both -dynamic-linker /lib64/ld-linux-x86-64.so.2
/usr/lib/gcc/x86_64-linux-gnu/4.4.4/../../../../lib/crt1.o
/usr/lib/gcc/x86_64-linux-gnu/4.4.4/../../../../lib/crti.o
/usr/lib/gcc/x86_64-linux-gnu/4.4.4/crtbegin.o
-L/usr/lib/gcc/x86_64-linux-gnu/4.4.4 -L/usr/lib/gcc/x86_64-linux-gnu/4.4.4
-L/usr/lib/gcc/x86_64-linux-gnu/4.4.4/../../../../lib -L/lib/../lib
-L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.4.4/../../.. bug_report.o
-lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/lib/gcc/x86_64-linux-gnu/4.4.4/crtend.o
/usr/lib/gcc/x86_64-linux-gnu/4.4.4/../../../../lib/crtn.o


bug_report.ii

# 1 "bug_report.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "bug_report.cpp"
struct A{
 const int i;
 A():i(1){}
 A(const A& a):i(0){}
};
int main(){
 return A(A()).i;
}


-- 
           Summary: explicit call of a defined copy constructor does not
                    work
           Product: gcc
           Version: 4.4.4
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gcc at razorcam dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44409


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/44409] explicit call of a defined copy constructor does not work
  2010-06-03 22:33 [Bug c++/44409] New: explicit call of a defined copy constructor does not work gcc at razorcam dot com
@ 2010-06-03 22:38 ` pinskia at gcc dot gnu dot org
  2010-06-03 22:43 ` redi at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-06-03 22:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2010-06-03 22:37 -------
I think this one case is where the copy constructor can be skipped.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44409


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/44409] explicit call of a defined copy constructor does not work
  2010-06-03 22:33 [Bug c++/44409] New: explicit call of a defined copy constructor does not work gcc at razorcam dot com
  2010-06-03 22:38 ` [Bug c++/44409] " pinskia at gcc dot gnu dot org
@ 2010-06-03 22:43 ` redi at gcc dot gnu dot org
  2010-06-03 23:05 ` gcc at razorcam dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-06-03 22:43 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 769 bytes --]



------- Comment #2 from redi at gcc dot gnu dot org  2010-06-03 22:42 -------
Yes, this is eligible for copy elision, see [class.copy]

— when a temporary class object that has not been bound to a reference (12.2)
would be copied/moved
to a class object with the same cv-unquali&#64257;ed type, the copy/move
operation can be omitted by
constructing the temporary object directly into the target of the omitted
copy/move


-- 

redi at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44409


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/44409] explicit call of a defined copy constructor does not work
  2010-06-03 22:33 [Bug c++/44409] New: explicit call of a defined copy constructor does not work gcc at razorcam dot com
  2010-06-03 22:38 ` [Bug c++/44409] " pinskia at gcc dot gnu dot org
  2010-06-03 22:43 ` redi at gcc dot gnu dot org
@ 2010-06-03 23:05 ` gcc at razorcam dot com
  2010-06-03 23:23 ` redi at gcc dot gnu dot org
  2010-06-03 23:27 ` redi at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: gcc at razorcam dot com @ 2010-06-03 23:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from gcc at razorcam dot com  2010-06-03 23:04 -------
Thanks for your answers. From the above answers I understand that g++ respects
the ISO c++ standard, and thus you can consider this is not a bug. But this is
clearly an explicit call of the copy constructor, not an implicit one. That
means that the fundamental concept of function composition is not respected
here by the ISO standard only when you compose the same constructor function
and silently so this is very error-prone.
I guess i have to submit a bug report to the ISO C++ standard now ...


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44409


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/44409] explicit call of a defined copy constructor does not work
  2010-06-03 22:33 [Bug c++/44409] New: explicit call of a defined copy constructor does not work gcc at razorcam dot com
                   ` (2 preceding siblings ...)
  2010-06-03 23:05 ` gcc at razorcam dot com
@ 2010-06-03 23:23 ` redi at gcc dot gnu dot org
  2010-06-03 23:27 ` redi at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-06-03 23:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from redi at gcc dot gnu dot org  2010-06-03 23:23 -------
Good luck with that.

Your copy constructor doesn't copy the state of the source object. Complaints
like this usually only come up in unrealistic examples created to test a
compiler's behaviour.  There are many, many situations where copy elision is a
good thing, there are very few where it's undesirable in real programs.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44409


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/44409] explicit call of a defined copy constructor does not work
  2010-06-03 22:33 [Bug c++/44409] New: explicit call of a defined copy constructor does not work gcc at razorcam dot com
                   ` (3 preceding siblings ...)
  2010-06-03 23:23 ` redi at gcc dot gnu dot org
@ 2010-06-03 23:27 ` redi at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-06-03 23:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from redi at gcc dot gnu dot org  2010-06-03 23:27 -------
see http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/ for more
details of copy elision and why it is a good thing


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44409


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-06-03 23:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-03 22:33 [Bug c++/44409] New: explicit call of a defined copy constructor does not work gcc at razorcam dot com
2010-06-03 22:38 ` [Bug c++/44409] " pinskia at gcc dot gnu dot org
2010-06-03 22:43 ` redi at gcc dot gnu dot org
2010-06-03 23:05 ` gcc at razorcam dot com
2010-06-03 23:23 ` redi at gcc dot gnu dot org
2010-06-03 23:27 ` redi at gcc dot gnu dot org

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