public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110900] New: std::string initializes SSO object subfield without making the SSO object active in the union
@ 2023-08-04 15:32 danakj at orodu dot net
  2023-08-04 15:43 ` [Bug c++/110900] " danakj at orodu dot net
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: danakj at orodu dot net @ 2023-08-04 15:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110900
           Summary: std::string initializes SSO object subfield without
                    making the SSO object active in the union
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: danakj at orodu dot net
  Target Milestone: ---

Specific errors by clang:

note: construction of subobject of member '_M_local_buf' of union with no
active member is not allowed in a constant expression

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

Specific error by GCC:

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

Full errors:

Here's the clang 17 error:

/usr/include/c++/12/bits/stl_construct.h:97:14: note: construction of subobject
of member '_M_local_buf' of union with no active member is not allowed in a
constant expression
   97 |     { return ::new((void*)__location)
_Tp(std::forward<_Args>(__args)...); }
      |              ^
/usr/include/c++/12/bits/char_traits.h:262:6: note: in call to
'construct_at(&[]() {
    std::string acc;
    sus::Array<char, 5>::with('a', 'b', 'c', 'd',
'e').into_iter().for_each([&](char v) {
        acc.push_back(v);
    });
    return acc;
}().._M_local_buf[0], acc.._M_local_buf[0])'
  262 |             std::construct_at(__s1 + __i, __s2[__i]);
      |             ^
/usr/include/c++/12/bits/char_traits.h:429:11: note: in call to 'copy(&[]() {
    std::string acc;
    sus::Array<char, 5>::with('a', 'b', 'c', 'd',
'e').into_iter().for_each([&](char v) {
        acc.push_back(v);
    });
    return acc;
}().._M_local_buf[0], &acc.._M_local_buf[0], 6)'
  429 |           return __gnu_cxx::char_traits<char_type>::copy(__s1, __s2,
__n);
      |                  ^
/usr/include/c++/12/bits/basic_string.h:675:6: note: in call to 'copy(&[]() {
    std::string acc;
    sus::Array<char, 5>::with('a', 'b', 'c', 'd',
'e').into_iter().for_each([&](char v) {
        acc.push_back(v);
    });
    return acc;
}().._M_local_buf[0], &acc.._M_local_buf[0], 6)'
  675 |             traits_type::copy(_M_local_buf, __str._M_local_buf,
      |             ^
/home/runner/work/subspace/subspace/sus/iter/iterator_unittest.cc:1864:12:
note: in call to 'basic_string(acc)'
 1864 |     return acc;
      |            ^
/home/runner/work/subspace/subspace/sus/iter/iterator_unittest.cc:1859:17:
note: in call to '[]() {
    std::string acc;
    sus::Array<char, 5>::with('a', 'b', 'c', 'd',
'e').into_iter().for_each([&](char v) {
        acc.push_back(v);
    });
    return acc;
}.operator()()'
 1859 |   static_assert([]() {
      |                 ^

Here's the g++ 13 error:
/home/runner/work/subspace/subspace/sus/iter/iterator_unittest.cc:1792:24:
error: non-constant condition for static assertion
 1787 |   static_assert(sus::Array<char, 5>::with('a', 'b', 'c', 'd', 'e')
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1788 |                     .into_iter()
      |                     ~~~~~~~~~~~~
 1789 |                     .fold(std::string(), [](std::string acc, char v) {
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1790 |                       acc.push_back(v);
      |                       ~~~~~~~~~~~~~~~~~
 1791 |                       return acc;
      |                       ~~~~~~~~~~~
 1792 |                     }) == "abcde");
      |                     ~~~^~~~~~~~~~
/home/runner/work/subspace/subspace/sus/iter/iterator_unittest.cc:1792:35:   in
‘constexpr’ expansion of ‘sus::iter::IteratorBase<Iter, Item>::fold(B, F) &&
[with B = std::__cxx11::basic_string<char>; F =
{anonymous}::Iterator_Fold_Test::TestBody()::<lambda(std::string, char)>; Iter
= sus::containers::ArrayIntoIter<char, 5>; ItemT =
char](std::__cxx11::basic_string<char>(), (<lambda closure
object>{anonymous}::Iterator_Fold_Test::TestBody()::<lambda(std::string,
char)>(), {anonymous}::Iterator_Fold_Test::TestBody()::<lambda(std::string,
char)>()))’
/home/runner/work/subspace/subspace/sus/iter/iterator_unittest.cc:1792:35:   in
‘constexpr’ expansion of ‘sus::fn::call_mut(F&&, Args&& ...) [with F =
{anonymous}::Iterator_Fold_Test::TestBody()::<lambda(std::string, char)>&; Args
= {std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >, char}]((* &
sus::mem::move<std::__cxx11::basic_string<char>&>(init)), (&
sus::mem::move<sus::option::Option<char>&>(o))->sus::option::Option<char>::unwrap())’
/home/runner/work/subspace/subspace/sus/iter/iterator_unittest.cc:1792:35:   in
‘constexpr’ expansion of ‘std::invoke(_Callable&&, _Args&& ...) [with _Callable
= {anonymous}::Iterator_Fold_Test::TestBody()::<lambda(string, char)>&; _Args =
{__cxx11::basic_string<char, char_traits<char>, allocator<char> >, char};
invoke_result_t<_Fn, _Args ...> = __cxx11::basic_string<char>]((* &
sus::mem::forward<std::__cxx11::basic_string<char> >((* & args#0))), (* &
sus::mem::forward<char>((* & args#1))))’
/home/runner/work/subspace/subspace/sus/iter/iterator_unittest.cc:1792:35:   in
‘constexpr’ expansion of ‘std::__invoke(_Callable&&, _Args&& ...) [with
_Callable = {anonymous}::Iterator_Fold_Test::TestBody()::<lambda(string,
char)>&; _Args = {__cxx11::basic_string<char, char_traits<char>,
allocator<char> >, char}; typename __invoke_result<_Functor, _ArgTypes>::type =
__cxx11::basic_string<char>]((* & std::forward<__cxx11::basic_string<char> >((*
& __args#0))), (* & std::forward<char>((* & __args#1))))’
/home/runner/work/subspace/subspace/sus/iter/iterator_unittest.cc:1792:35:   in
‘constexpr’ expansion of ‘std::__invoke_impl(__invoke_other, _Fn&&, _Args&&
...) [with _Res = __cxx11::basic_string<char>; _Fn =
{anonymous}::Iterator_Fold_Test::TestBody()::<lambda(string, char)>&; _Args =
{__cxx11::basic_string<char, char_traits<char>, allocator<char> >, char}]((* &
std::forward<{anonymous}::Iterator_Fold_Test::TestBody()::<lambda(string,
char)>&>((* & __fn))), (* & std::forward<__cxx11::basic_string<char> >((* &
__args#0))), (* & std::forward<char>((* & __args#1))))’
/home/runner/work/subspace/subspace/sus/iter/iterator_unittest.cc:1792:35:   in
‘constexpr’ expansion of ‘std::__cxx11::basic_string<char>((* &
std::forward<__cxx11::basic_string<char> >((* & __args#0))))’
/home/runner/work/subspace/subspace/sus/iter/iterator_unittest.cc:1792:24:
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

I don't have a great minimal repo atm, and I don't have a local machine that
uses libstdc++, but the Iterator.Fold unittest in iterator_unittest.cc is an
example that causes it here:
https://github.com/danakj/subspace/blob/experiment-iters/sus/iter/iterator_unittest.cc#L1787-L1792

With gcc-13:

git clone --recurse-submodules https://github.com/danakj/subspace
cd subspace
git checkout test origin/experiment-iters
CXX=path/to/gcc-13 cmake -B out -DSUBSPACE_BUILD_TESTS=ON
cmake --build out -j 20

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/110900] std::string initializes SSO object subfield without making the SSO object active in the union
  2023-08-04 15:32 [Bug c++/110900] New: std::string initializes SSO object subfield without making the SSO object active in the union danakj at orodu dot net
@ 2023-08-04 15:43 ` danakj at orodu dot net
  2023-08-04 15:52 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: danakj at orodu dot net @ 2023-08-04 15:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from danakj at orodu dot net ---
