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

            Bug ID: 111258
           Summary: std::string cannot to be moved in constant evaluated
                    expression
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kisses07_rupee at icloud dot com
  Target Milestone: ---

c++20 std::string's destructor fails after move:

#include <string>

using namespace std::literals;

constexpr auto foo(auto a) {
    auto b = std::move(a);
    return b[1];
}

int main(int,char**) {
    static_assert( foo("hello"s) == 'e' );
    return 0;
}

fails with:
<source>: In function 'int main(int, char**)':
<source>:11:34: error: non-constant condition for static assertion
   11 |     static_assert( foo("hello"s) == 'e' );
      |                    ~~~~~~~~~~~~~~^~~~~~
<source>:11:23:   in 'constexpr' expansion of
'foo<std::__cxx11::basic_string<char>
>(std::literals::string_literals::operator""s(const char*, std::size_t)(5))'
<source>:11:42:   in 'constexpr' expansion of
'std::__cxx11::basic_string<char>((* &
std::move<__cxx11::basic_string<char>&>(a)))'
<source>:11:34: error: accessing 'std::__cxx11::basic_string<char>::<unnamed
union>::_M_allocated_capacity' member instead of initialized
'std::__cxx11::basic_string<char>::<unnamed union>::_M_local_buf' member in
constant expression
Compiler returned: 1

online demo: https://godbolt.org/z/Tz7MK58f1

it seems it's affecting on bug 103924

Reply via email to