[jira] [Commented] (STDCXX-1059) std::ios_base::setf() and std::ios_base::unsetf() do not set/clear the format flags correctly

2012-02-06 Thread Martin Sebor (Commented) (JIRA)

[ 
https://issues.apache.org/jira/browse/STDCXX-1059?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13201902#comment-13201902
 ] 

Martin Sebor commented on STDCXX-1059:
--

stdcxx uses additional bits in flags to make it possible to format numbers in 
bases 2 through 36 (see the {{\_\_rw::\_\_rw_setbase}} manipulator in 
{{}}, for example). I suspect this is an unintended result of that 
extension.

> std::ios_base::setf() and std::ios_base::unsetf() do not set/clear the format 
> flags correctly
> -
>
> Key: STDCXX-1059
> URL: https://issues.apache.org/jira/browse/STDCXX-1059
> Project: C++ Standard Library
>  Issue Type: Bug
>  Components: 27. Input/Output
>Affects Versions: 4.2.1, 4.2.x, 4.3.x, 5.0.0
> Environment: Solaris 10 and 11
> Red Hat Linux, OpenSuSE Linux
> Sun C++ Compilers 12.1, 12.2, 12.3
> Defect is independent of platform and/or compiler
>Reporter: Stefan Teleman
>  Labels: conformance, runtime, standards
> Fix For: 4.2.2, 4.2.x, 4.3.x, 5.0.0
>
> Attachments: flags.cc, test.cc
>
>
> std::ios_base::setf (fmtflags fl) and std::ios_base::unsetf (fmtflags fl)
> do not set or clear the format flags correctly:
> {code:title=test.cc|borderStyle=solid}
> #include 
> #include 
> #include 
> int main()
> {
> std::fstream strm;
> std::ios_base::fmtflags fl;
> int ret = 0;
> fl = std::ios_base::dec;
> strm.unsetf(fl);
> fl = std::ios_base::hex;
> strm.setf(fl);
> strm.unsetf(fl);
> if (strm.flags() & fl)
> {
> std::cerr << "failure to clear hex flags" << std::endl;
> ++ret;
> }
> return ret;
> }
> {code}
> 1. Output from GCC 4.5.0:
> {noformat}
> [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/fmtflags][02/05/2012
>  15:19:37][1957]>> ./test-gcc 
> [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/fmtflags][02/05/2012
>  15:20:02][1958]>> echo $status
> 0
> {noformat}
> 2. Output from Sun C++ 12.2 with stlport:
> {noformat}
> [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/fmtflags][02/05/2012
>  15:20:24][1959]>> ./test-ss122-stlport 
> [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/fmtflags][02/05/2012
>  15:21:08][1960]>> echo $status
> 0
> {noformat}
> 3. Output rom Sun C++ 12.2 with our patched stdcxx:
> {noformat}
> [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/fmtflags][02/05/2012
>  15:21:09][1961]>> ./test-ss122-stdcxx 
> [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/fmtflags][02/05/2012
>  15:21:44][1962]>> echo $status
> 0
> {noformat}
> 4. Output from Pathscale 4.0.12.1 (which did not patch stdcxx):
> {noformat}
> [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/fmtflags][02/05/2012
>  15:21:46][1963]>> ./test-pathscale 
> failure to clear hex flags
> [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/fmtflags][02/05/2012
>  15:22:48][1964]>> echo $status
> 1
> {noformat}
> Simplified test case identifying the problem:
> {code:title=flags.cc|borderStyle=solid}
> #include 
> #include 
> class BadTest
> {
> public:
> BadTest() : _flags(0) { }
> ~BadTest() { }
> unsigned int flags() const { return _flags; }
> unsigned int flags (unsigned int f)
> {
> unsigned int ret = _flags;
> _flags |= f;
> return ret;
> }
> unsigned int setf (unsigned int f) { return flags (flags() | f); }
> void unsetf (unsigned int f) { flags (flags() & ~f); }
> private:
> unsigned int _flags;
> };
> class GoodTest
> {
> public:
> GoodTest() : _flags(0) { }
> ~GoodTest() { }
> unsigned int flags() const { return _flags; }
> unsigned int flags (unsigned int f)
> {
> unsigned int ret = _flags;
> _flags |= f;
> return ret;
> }
> unsigned int setf (unsigned int f)
> {
> unsigned int ret = _flags;
> _flags |= f;
> return ret;
> }
> void unsetf (unsigned int f) { _flags &= ~f; }
> private:
> unsigned int _flags;
> };
> int main()
> {
> BadTest bt;
> std::ios_base::fmtflags fl;
> std::cerr << "* BadTest *" << std::endl;
> std::cerr << "default flags: " << bt.flags() << std::endl;
> fl = std::ios_base::dec;
> bt.setf(fl);
> std::cerr << "flags: " << bt.flags() << std::endl;
> bt.unsetf(fl);
> std::cerr << "flags: " << bt.flags() << std::endl;
> fl = std::ios_base::hex;
> bt.setf(fl);
> std::cerr << "flags: " << bt.flags() << std::endl;
> bt.unsetf(fl);
> std::cerr << "flags: " << bt.flags() << std::endl;
> std::cerr << std::endl;
> Go

[jira] [Commented] (STDCXX-1059) std::ios_base::setf() and std::ios_base::unsetf() do not set/clear the format flags correctly

2012-02-06 Thread Travis Vitek (Commented) (JIRA)

[ 
https://issues.apache.org/jira/browse/STDCXX-1059?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13201459#comment-13201459
 ] 

Travis Vitek commented on STDCXX-1059:
--

According to C++03, all of the functions are required to take/return values.

{noformat}
// 27.4.2.2 fmtflags state:
fmtflags flags() const;
fmtflags flags(fmtflags fmtfl);
fmtflags setf(fmtflags fmtfl);
fmtflags setf(fmtflags fmtfl, fmtflags mask);
void unsetf(fmtflags mask);
{noformat}

In your {{flags.cc}} example, it seems to me that the problem is 
{{flags(fmtflags)}} is supposed to set the underlying flags member directly, 
not mask it in.

{noformat}
fmtflags flags(fmtflags fmtfl);
2 Postcondition: fmtfl == flags().
3 Returns: The previous value of flags().
fmtflags setf(fmtflags fmtfl);
4 Effects: Sets fmtfl in flags().
5 Returns: The previous value of flags().
{noformat}

It looks to me like the implementations of {{setf()}} and {{unsetf()}} are 
correct, and there is some sort of bug in {{flags()}}.

> std::ios_base::setf() and std::ios_base::unsetf() do not set/clear the format 
> flags correctly
> -
>
> Key: STDCXX-1059
> URL: https://issues.apache.org/jira/browse/STDCXX-1059
> Project: C++ Standard Library
>  Issue Type: Bug
>  Components: 27. Input/Output
>Affects Versions: 4.2.1, 4.2.x, 4.3.x, 5.0.0
> Environment: Solaris 10 and 11
> Red Hat Linux, OpenSuSE Linux
> Sun C++ Compilers 12.1, 12.2, 12.3
> Defect is independent of platform and/or compiler
>Reporter: Stefan Teleman
>  Labels: conformance, runtime, standards
> Fix For: 4.2.2, 4.2.x, 4.3.x, 5.0.0
>
> Attachments: flags.cc, test.cc
>
>
> std::ios_base::setf (fmtflags fl) and std::ios_base::unsetf (fmtflags fl)
> do not set or clear the format flags correctly:
> {code:title=test.cc|borderStyle=solid}
> #include 
> #include 
> #include 
> int main()
> {
> std::fstream strm;
> std::ios_base::fmtflags fl;
> int ret = 0;
> fl = std::ios_base::dec;
> strm.unsetf(fl);
> fl = std::ios_base::hex;
> strm.setf(fl);
> strm.unsetf(fl);
> if (strm.flags() & fl)
> {
> std::cerr << "failure to clear hex flags" << std::endl;
> ++ret;
> }
> return ret;
> }
> {code}
> 1. Output from GCC 4.5.0:
> {noformat}
> [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/fmtflags][02/05/2012
>  15:19:37][1957]>> ./test-gcc 
> [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/fmtflags][02/05/2012
>  15:20:02][1958]>> echo $status
> 0
> {noformat}
> 2. Output from Sun C++ 12.2 with stlport:
> {noformat}
> [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/fmtflags][02/05/2012
>  15:20:24][1959]>> ./test-ss122-stlport 
> [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/fmtflags][02/05/2012
>  15:21:08][1960]>> echo $status
> 0
> {noformat}
> 3. Output rom Sun C++ 12.2 with our patched stdcxx:
> {noformat}
> [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/fmtflags][02/05/2012
>  15:21:09][1961]>> ./test-ss122-stdcxx 
> [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/fmtflags][02/05/2012
>  15:21:44][1962]>> echo $status
> 0
> {noformat}
> 4. Output from Pathscale 4.0.12.1 (which did not patch stdcxx):
> {noformat}
> [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/fmtflags][02/05/2012
>  15:21:46][1963]>> ./test-pathscale 
> failure to clear hex flags
> [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/fmtflags][02/05/2012
>  15:22:48][1964]>> echo $status
> 1
> {noformat}
> Simplified test case identifying the problem:
> {code:title=flags.cc|borderStyle=solid}
> #include 
> #include 
> class BadTest
> {
> public:
> BadTest() : _flags(0) { }
> ~BadTest() { }
> unsigned int flags() const { return _flags; }
> unsigned int flags (unsigned int f)
> {
> unsigned int ret = _flags;
> _flags |= f;
> return ret;
> }
> unsigned int setf (unsigned int f) { return flags (flags() | f); }
> void unsetf (unsigned int f) { flags (flags() & ~f); }
> private:
> unsigned int _flags;
> };
> class GoodTest
> {
> public:
> GoodTest() : _flags(0) { }
> ~GoodTest() { }
> unsigned int flags() const { return _flags; }
> unsigned int flags (unsigned int f)
> {
> unsigned int ret = _flags;
> _flags |= f;
> return ret;
> }
> unsigned int setf (unsigned int f)
> {
> unsigned int ret = _flags;
> _flags |= f;
> return ret;
> }
> void unsetf (unsigned int f) { _flags &= ~f; }
> private:
> unsigned int _flags;
> };
> int