public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/100147] New: libstdc++-v3/include/bits/gslice.h:170: missing check for assignment to self ?
@ 2021-04-19 9:59 dcb314 at hotmail dot com
2021-04-19 10:12 ` [Bug libstdc++/100147] " redi at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: dcb314 at hotmail dot com @ 2021-04-19 9:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100147
Bug ID: 100147
Summary: libstdc++-v3/include/bits/gslice.h:170: missing check
for assignment to self ?
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: dcb314 at hotmail dot com
Target Milestone: ---
Static analyser cppcheck says:
libstdc++-v3/include/bits/gslice.h:170:11: warning: 'operator=' should check
for assignment to self to avoid problems with dynamic memory.
[operatorEqToSelf]
Source code is
inline gslice&
gslice::operator=(const gslice& __g)
{
if (__g._M_index)
__g._M_index->_M_increment_use();
if (_M_index && _M_index->_M_decrement_use() == 0)
delete _M_index;
_M_index = __g._M_index;
return *this;
}
It certainly would be standard C++ practice to make the check for assignment
to self.
Perhaps there is a good reason why it isn't done here.
If so, there may be some value in documenting why.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/100147] libstdc++-v3/include/bits/gslice.h:170: missing check for assignment to self ?
2021-04-19 9:59 [Bug libstdc++/100147] New: libstdc++-v3/include/bits/gslice.h:170: missing check for assignment to self ? dcb314 at hotmail dot com
@ 2021-04-19 10:12 ` redi at gcc dot gnu.org
2024-02-03 11:16 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-04-19 10:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100147
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's obviously safe for self-assignment.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/100147] libstdc++-v3/include/bits/gslice.h:170: missing check for assignment to self ?
2021-04-19 9:59 [Bug libstdc++/100147] New: libstdc++-v3/include/bits/gslice.h:170: missing check for assignment to self ? dcb314 at hotmail dot com
2021-04-19 10:12 ` [Bug libstdc++/100147] " redi at gcc dot gnu.org
@ 2024-02-03 11:16 ` redi at gcc dot gnu.org
2024-02-08 21:49 ` cvs-commit at gcc dot gnu.org
2024-02-08 21:50 ` redi at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2024-02-03 11:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100147
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2024-02-03
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Due to the aliasing rules for valarrays and slices, I think it would be
undefined to assign a gslice to itself. So the overhead of checking for
something that should never happen to avoid a redundant increment/decrement
pair is a poor trade off. Letting it redundantly inc/dec the reference count is
safe and correct for self-assignment, without adding a branch to handle
"impossible" cases.
I suppose we can add a comment to that effect.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/100147] libstdc++-v3/include/bits/gslice.h:170: missing check for assignment to self ?
2021-04-19 9:59 [Bug libstdc++/100147] New: libstdc++-v3/include/bits/gslice.h:170: missing check for assignment to self ? dcb314 at hotmail dot com
2021-04-19 10:12 ` [Bug libstdc++/100147] " redi at gcc dot gnu.org
2024-02-03 11:16 ` redi at gcc dot gnu.org
@ 2024-02-08 21:49 ` cvs-commit at gcc dot gnu.org
2024-02-08 21:50 ` redi at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-08 21:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100147
--- Comment #3 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:4e5dc6d9686a34d446147b923fe838389758a512
commit r14-8890-g4e5dc6d9686a34d446147b923fe838389758a512
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Sun Feb 4 21:39:11 2024 +0000
libstdc++: Add comment to gslice::operator=(const gslice&) [PR100147]
There's no need to check for self-assignment here, it would just add
extra code for an unlikely case. Add a comment saying so.
libstdc++-v3/ChangeLog:
PR libstdc++/100147
* include/bits/gslice.h (operator=): Add comment about lack of
self-assignment check.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/100147] libstdc++-v3/include/bits/gslice.h:170: missing check for assignment to self ?
2021-04-19 9:59 [Bug libstdc++/100147] New: libstdc++-v3/include/bits/gslice.h:170: missing check for assignment to self ? dcb314 at hotmail dot com
` (2 preceding siblings ...)
2024-02-08 21:49 ` cvs-commit at gcc dot gnu.org
@ 2024-02-08 21:50 ` redi at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2024-02-08 21:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100147
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |14.0
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-02-08 21:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-19 9:59 [Bug libstdc++/100147] New: libstdc++-v3/include/bits/gslice.h:170: missing check for assignment to self ? dcb314 at hotmail dot com
2021-04-19 10:12 ` [Bug libstdc++/100147] " redi at gcc dot gnu.org
2024-02-03 11:16 ` redi at gcc dot gnu.org
2024-02-08 21:49 ` cvs-commit at gcc dot gnu.org
2024-02-08 21:50 ` 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).