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

            Bug ID: 94013
           Summary: [10 Regression] library algos need to work around cwg
                    2094
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

r271435 changed is_trivially_copyable_v<volatile int> to true, which breaks
this:

#include <algorithm>
int main()
{
  volatile int i = 0;
  volatile int j;
  std::copy(&i, &i + 1, &j);
}

In file included from /home/jwakely/gcc/10/include/c++/10.0.1/algorithm:61,
                 from vol.cc:1:
/home/jwakely/gcc/10/include/c++/10.0.1/bits/stl_algobase.h: In instantiation
of 'static _Tp* std::__copy_move<_IsMove, true,
std::random_access_iterator_tag>::__copy_m(const _Tp*, const _Tp*, _Tp*) [with
_Tp = volatile int; bool _IsMove = false]':
/home/jwakely/gcc/10/include/c++/10.0.1/bits/stl_algobase.h:475:30:   required
from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II =
volatile int*; _OI = volatile int*]'
/home/jwakely/gcc/10/include/c++/10.0.1/bits/stl_algobase.h:509:42:   required
from '_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II =
volatile int*; _OI = volatile int*]'
/home/jwakely/gcc/10/include/c++/10.0.1/bits/stl_algobase.h:517:31:   required
from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II =
volatile int*; _OI = volatile int*]'
/home/jwakely/gcc/10/include/c++/10.0.1/bits/stl_algobase.h:572:7:   required
from '_OI std::copy(_II, _II, _OI) [with _II = volatile int*; _OI = volatile
int*]'
vol.cc:7:27:   required from here
/home/jwakely/gcc/10/include/c++/10.0.1/bits/stl_algobase.h:423:24: error:
invalid conversion from 'volatile void*' to 'void*' [-fpermissive]
  423 |      __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |                        ^~~~~~~~
      |                        |
      |                        volatile void*
<built-in>: note:   initializing argument 1 of 'void* __builtin_memmove(void*,
const void*, long unsigned int)'
/home/jwakely/gcc/10/include/c++/10.0.1/bits/stl_algobase.h:423:34: error:
invalid conversion from 'const volatile void*' to 'const void*' [-fpermissive]
  423 |      __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |                                  ^~~~~~~
      |                                  |
      |                                  const volatile void*
<built-in>: note:   initializing argument 2 of 'void* __builtin_memmove(void*,
const void*, long unsigned int)'


It's no longer possible to use is_trivially_copyable to tell if something can
be copied with memcpy.

There are probably similar issues with the algos using memcmp (std::equal,
std::lexicographical_compare).

Reply via email to