I am going to try work around this by not using std::string in constant
expressions..

So in the meantime I pushed a branch where this bug will continue to reproduce.

With gcc-13:

git clone --recurse-submodules https://github.com/danakj/subspace
cd subspace
git checkout test origin/libstd-bug-sso
CXX=path/to/gcc-13 cmake -B out -DSUBSPACE_BUILD_TESTS=ON
cmake --build out -j 20

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/110900] std::string initializes SSO object subfield without making the SSO object active in the union
  2023-08-04 15:32 [Bug c++/110900] New: std::string initializes SSO object subfield without making the SSO object active in the union danakj at orodu dot net
  2023-08-04 15:43 ` [Bug c++/110900] " danakj at orodu dot net
@ 2023-08-04 15:52 ` pinskia at gcc dot gnu.org
  2023-08-04 15:55 ` [Bug libstdc++/110900] " pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-04 15:52 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2023-08-04

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Can you please read https://gcc.gnu.org/bugs/ on what we need?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libstdc++/110900] std::string initializes SSO object subfield without making the SSO object active in the union
  2023-08-04 15:32 [Bug c++/110900] New: std::string initializes SSO object subfield without making the SSO object active in the union danakj at orodu dot net
  2023-08-04 15:43 ` [Bug c++/110900] " danakj at orodu dot net
  2023-08-04 15:52 ` pinskia at gcc dot gnu.org
@ 2023-08-04 15:55 ` pinskia at gcc dot gnu.org
  2023-08-04 16:01 ` danakj at orodu dot net
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-04 15:55 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 110158.

*** This bug has been marked as a duplicate of bug 110158 ***

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libstdc++/110900] std::string initializes SSO object subfield without making the SSO object active in the union
  2023-08-04 15:32 [Bug c++/110900] New: std::string initializes SSO object subfield without making the SSO object active in the union danakj at orodu dot net
                   ` (2 preceding siblings ...)
  2023-08-04 15:55 ` [Bug libstdc++/110900] " pinskia at gcc dot gnu.org
@ 2023-08-04 16:01 ` danakj at orodu dot net
  2023-08-04 16:04 ` danakj at orodu dot net
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: danakj at orodu dot net @ 2023-08-04 16:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from danakj at orodu dot net ---
The error message is the same as 110158 but to be clear the std::string is not
in a union. The error message is about the union _inside_ std::string.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libstdc++/110900] std::string initializes SSO object subfield without making the SSO object active in the union
  2023-08-04 15:32 [Bug c++/110900] New: std::string initializes SSO object subfield without making the SSO object active in the union danakj at orodu dot net
                   ` (3 preceding siblings ...)
  2023-08-04 16:01 ` danakj at orodu dot net
@ 2023-08-04 16:04 ` danakj at orodu dot net
  2023-08-04 16:17 ` danakj at orodu dot net
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: danakj at orodu dot net @ 2023-08-04 16:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from danakj at orodu dot net ---
> Can you please read https://gcc.gnu.org/bugs/ on what we need?

Yeah, sorry I can't reproduce this locally on my Mac or Windows machine. It
reproduces on github Linux CI bots, and I have diagnosed it from there.

https://github.com/chromium/subspace/actions/runs/5758764036/job/15611774084?pr=306

This job is using gcc 13.1.0, and it installs libstdc++-13-dev.

Here's the command that fails:

/usr/bin/g++-13  -I/home/runner/work/subspace/subspace
-I/home/runner/work/subspace/subspace/third_party/googletest
-I/home/runner/work/subspace/subspace/third_party/fmt/include -isystem
/home/runner/work/subspace/subspace/third_party/googletest/googletest/include
-isystem /home/runner/work/subspace/subspace/third_party/googletest/googletest
-isystem /usr/include/c++/13 -isystem /usr/include/x86_64-linux-gnu/c++/13
-isystem /usr/include/c++/13/backward -isystem
/usr/lib/gcc/x86_64-linux-gnu/13/include -isystem /usr/local/include -isystem
/usr/include/x86_64-linux-gnu -isystem /usr/include -O3 -DNDEBUG -std=gnu++20
-fno-rtti -Werror -MD -MT
sus/CMakeFiles/subspace_unittests.dir/iter/iterator_unittest.cc.o -MF
sus/CMakeFiles/subspace_unittests.dir/iter/iterator_unittest.cc.o.d -o
sus/CMakeFiles/subspace_unittests.dir/iter/iterator_unittest.cc.o -c
/home/runner/work/subspace/subspace/sus/iter/iterator_unittest.cc

I think it's simplest to just do a git clone and build that though... as I
can't easily minmize this.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libstdc++/110900] std::string initializes SSO object subfield without making the SSO object active in the union
  2023-08-04 15:32 [Bug c++/110900] New: std::string initializes SSO object subfield without making the SSO object active in the union danakj at orodu dot net
                   ` (4 preceding siblings ...)
  2023-08-04 16:04 ` danakj at orodu dot net
@ 2023-08-04 16:17 ` danakj at orodu dot net
  2023-09-29 11:08 ` redi at gcc dot gnu.org
  2023-09-29 15:07 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: danakj at orodu dot net @ 2023-08-04 16:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from danakj at orodu dot net ---
Thanks for the link, I used the godbolt from that bug to set up the right
environment and that let me minimize it. I posted it into the dupe bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libstdc++/110900] std::string initializes SSO object subfield without making the SSO object active in the union
  2023-08-04 15:32 [Bug c++/110900] New: std::string initializes SSO object subfield without making the SSO object active in the union danakj at orodu dot net
                   ` (5 preceding siblings ...)
  2023-08-04 16:17 ` danakj at orodu dot net
@ 2023-09-29 11:08 ` redi at gcc dot gnu.org
  2023-09-29 15:07 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2023-09-29 11:08 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|DUPLICATE                   |---
             Status|RESOLVED                    |NEW

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I don't think this is a duplicate.

