public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/111948] New: subrange modifies a const size object
@ 2023-10-24 5:51 hewillk at gmail dot com
2023-10-24 5:55 ` [Bug libstdc++/111948] " hewillk at gmail dot com
` (11 more replies)
0 siblings, 12 replies; 13+ messages in thread
From: hewillk at gmail dot com @ 2023-10-24 5:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111948
Bug ID: 111948
Summary: subrange modifies a const size object
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: hewillk at gmail dot com
Target Milestone: ---
https://godbolt.org/z/Gf4zWP3qT
testcase:
#include <ranges>
constexpr auto r = std::ranges::subrange(std::views::iota(0), 5);
static_assert(std::ranges::distance(r));
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/111948] subrange modifies a const size object
2023-10-24 5:51 [Bug libstdc++/111948] New: subrange modifies a const size object hewillk at gmail dot com
@ 2023-10-24 5:55 ` hewillk at gmail dot com
2023-10-24 16:15 ` redi at gcc dot gnu.org
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: hewillk at gmail dot com @ 2023-10-24 5:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111948
--- Comment #1 from 康桓瑋 <hewillk at gmail dot com> ---
This is the cause:
constexpr
subrange(__detail::__convertible_to_non_slicing<_It> auto __i, _Sent __s,
__size_type __n)
noexcept(is_nothrow_constructible_v<_It, decltype(__i)>
&& is_nothrow_constructible_v<_Sent, _Sent&>)
requires (_Kind == subrange_kind::sized)
: _M_begin(std::move(__i)), _M_end(__s)
{
if constexpr (_S_store_size)
_M_size._M_size = __n;
}
_M_size._M_size in the function body is already const.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/111948] subrange modifies a const size object
2023-10-24 5:51 [Bug libstdc++/111948] New: subrange modifies a const size object hewillk at gmail dot com
2023-10-24 5:55 ` [Bug libstdc++/111948] " hewillk at gmail dot com
@ 2023-10-24 16:15 ` redi at gcc dot gnu.org
2023-10-24 16:20 ` redi at gcc dot gnu.org
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2023-10-24 16:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111948
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to 康桓瑋 from comment #1)
> _M_size._M_size in the function body is already const.
It shouldn't be. Is that a compiler bug?
Clang compiles the same libstdc++ code without problems.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/111948] subrange modifies a const size object
2023-10-24 5:51 [Bug libstdc++/111948] New: subrange modifies a const size object hewillk at gmail dot com
2023-10-24 5:55 ` [Bug libstdc++/111948] " hewillk at gmail dot com
2023-10-24 16:15 ` redi at gcc dot gnu.org
@ 2023-10-24 16:20 ` redi at gcc dot gnu.org
2023-10-24 16:30 ` redi at gcc dot gnu.org
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2023-10-24 16:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111948
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This compiles OK:
namespace std::ranges
{
template<class T, bool Sized = true>
class subrange
{
private:
template<typename, bool = Sized>
struct _Size
{ };
template<typename U>
struct _Size<U, true>
{ U _M_size; };
[[no_unique_address]] _Size<unsigned> _M_size = {};
public:
constexpr
subrange(const T*, unsigned __n)
{
if constexpr (Sized)
_M_size._M_size = __n;
}
constexpr unsigned size() const
{
if constexpr (Sized)
return _M_size._M_size;
else
return 0;
}
};
template<class T>
constexpr int distance(subrange<T, true> const& s)
{ return s.size(); }
} // std::ranges
constexpr int i = 0;
constexpr auto r = std::ranges::subrange(&i, 1);
static_assert(std::ranges::distance(r));
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/111948] subrange modifies a const size object
2023-10-24 5:51 [Bug libstdc++/111948] New: subrange modifies a const size object hewillk at gmail dot com
` (2 preceding siblings ...)
2023-10-24 16:20 ` redi at gcc dot gnu.org
@ 2023-10-24 16:30 ` redi at gcc dot gnu.org
2023-10-24 20:37 ` hewillk at gmail dot com
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2023-10-24 16:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111948
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2023-10-24
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This patch makes the testcase compile, but I still think it's a compiler bug
not a library bug:
--- a/libstdc++-v3/include/bits/ranges_util.h
+++ b/libstdc++-v3/include/bits/ranges_util.h
@@ -267,13 +267,21 @@ namespace ranges
using __size_type
= __detail::__make_unsigned_like_t<iter_difference_t<_It>>;
- template<typename, bool = _S_store_size>
+ template<typename _Tp, bool = _S_store_size>
struct _Size
- { };
+ {
+ [[__gnu__::__always_inline__]]
+ constexpr _Size(_Tp) { }
+ };
template<typename _Tp>
struct _Size<_Tp, true>
- { _Tp _M_size; };
+ {
+ [[__gnu__::__always_inline__]]
+ constexpr _Size(_Tp __s) : _M_size(__s) { }
+
+ _Tp _M_size;
+ };
[[no_unique_address]] _Size<__size_type> _M_size = {};
@@ -294,11 +302,8 @@ namespace ranges
noexcept(is_nothrow_constructible_v<_It, decltype(__i)>
&& is_nothrow_constructible_v<_Sent, _Sent&>)
requires (_Kind == subrange_kind::sized)
- : _M_begin(std::move(__i)), _M_end(__s)
- {
- if constexpr (_S_store_size)
- _M_size._M_size = __n;
- }
+ : _M_begin(std::move(__i)), _M_end(__s), _M_size(__n)
+ { }
template<__detail::__different_from<subrange> _Rng>
requires borrowed_range<_Rng>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/111948] subrange modifies a const size object
2023-10-24 5:51 [Bug libstdc++/111948] New: subrange modifies a const size object hewillk at gmail dot com
` (3 preceding siblings ...)
2023-10-24 16:30 ` redi at gcc dot gnu.org
@ 2023-10-24 20:37 ` hewillk at gmail dot com
2023-11-08 11:35 ` de34 at live dot cn
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: hewillk at gmail dot com @ 2023-10-24 20:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111948
--- Comment #5 from 康桓瑋 <hewillk at gmail dot com> ---
It shouldn't be. Is that a compiler bug?
Clang compiles the same libstdc++ code without problems.(In reply to Jonathan
Wakely from comment #2)
> (In reply to 康桓瑋 from comment #1)
> > _M_size._M_size in the function body is already const.
>
> It shouldn't be. Is that a compiler bug?
>
> Clang compiles the same libstdc++ code without problems.
Sorry, I didn't delve into whether this was a bug in libstdc++ or the compiler.
At the moment it seems this is a compiler problem.
https://godbolt.org/z/ronn4exhG
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/111948] subrange modifies a const size object
2023-10-24 5:51 [Bug libstdc++/111948] New: subrange modifies a const size object hewillk at gmail dot com
` (4 preceding siblings ...)
2023-10-24 20:37 ` hewillk at gmail dot com
@ 2023-11-08 11:35 ` de34 at live dot cn
2023-11-08 12:01 ` redi at gcc dot gnu.org
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: de34 at live dot cn @ 2023-11-08 11:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111948
Jiang An <de34 at live dot cn> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |de34 at live dot cn
--- Comment #6 from Jiang An <de34 at live dot cn> ---
This is certainly a compiler bug. I've reduced it and reported Bug 112439.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/111948] subrange modifies a const size object
2023-10-24 5:51 [Bug libstdc++/111948] New: subrange modifies a const size object hewillk at gmail dot com
` (5 preceding siblings ...)
2023-11-08 11:35 ` de34 at live dot cn
@ 2023-11-08 12:01 ` redi at gcc dot gnu.org
2023-11-23 14:40 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2023-11-08 12:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111948
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Thanks! I briefly tried but failed to reproduce it in a reduced example.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/111948] subrange modifies a const size object
2023-10-24 5:51 [Bug libstdc++/111948] New: subrange modifies a const size object hewillk at gmail dot com
` (6 preceding siblings ...)
2023-11-08 12:01 ` redi at gcc dot gnu.org
@ 2023-11-23 14:40 ` redi at gcc dot gnu.org
2023-12-05 23:35 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2023-11-23 14:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111948
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Depends on| |112439
Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
Status|NEW |ASSIGNED
See Also|https://gcc.gnu.org/bugzill |
|a/show_bug.cgi?id=112439 |
Target Milestone|--- |13.3
--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This hasn't been fixed yet, so I'll add the library workaround.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112439
[Bug 112439] [13/14 Regression] Modification of a member overlapping with a
[[no_unique_address]] member in the constructor is incorrectly rejected in
constant evaluation
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/111948] subrange modifies a const size object
2023-10-24 5:51 [Bug libstdc++/111948] New: subrange modifies a const size object hewillk at gmail dot com
` (7 preceding siblings ...)
2023-11-23 14:40 ` redi at gcc dot gnu.org
@ 2023-12-05 23:35 ` cvs-commit at gcc dot gnu.org
2023-12-06 14:44 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-05 23:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111948
--- Comment #9 from GCC 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:08448dc146b6dd32383d64ab491a594d41f62aaa
commit r14-6200-g08448dc146b6dd32383d64ab491a594d41f62aaa
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Oct 24 20:15:12 2023 +0100
libstdc++: Add workaround to std::ranges::subrange [PR111948]
libstdc++-v3/ChangeLog:
PR libstdc++/111948
* include/bits/ranges_util.h (subrange): Add constructor to
_Size to aoid setting member in constructor.
* testsuite/std/ranges/subrange/111948.cc: New test.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/111948] subrange modifies a const size object
2023-10-24 5:51 [Bug libstdc++/111948] New: subrange modifies a const size object hewillk at gmail dot com
` (8 preceding siblings ...)
2023-12-05 23:35 ` cvs-commit at gcc dot gnu.org
@ 2023-12-06 14:44 ` cvs-commit at gcc dot gnu.org
2023-12-06 14:46 ` redi at gcc dot gnu.org
2024-02-02 16:12 ` jason at gcc dot gnu.org
11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-06 14:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111948
--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:
https://gcc.gnu.org/g:be26992b3115b95189ac02fcf25902cb5430c0e1
commit r13-8133-gbe26992b3115b95189ac02fcf25902cb5430c0e1
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Tue Oct 24 20:15:12 2023 +0100
libstdc++: Add workaround to std::ranges::subrange [PR111948]
libstdc++-v3/ChangeLog:
PR libstdc++/111948
* include/bits/ranges_util.h (subrange): Add constructor to
_Size to avoid setting member in constructor.
* testsuite/std/ranges/subrange/111948.cc: New test.
(cherry picked from commit 08448dc146b6dd32383d64ab491a594d41f62aaa)
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/111948] subrange modifies a const size object
2023-10-24 5:51 [Bug libstdc++/111948] New: subrange modifies a const size object hewillk at gmail dot com
` (9 preceding siblings ...)
2023-12-06 14:44 ` cvs-commit at gcc dot gnu.org
@ 2023-12-06 14:46 ` redi at gcc dot gnu.org
2024-02-02 16:12 ` jason at gcc dot gnu.org
11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2023-12-06 14:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111948
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 13.3, thanks for the report.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/111948] subrange modifies a const size object
2023-10-24 5:51 [Bug libstdc++/111948] New: subrange modifies a const size object hewillk at gmail dot com
` (10 preceding siblings ...)
2023-12-06 14:46 ` redi at gcc dot gnu.org
@ 2024-02-02 16:12 ` jason at gcc dot gnu.org
11 siblings, 0 replies; 13+ messages in thread
From: jason at gcc dot gnu.org @ 2024-02-02 16:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111948
Bug 111948 depends on bug 112439, which changed state.
Bug 112439 Summary: [13/14 Regression] Modification of a member overlapping with a [[no_unique_address]] member in the constructor is incorrectly rejected in constant evaluation since r13-160-g967cdbe6629653
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112439
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2024-02-02 16:12 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-24 5:51 [Bug libstdc++/111948] New: subrange modifies a const size object hewillk at gmail dot com
2023-10-24 5:55 ` [Bug libstdc++/111948] " hewillk at gmail dot com
2023-10-24 16:15 ` redi at gcc dot gnu.org
2023-10-24 16:20 ` redi at gcc dot gnu.org
2023-10-24 16:30 ` redi at gcc dot gnu.org
2023-10-24 20:37 ` hewillk at gmail dot com
2023-11-08 11:35 ` de34 at live dot cn
2023-11-08 12:01 ` redi at gcc dot gnu.org
2023-11-23 14:40 ` redi at gcc dot gnu.org
2023-12-05 23:35 ` cvs-commit at gcc dot gnu.org
2023-12-06 14:44 ` cvs-commit at gcc dot gnu.org
2023-12-06 14:46 ` redi at gcc dot gnu.org
2024-02-02 16:12 ` jason 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).