|
Bugzilla – Full Text Bug Listing |
| Summary: | showpos is bugged in gcc-4.2.1 | ||
|---|---|---|---|
| Product: | ns-3 | Reporter: | Tom Henderson <tomh> |
| Component: | core | Assignee: | Peter Barnes <pdbarnes> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | mathieu.lacage, ns-bugs |
| Priority: | P5 | ||
| Version: | pre-release | ||
| Hardware: | All | ||
| OS: | All | ||
|
Description
Tom Henderson
2013-07-26 17:37:04 UTC
Given
int64_t imin = std::numeric_limits<in64_t>::min();
the original code
os << ((hi<0) ? "-" : "+") << ((hi<0) ? -hi : hi) << ".";
prints
--9223372036854775808.0
Note the two '-' minus signs.
This is because
- imin == imin,
that is, there are two identities for negation, imin and zero, instead of just zero.
The r9965 patch replaced the original code with
os << std::showpos << hi << ".";
(This is almost correct: it neglects to restore the stream format after setting showpos.)
I propose the following:
// Save stream format flags
std::ios_base::fmtflags ff = os.flags ();
{ // This block should be a simple
// os << std::showpos << hi << ".";
// but for a bug in libstc++ affecting showpos of zero.
// This bug has been around since at least 2004
// (http://gcc.gnu.org/bugzilla/0)
// but still present in at least some libstc++ 4.2
// (http://gcc.gnu.org/ml/libstdc++/2007-11/msg00074.html)
// (http://openbsd.7691.n7.nabble.com/Patch-to-fix-libstdc-std-showpos-td162922.html)
if (hi == 0)
{
os << '+'; // work around libstc++ 4.2 bug
}
else {
os << std::showpos;
}
os << hi << ".";
}
os.flags (ff); // Restore stream flags
Commit r10106 41f46a8e5a96 |