In the following code, the X's move constructor (the constructor overloaded for
rvalue reference) should be called for the copy-initialization
`X y = static_cast<X&&>(x);', and two successive assertions should be passed.
However, it seems that the implicitly defined copy constructor is called, and
the second assertion fails.


cryol...@thinblue:~/work/gcc_bug/move_on_tribially_copy_constructible$
g++-4.5.0 -v -save-temps -std=c++0x main.cpp 
Using built-in specs.
COLLECT_GCC=g++-4.5.0
COLLECT_LTO_WRAPPER=/home/cryolite/local/libexec/gcc/i486-linux-gnu/4.5.0/lto-wrapper
Target: i486-linux-gnu
Configured with: ../gcc-4.5.0/configure --build=i486-linux-gnu
--prefix=/home/cryolite/local --program-suffix=-4.5.0
--enable-version-specific-runtime-libs --enable-languages=c,c++
Thread model: posix
gcc version 4.5.0 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++0x' '-shared-libgcc'
'-mtune=i486' '-march=i486'
 /home/cryolite/local/libexec/gcc/i486-linux-gnu/4.5.0/cc1plus -E -quiet -v
-D_GNU_SOURCE main.cpp -mtune=i486 -march=i486 -std=c++0x -fpch-preprocess -o
main.ii
ignoring duplicate directory "/home/cryolite/local/include"
ignoring nonexistent directory
"/home/cryolite/local/lib/gcc/i486-linux-gnu/4.5.0/../../../../i486-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /home/cryolite/local/include
 /home/cryolite/local/lib/gcc/i486-linux-gnu/4.5.0/include/c++
 /home/cryolite/local/lib/gcc/i486-linux-gnu/4.5.0/include/c++/i486-linux-gnu
 /home/cryolite/local/lib/gcc/i486-linux-gnu/4.5.0/include/c++/backward
 /usr/local/include
 /home/cryolite/local/lib/gcc/i486-linux-gnu/4.5.0/include
 /home/cryolite/local/lib/gcc/i486-linux-gnu/4.5.0/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++0x' '-shared-libgcc'
'-mtune=i486' '-march=i486'
 /home/cryolite/local/libexec/gcc/i486-linux-gnu/4.5.0/cc1plus -fpreprocessed
main.ii -quiet -dumpbase main.cpp -mtune=i486 -march=i486 -auxbase main
-std=c++0x -version -o main.s
GNU C++ (GCC) version 4.5.0 (i486-linux-gnu)
        compiled by GNU C version 4.5.0, GMP version 4.3.1, MPFR version
2.4.1-p2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=81 --param ggc-min-heapsize=95967
GNU C++ (GCC) version 4.5.0 (i486-linux-gnu)
        compiled by GNU C version 4.5.0, GMP version 4.3.1, MPFR version
2.4.1-p2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=81 --param ggc-min-heapsize=95967
Compiler executable checksum: f3cfa96cf9dcd630b91f4110d3b8b2b3
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++0x' '-shared-libgcc'
'-mtune=i486' '-march=i486'
 as -V -Qy --32 -o main.o main.s
GNU assembler version 2.20 (i486-linux-gnu) using BFD version (GNU Binutils for
Ubuntu) 2.20
COMPILER_PATH=/home/cryolite/local/libexec/gcc/i486-linux-gnu/4.5.0/:/home/cryolite/local/libexec/gcc/i486-linux-gnu/4.5.0/:/home/cryolite/local/libexec/gcc/i486-linux-gnu/:/home/cryolite/local/lib/gcc/i486-linux-gnu/4.5.0/:/home/cryolite/local/lib/gcc/i486-linux-gnu/
LIBRARY_PATH=/home/cryolite/local/lib/:/home/cryolite/local/lib/gcc/i486-linux-gnu/4.5.0/:/home/cryolite/local/lib/gcc/i486-linux-gnu/4.5.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++0x' '-shared-libgcc'
'-mtune=i486' '-march=i486'
 /home/cryolite/local/libexec/gcc/i486-linux-gnu/4.5.0/collect2 --eh-frame-hdr
-m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o
/home/cryolite/local/lib/gcc/i486-linux-gnu/4.5.0/crtbegin.o
-L/home/cryolite/local/lib -L/home/cryolite/local/lib/gcc/i486-linux-gnu/4.5.0
-L/home/cryolite/local/lib/gcc/i486-linux-gnu/4.5.0/../../.. main.o -lstdc++
-lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/home/cryolite/local/lib/gcc/i486-linux-gnu/4.5.0/crtend.o /usr/lib/crtn.o

cryol...@thinblue:~/work/gcc_bug/move_on_tribially_copy_constructible$ cat
main.ii 
# 1 "main.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "main.cpp"
# 1 "/home/cryolite/local/lib/gcc/i486-linux-gnu/4.5.0/include/c++/cassert" 1 3
# 43 "/home/cryolite/local/lib/gcc/i486-linux-gnu/4.5.0/include/c++/cassert" 3

# 44 "/home/cryolite/local/lib/gcc/i486-linux-gnu/4.5.0/include/c++/cassert" 3

# 1 "/usr/include/assert.h" 1 3 4
# 37 "/usr/include/assert.h" 3 4
# 1 "/usr/include/features.h" 1 3 4
# 313 "/usr/include/features.h" 3 4
# 1 "/usr/include/bits/predefs.h" 1 3 4
# 314 "/usr/include/features.h" 2 3 4
# 346 "/usr/include/features.h" 3 4
# 1 "/usr/include/sys/cdefs.h" 1 3 4
# 353 "/usr/include/sys/cdefs.h" 3 4
# 1 "/usr/include/bits/wordsize.h" 1 3 4
# 354 "/usr/include/sys/cdefs.h" 2 3 4
# 347 "/usr/include/features.h" 2 3 4
# 378 "/usr/include/features.h" 3 4
# 1 "/usr/include/gnu/stubs.h" 1 3 4



# 1 "/usr/include/bits/wordsize.h" 1 3 4
# 5 "/usr/include/gnu/stubs.h" 2 3 4


# 1 "/usr/include/gnu/stubs-32.h" 1 3 4
# 8 "/usr/include/gnu/stubs.h" 2 3 4
# 379 "/usr/include/features.h" 2 3 4
# 38 "/usr/include/assert.h" 2 3 4
# 68 "/usr/include/assert.h" 3 4
extern "C" {


extern void __assert_fail (__const char *__assertion, __const char *__file,
      unsigned int __line, __const char *__function)
     throw () __attribute__ ((__noreturn__));


extern void __assert_perror_fail (int __errnum, __const char *__file,
      unsigned int __line,
      __const char *__function)
     throw () __attribute__ ((__noreturn__));




extern void __assert (const char *__assertion, const char *__file, int __line)
     throw () __attribute__ ((__noreturn__));


}
# 45 "/home/cryolite/local/lib/gcc/i486-linux-gnu/4.5.0/include/c++/cassert" 2
3
# 2 "main.cpp" 2

struct X
{
  X(int i) : i_(i) {}
  X(X &&x) : i_(x.i_) { x.i_ = 0; }
  int i_;
};

int main()
{
  X x(42);
  X y = static_cast<X&&>(x);
  ((y.i_ == 42) ? static_cast<void> (0) : __assert_fail ("y.i_ == 42",
"main.cpp", 14, __PRETTY_FUNCTION__));
  ((x.i_ == 0) ? static_cast<void> (0) : __assert_fail ("x.i_ == 0",
"main.cpp", 15, __PRETTY_FUNCTION__));
}

cryol...@thinblue:~/work/gcc_bug/move_on_tribially_copy_constructible$ ./a.out 
a.out: main.cpp:15: int main(): Assertion `x.i_ == 0' failed.
Aborted


-- 
           Summary: [C++0x]wrong overload resolution for copy-initialization
                    from an rvalue
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ai dot azuma at gmail dot com


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

Reply via email to