[Bug libstdc++/100475] semiregular-box's constructor uses wrong list-initialization

2021-10-12 Thread ppalka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100475

Patrick Palka  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED
   Target Milestone|--- |11.3

--- Comment #10 from Patrick Palka  ---
Fixed for GCC 11.3 and 12.

(10.4 doesn't implement this partial specialization of __box)

[Bug libstdc++/100475] semiregular-box's constructor uses wrong list-initialization

2021-10-12 Thread ppalka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100475

Patrick Palka  changed:

   What|Removed |Added

   Target Milestone|11.3|11.2

--- Comment #11 from Patrick Palka  ---
Er, this was actually already fixed for 11.2

[Bug libstdc++/100475] semiregular-box's constructor uses wrong list-initialization

2021-05-07 Thread ppalka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100475

Patrick Palka  changed:

   What|Removed |Added

   Last reconfirmed||2021-05-07
   Assignee|unassigned at gcc dot gnu.org  |ppalka at gcc dot 
gnu.org
 Status|UNCONFIRMED |ASSIGNED
 Ever confirmed|0   |1
 CC||ppalka at gcc dot gnu.org

--- Comment #1 from Patrick Palka  ---
Confirmed.

[Bug libstdc++/100475] semiregular-box's constructor uses wrong list-initialization

2021-05-07 Thread hewillk at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100475

--- Comment #2 from 康桓瑋  ---
Reduced example:

#include 

struct S {
  S() = default;
  S(int, int) {}
  S(std::initializer_list) = delete;
};

std::ranges::single_view single(std::in_place, 0, 0);

https://godbolt.org/z/d1bE8sPdd

[Bug libstdc++/100475] semiregular-box's constructor uses wrong list-initialization

2021-05-07 Thread hewillk at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100475

--- Comment #3 from 康桓瑋  ---
Also, the operator->() simply uses operator& instead of std::__addressof.

https://godbolt.org/z/zfGnEoePG

[Bug libstdc++/100475] semiregular-box's constructor uses wrong list-initialization

2021-05-07 Thread hewillk at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100475

--- Comment #4 from 康桓瑋  ---
(In reply to 康桓瑋 from comment #3)
> Also, the operator->() simply uses operator& instead of std::__addressof.
> 
> https://godbolt.org/z/zfGnEoePG

Another issue is that the has_value() of this specialization will always return
true, which will make the precondition __glibcxx_assert(_M_pred.has_value())
for filter_view's begin() almost useless.

Although it is not clear why semiregular-box is partial specialization in
gcc-11, it is obvious that this needs to be treated with care.

[Bug libstdc++/100475] semiregular-box's constructor uses wrong list-initialization

2021-05-11 Thread ppalka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100475

--- Comment #5 from Patrick Palka  ---
(In reply to 康桓瑋 from comment #4)
> (In reply to 康桓瑋 from comment #3)
> > Also, the operator->() simply uses operator& instead of std::__addressof.
> > 
> > https://godbolt.org/z/zfGnEoePG

Good catch, thanks.

> 
> Another issue is that the has_value() of this specialization will always
> return true, which will make the precondition
> __glibcxx_assert(_M_pred.has_value()) for filter_view's begin() almost
> useless.

That's fine I suppose, the assert will just be a no-op in that case.

> 
> Although it is not clear why semiregular-box is partial specialization in
> gcc-11, it is obvious that this needs to be treated with care.

The advantage of the partial specialization is that it's space-optimal whereas
the primary template is not, due to its use of std::optional.

[Bug libstdc++/100475] semiregular-box's constructor uses wrong list-initialization

2021-05-17 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100475

--- Comment #6 from CVS Commits  ---
The master branch has been updated by Patrick Palka :

https://gcc.gnu.org/g:fe993b469c528230d9a01e1ae2208610f960dd9f

commit r12-856-gfe993b469c528230d9a01e1ae2208610f960dd9f
Author: Patrick Palka 
Date:   Tue May 18 00:28:44 2021 -0400

libstdc++: Fix up semiregular-box partial specialization [PR100475]

This makes the in-place constructor of our partial specialization of
__box for already-semiregular types perform direct-non-list-initialization
(in accordance with the specification of the primary template), and
additionally makes the member function data() use std::__addressof.

libstdc++-v3/ChangeLog:

PR libstdc++/100475
* include/std/ranges (__box::__box): Use non-list-initialization
in member initializer list of in-place constructor of the
partial specialization for semiregular types.
(__box::operator->): Use std::__addressof.
* testsuite/std/ranges/adaptors/detail/semiregular_box.cc
(test02): New test.
* testsuite/std/ranges/single_view.cc (test04): New test.

[Bug libstdc++/100475] semiregular-box's constructor uses wrong list-initialization

2021-06-06 Thread hewillk at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100475

--- Comment #7 from 康桓瑋  ---
(In reply to CVS Commits from comment #6)
> The master branch has been updated by Patrick Palka :
> 
> https://gcc.gnu.org/g:fe993b469c528230d9a01e1ae2208610f960dd9f
> 
> commit r12-856-gfe993b469c528230d9a01e1ae2208610f960dd9f
> Author: Patrick Palka 
> Date:   Tue May 18 00:28:44 2021 -0400
> 
> libstdc++: Fix up semiregular-box partial specialization [PR100475]
> 
> This makes the in-place constructor of our partial specialization of
> __box for already-semiregular types perform
> direct-non-list-initialization
> (in accordance with the specification of the primary template), and
> additionally makes the member function data() use std::__addressof.
> 
> libstdc++-v3/ChangeLog:
> 
> PR libstdc++/100475
> * include/std/ranges (__box::__box): Use non-list-initialization
> in member initializer list of in-place constructor of the
> partial specialization for semiregular types.
> (__box::operator->): Use std::__addressof.
> * testsuite/std/ranges/adaptors/detail/semiregular_box.cc
> (test02): New test.
> * testsuite/std/ranges/single_view.cc (test04): New test.


I think that even list-initialization with a single parameter should be changed
to direct-non-list-initialization to avoid bugs in some uncommon situations.



#include 

struct S {
  S() = default;
  S(std::initializer_list) = delete;
  S(const S&) {}
};
S obj;

auto l = std::initializer_list{{}, {}};
auto x = std::views::single(obj);
auto y = std::views::single(std::move(l));

https://godbolt.org/z/7nePj6Y57

[Bug libstdc++/100475] semiregular-box's constructor uses wrong list-initialization

2021-06-07 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100475

--- Comment #8 from Jonathan Wakely  ---
We should almost never use list-init in the library unless the standard
explicitly specifies it. Even if the standard specifies it, we should consider
whether that's a defect in the standard. Uniform init is uniformly bad.

[Bug libstdc++/100475] semiregular-box's constructor uses wrong list-initialization

2021-06-13 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100475

--- Comment #9 from CVS Commits  ---
The releases/gcc-11 branch has been updated by Patrick Palka
:

https://gcc.gnu.org/g:258aedd9ad1ea4597528632e93dee860acc2eaf5

commit r11-8566-g258aedd9ad1ea4597528632e93dee860acc2eaf5
Author: Patrick Palka 
Date:   Tue May 18 00:28:44 2021 -0400

libstdc++: Fix up semiregular-box partial specialization [PR100475]

This makes the in-place constructor of our partial specialization of
__box for already-semiregular types perform direct-non-list-initialization
(in accordance with the specification of the primary template), and
additionally makes the member function data() use std::__addressof.

libstdc++-v3/ChangeLog:

PR libstdc++/100475
* include/std/ranges (__box::__box): Use non-list-initialization
in member initializer list of in-place constructor of the
partial specialization for semiregular types.
(__box::operator->): Use std::__addressof.
* testsuite/std/ranges/adaptors/detail/semiregular_box.cc
(test02): New test.
* testsuite/std/ranges/single_view.cc (test04): New test.

(cherry picked from commit fe993b469c528230d9a01e1ae2208610f960dd9f)