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

--- Comment #2 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:ead408529d7a69873a7c14dd12fa043cd5862253

commit r12-3147-gead408529d7a69873a7c14dd12fa043cd5862253
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Wed Aug 25 21:10:48 2021 +0100

    libstdc++: Fix conditions for optimizing uninitialized algos [PR102064]

    While laying some groundwork for constexpr std::vector, I noticed some
    bugs in the std::uninitialized_xxx algorithms. The conditions being
    checked for optimizing trivial cases were not quite right, as shown in
    the examples in the PR.

    This consolidates the checks into a single macro. The macro has
    appropriate definitions for C++98 or for later standards, to avoid a #if
    everywhere the checks are used. For C++11 and later the check makes a
    call to a new function doing a static_assert to ensure we don't use
    assignment in cases where construction would have been invalid.
    Extracting that check to a separate function will be useful for
    constexpr std::vector, as that can't use std::uninitialized_copy
    directly because it isn't constexpr).

    The consolidated checks mean that some slight variations in static
    assert message are gone, as there is only one place that does the assert
    now. That required adjusting some tests. As part of that the redundant
    89164_c++17.cc test was merged into 89164.cc which is compiled as C++17
    by default now, but can also use other -std options if the
    C++17-specific error is made conditional with a target selector.

    Signed-off-by: Jonathan Wakely <jwak...@redhat.com>

    libstdc++-v3/ChangeLog:

            PR libstdc++/102064
            * include/bits/stl_uninitialized.h (_GLIBCXX_USE_ASSIGN_FOR_INIT):
            Define macro to check conditions for optimizing trivial cases.
            (__check_constructible): New function to do static assert.
            (uninitialized_copy, uninitialized_fill, uninitialized_fill_n):
            Use new macro.
            * testsuite/20_util/specialized_algorithms/uninitialized_copy/1.cc:
            Adjust dg-error pattern.
            * testsuite/23_containers/vector/cons/89164.cc: Likewise. Add
            C++17-specific checks from 89164_c++17.cc.
            * testsuite/23_containers/vector/cons/89164_c++17.cc: Removed.
            *
testsuite/20_util/specialized_algorithms/uninitialized_copy/102064.cc:
            New test.
            *
testsuite/20_util/specialized_algorithms/uninitialized_copy_n/102064.cc:
            New test.
            *
testsuite/20_util/specialized_algorithms/uninitialized_fill/102064.cc:
            New test.
            *
testsuite/20_util/specialized_algorithms/uninitialized_fill_n/102064.cc:
            New test.

Reply via email to