https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80654

            Bug ID: 80654
           Summary: is_trivially_copy_constructible fails with compiler
                    error with vector of uncopyable objects
           Product: gcc
           Version: 7.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bugs at mm dot beanwood.com
  Target Milestone: ---

Created attachment 41332
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41332&action=edit
Pre-processed file that triggers bug

std::is_trivially_copy_constructible<std::vector<nocopy>>::value, where nocopy
is a non-copyable type (e.g. std::unique_ptr), causes a compiler error instead
of producing a value of false as expected.

A practical consequence of this bug is that it is not possible to
move-construct a std::optional<std::vector<nocopy>>, because std::optional uses
std::is_trivially_copy_constructible internally.

Preprocessed file is attached.

Compiler output:

Using built-in specs.
COLLECT_GCC=/usr/local/gcc-7/current.x86_64/bin/g++
COLLECT_LTO_WRAPPER=/usr/local/gcc-7/7.1.0.x86_64/libexec/gcc/x86_64-pc-linux-gnu/7.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /usr/local/gcc-7/tmp-build/gcc-7.1.0/configure
--prefix=/usr/local/gcc-7/7.1.0.x86_64 --enable-languages=c,c++,go
--with-arch-32=i586
Thread model: posix
gcc version 7.1.0 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
'-march=x86-64'
 /usr/local/gcc-7/7.1.0.x86_64/libexec/gcc/x86_64-pc-linux-gnu/7.1.0/cc1plus -E
-quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE bug.cpp -mtune=generic
-march=x86-64 -fpch-preprocess -o bug.ii
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory
"/usr/local/gcc-7/7.1.0.x86_64/lib/gcc/x86_64-pc-linux-gnu/7.1.0/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:

/usr/local/gcc-7/7.1.0.x86_64/lib/gcc/x86_64-pc-linux-gnu/7.1.0/../../../../include/c++/7.1.0

/usr/local/gcc-7/7.1.0.x86_64/lib/gcc/x86_64-pc-linux-gnu/7.1.0/../../../../include/c++/7.1.0/x86_64-pc-linux-gnu

/usr/local/gcc-7/7.1.0.x86_64/lib/gcc/x86_64-pc-linux-gnu/7.1.0/../../../../include/c++/7.1.0/backward
 /usr/local/gcc-7/7.1.0.x86_64/lib/gcc/x86_64-pc-linux-gnu/7.1.0/include
 /usr/local/include
 /usr/local/gcc-7/7.1.0.x86_64/include
 /usr/local/gcc-7/7.1.0.x86_64/lib/gcc/x86_64-pc-linux-gnu/7.1.0/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
'-march=x86-64'
 /usr/local/gcc-7/7.1.0.x86_64/libexec/gcc/x86_64-pc-linux-gnu/7.1.0/cc1plus
-fpreprocessed bug.ii -quiet -dumpbase bug.cpp -mtune=generic -march=x86-64
-auxbase bug -version -o bug.s
GNU C++14 (GCC) version 7.1.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 7.1.0, GMP version 6.0.0, MPFR version
3.1.2-p3, MPC version 1.0.2, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++14 (GCC) version 7.1.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 7.1.0, GMP version 6.0.0, MPFR version
3.1.2-p3, MPC version 1.0.2, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: b73243a43f922df6e56feb5c73c5449a
In file included from
/usr/local/gcc-7/7.1.0.x86_64/include/c++/7.1.0/vector:62:0,
                 from bug.cpp:3:
/usr/local/gcc-7/7.1.0.x86_64/include/c++/7.1.0/bits/stl_construct.h: In
instantiation of 'void std::_Construct(_T1*, _Args&& ...) [with _T1 = nocopy;
_Args = {const nocopy&}]':
/usr/local/gcc-7/7.1.0.x86_64/include/c++/7.1.0/bits/stl_uninitialized.h:83:18:
  required from 'static _ForwardIterator
std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator,
_InputIterator, _ForwardIterator) [with _InputIterator =
__gnu_cxx::__normal_iterator<const nocopy*, std::vector<nocopy> >;
_ForwardIterator = nocopy*; bool _TrivialValueTypes = false]'
/usr/local/gcc-7/7.1.0.x86_64/include/c++/7.1.0/bits/stl_uninitialized.h:134:15:
  required from '_ForwardIterator std::uninitialized_copy(_InputIterator,
_InputIterator, _ForwardIterator) [with _InputIterator =
__gnu_cxx::__normal_iterator<const nocopy*, std::vector<nocopy> >;
_ForwardIterator = nocopy*]'
/usr/local/gcc-7/7.1.0.x86_64/include/c++/7.1.0/bits/stl_uninitialized.h:289:37:
  required from '_ForwardIterator std::__uninitialized_copy_a(_InputIterator,
_InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator =
__gnu_cxx::__normal_iterator<const nocopy*, std::vector<nocopy> >;
_ForwardIterator = nocopy*; _Tp = nocopy]'
/usr/local/gcc-7/7.1.0.x86_64/include/c++/7.1.0/bits/stl_vector.h:331:31:  
required from 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp,
_Alloc>&) [with _Tp = nocopy; _Alloc = std::allocator<nocopy>]'
/usr/local/gcc-7/7.1.0.x86_64/include/c++/7.1.0/type_traits:1409:12:   required
from 'struct std::is_trivially_copy_constructible<std::vector<nocopy> >'
bug.cpp:11:72:   required from here
/usr/local/gcc-7/7.1.0.x86_64/include/c++/7.1.0/bits/stl_construct.h:75:7:
error: use of deleted function 'nocopy::nocopy(const nocopy&)'
     { ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bug.cpp:6:2: note: declared here
  nocopy (const nocopy&) = delete;
  ^~~~~~


bug.cpp:

#include <iostream>
#include <type_traits>
#include <vector>

struct nocopy {
        nocopy (const nocopy&) = delete;
};

int main ()
{
        std::cout <<
std::is_trivially_copy_constructible<std::vector<nocopy>>::value;
        return 0;
}

Reply via email to