public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/42943] New: std::partial_sum performs improper casts
@ 2010-02-03 3:15 potswa at mac dot com
2010-02-03 3:31 ` [Bug libstdc++/42943] " paolo dot carlini at oracle dot com
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: potswa at mac dot com @ 2010-02-03 3:15 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1561 bytes --]
std::partial_sum( first, last, result, binary_op ) (§26.4.2) is defined as
binary_op(binary_op(..., binary_op(*first, *(first + 1)),...),
*(first + (i - result)))
Ambiguity notwithstanding (what is the first value??), the result of each
application is clearly supposed to be forwarded to the next.
However, the current implementation does this:
typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
__value = __binary_op(__value, *__first);
This would be safer:
typedef typename _BinaryOperation::result_type _ValueType;
Copying *first to *result would require an implicit cast from
iterator_traits<_InputIterator>::value_type to _BinaryOperation::result_type,
which is not required. Since an additional __binary_op() is not allowed,
_ValueType __value( *__first );
might be the best compromise. Anyway, implicit casting the result_type to the
input iterator type, as the current implementation does, seems much riskier.
The motivating case is pretty simple: I was specifically trying to avoid
overflow by summing a std::vector<char> into a std::vector<int>. Furthermore,
std::accumulate does correctly avoid overflow.
--
Summary: std::partial_sum performs improper casts
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: potswa at mac dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42943
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libstdc++/42943] std::partial_sum performs improper casts
2010-02-03 3:15 [Bug libstdc++/42943] New: std::partial_sum performs improper casts potswa at mac dot com
@ 2010-02-03 3:31 ` paolo dot carlini at oracle dot com
2010-02-04 18:36 ` paolo dot carlini at oracle dot com
2010-02-04 18:36 ` paolo dot carlini at oracle dot com
2 siblings, 0 replies; 4+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-02-03 3:31 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from paolo dot carlini at oracle dot com 2010-02-03 03:30 -------
As far as I can tell, we are already implementing correctly the resolution of
DR 539, I went through it one month ago or so:
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#539
If you disagree, please re-open. Thanks.
--
paolo dot carlini at oracle dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42943
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libstdc++/42943] std::partial_sum performs improper casts
2010-02-03 3:15 [Bug libstdc++/42943] New: std::partial_sum performs improper casts potswa at mac dot com
2010-02-03 3:31 ` [Bug libstdc++/42943] " paolo dot carlini at oracle dot com
@ 2010-02-04 18:36 ` paolo dot carlini at oracle dot com
2010-02-04 18:36 ` paolo dot carlini at oracle dot com
2 siblings, 0 replies; 4+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-02-04 18:36 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from paolo dot carlini at oracle dot com 2010-02-04 18:36 -------
Reopen...
--
paolo dot carlini at oracle dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42943
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libstdc++/42943] std::partial_sum performs improper casts
2010-02-03 3:15 [Bug libstdc++/42943] New: std::partial_sum performs improper casts potswa at mac dot com
2010-02-03 3:31 ` [Bug libstdc++/42943] " paolo dot carlini at oracle dot com
2010-02-04 18:36 ` paolo dot carlini at oracle dot com
@ 2010-02-04 18:36 ` paolo dot carlini at oracle dot com
2 siblings, 0 replies; 4+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-02-04 18:36 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from paolo dot carlini at oracle dot com 2010-02-04 18:36 -------
... to close as duplicate.
*** This bug has been marked as a duplicate of 22634 ***
--
paolo dot carlini at oracle dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42943
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-02-04 18:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-03 3:15 [Bug libstdc++/42943] New: std::partial_sum performs improper casts potswa at mac dot com
2010-02-03 3:31 ` [Bug libstdc++/42943] " paolo dot carlini at oracle dot com
2010-02-04 18:36 ` paolo dot carlini at oracle dot com
2010-02-04 18:36 ` paolo dot carlini at oracle dot com
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).