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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <r...@gcc.gnu.org>:

https://gcc.gnu.org/g:462f6c2041fad058abcdd5122e99a024f69a39d5

commit r10-6999-g462f6c2041fad058abcdd5122e99a024f69a39d5
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Tue Mar 3 21:38:57 2020 +0000

    libstdc++: Workaround is_trivially_copyable<volatile T> (PR 94013)

    Several algorithms check the is_trivially_copyable trait to decide
    whether to dispatch to memmove or memcmp as an optimization. Since
    r271435 (CWG DR 2094) the trait is true for volatile-qualified scalars,
    but we can't use memmove or memcmp when the type is volatile. We need to
    also check for volatile types.

    This is complicated by the fact that in C++20 (but not earlier standards)
    iterator_traits<volatile T*>::value_type is T, so we can't just check
    whether the value_type is volatile.

    The solution in this patch is to introduce new traits __memcpyable and
    __memcmpable which combine into a single trait the checks for pointers,
    the value types being the same, and the type being trivially copyable
    but not volatile-qualified.

        PR libstdc++/94013
        * include/bits/cpp_type_traits.h (__memcpyable, __memcmpable): New
        traits to control when to use memmove and memcmp optimizations.
        (__is_nonvolatile_trivially_copyable): New helper trait.
        * include/bits/ranges_algo.h (__lexicographical_compare_fn): Do not
        use memcmp optimization with volatile data.
        * include/bits/ranges_algobase.h (__equal_fn): Use __memcmpable.
        (__copy_or_move, __copy_or_move_backward): Use __memcpyable.
        * include/bits/stl_algobase.h (__copy_move_a2): Use __memcpyable.
        (__copy_move_backward_a2): Likewise.
        (__equal_aux1): Use __memcmpable.
        (__lexicographical_compare_aux): Do not use memcmp optimization with
        volatile data.
        * testsuite/25_algorithms/copy/94013.cc: New test.
        * testsuite/25_algorithms/copy_backward/94013.cc: New test.
        * testsuite/25_algorithms/equal/94013.cc: New test.
        * testsuite/25_algorithms/fill/94013.cc: New test.
        * testsuite/25_algorithms/lexicographical_compare/94013.cc: New test.
        * testsuite/25_algorithms/move/94013.cc: New test.
        * testsuite/25_algorithms/move_backward/94013.cc: New test.

Reply via email to