This is just a libstdc++ bug, which we have a patch for.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libstdc++/110900] std::string initializes SSO object subfield without making the SSO object active in the union
  2023-08-04 15:32 [Bug c++/110900] New: std::string initializes SSO object subfield without making the SSO object active in the union danakj at orodu dot net
                   ` (6 preceding siblings ...)
  2023-09-29 11:08 ` redi at gcc dot gnu.org
@ 2023-09-29 15:07 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2023-09-29 15:07 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.4

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This should be fixed on trunk now by r14-4334-g28adad7a32ed92

That needs to be backported too.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-09-29 15:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-04 15:32 [Bug c++/110900] New: std::string initializes SSO object subfield without making the SSO object active in the union danakj at orodu dot net
2023-08-04 15:43 ` [Bug c++/110900] " danakj at orodu dot net
2023-08-04 15:52 ` pinskia at gcc dot gnu.org
2023-08-04 15:55 ` [Bug libstdc++/110900] " pinskia at gcc dot gnu.org
2023-08-04 16:01 ` danakj at orodu dot net
2023-08-04 16:04 ` danakj at orodu dot net
2023-08-04 16:17 ` danakj at orodu dot net
2023-09-29 11:08 ` redi at gcc dot gnu.org
2023-09-29 15:07 ` redi at gcc dot gnu.org

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).