public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/103295] constexpr std::string does not work for clang
Date: Fri, 19 Nov 2021 18:16:30 +0000	[thread overview]
Message-ID: <bug-103295-4-LBS7mWu5lv@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-103295-4@http.gcc.gnu.org/bugzilla/>

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

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

https://gcc.gnu.org/g:2d76292bd6719d687bc77051da265df8ed7f5a61

commit r12-5413-g2d76292bd6719d687bc77051da265df8ed7f5a61
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Nov 18 10:33:14 2021 +0000

    libstdc++: Begin lifetime of chars in constexpr std::string [PR103295]

    Clang gives errors for constexpr std::string because the memory returned
    by std::allocator<T>::allocate does not contain any objects yet, and
    attempting to set them using char_traits::assign or char_traits::copy
    fails with:

    assignment to object outside its lifetime is not allowed in a constant
expression
                  *__result = *__first;
                            ^
    This adds code to std::char_traits to use std::construct_at to begin
    lifetimes when called during constant evaluation. To support
    specializations of std::basic_string that don't use std::char_traits
    there is now another layer of wrapper around the allocator_traits, so
    that the lifetime of characters is begun as soon as the memory is
    allocated. By doing it in the char traits and allocator traits, the rest
    of basic_string can ignore the problem.

    While modifying char_traits::copy and char_traits::assign to begin
    lifetimes for the constexpr cases, I also replaced their uses of
    std::copy and std::fill_n respectively. That means we don't need
    <bits/stl_algobase.h> for char_traits.

    libstdc++-v3/ChangeLog:

            PR libstdc++/103295
            * include/bits/basic_string.h (_Alloc_traits): Replace typedef
            with struct for C++20 mode.
            * include/bits/basic_string.tcc (_M_replace): Use _Alloc_traits
            for allocation.
            * include/bits/char_traits.h (__gnu_cxx::char_traits::assign):
            Use std::_Construct during constant evaluation.
            (__gnu_cxx::char_traits::assign(CharT*, const CharT*, size_t)):
            Likewise. Replace std::fill_n with memset or manual loop.
            (__gnu_cxx::char_traits::copy): Likewise, replacing std::copy
            with memcpy.
            * include/ext/vstring.h: Include <bits/stl_algobase.h> for
            std::min.
            * include/std/string_view: Likewise.
            *
testsuite/21_strings/basic_string/capacity/char/resize_and_overwrite.cc:
            Add constexpr test.

  parent reply	other threads:[~2021-11-19 18:16 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-17  0:31 [Bug libstdc++/103295] New: " unlvsur at live dot com
2021-11-17  0:31 ` [Bug libstdc++/103295] " unlvsur at live dot com
2021-11-17  0:46 ` unlvsur at live dot com
2021-11-17  0:55 ` pinskia at gcc dot gnu.org
2021-11-17  0:57 ` unlvsur at live dot com
2021-11-17  1:13 ` unlvsur at live dot com
2021-11-17  1:14 ` redi at gcc dot gnu.org
2021-11-17  1:17 ` redi at gcc dot gnu.org
2021-11-17  9:53 ` redi at gcc dot gnu.org
2021-11-17  9:57 ` redi at gcc dot gnu.org
2021-11-17  9:58 ` unlvsur at live dot com
2021-11-17 10:00 ` redi at gcc dot gnu.org
2021-11-17 12:02 ` redi at gcc dot gnu.org
2021-11-17 14:48 ` redi at gcc dot gnu.org
2021-11-17 17:23 ` cvs-commit at gcc dot gnu.org
2021-11-17 17:41 ` redi at gcc dot gnu.org
2021-11-18  0:21 ` redi at gcc dot gnu.org
2021-11-18  0:23 ` unlvsur at live dot com
2021-11-18  7:43 ` rguenth at gcc dot gnu.org
2021-11-19 18:16 ` cvs-commit at gcc dot gnu.org [this message]
2021-11-19 18:50 ` redi at gcc dot gnu.org
2021-11-19 20:19 ` cvs-commit at gcc dot gnu.org
2021-11-19 20:21 ` redi at gcc dot gnu.org
2022-11-11 17:59 ` cvs-commit at gcc dot gnu.org
2022-11-14 18:34 ` cvs-commit at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-103295-4-LBS7mWu5lv@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).