Return-Path: X-Original-To: apmail-stdcxx-issues-archive@minotaur.apache.org Delivered-To: apmail-stdcxx-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3D30D9BCC for ; Sun, 5 Feb 2012 20:38:24 +0000 (UTC) Received: (qmail 97726 invoked by uid 500); 5 Feb 2012 20:38:24 -0000 Delivered-To: apmail-stdcxx-issues-archive@stdcxx.apache.org Received: (qmail 97711 invoked by uid 500); 5 Feb 2012 20:38:24 -0000 Mailing-List: contact issues-help@stdcxx.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@stdcxx.apache.org Delivered-To: mailing list issues@stdcxx.apache.org Received: (qmail 97703 invoked by uid 99); 5 Feb 2012 20:38:24 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Feb 2012 20:38:24 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Feb 2012 20:38:20 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 8419A186070 for ; Sun, 5 Feb 2012 20:37:59 +0000 (UTC) Date: Sun, 5 Feb 2012 20:37:59 +0000 (UTC) From: "Stefan Teleman (Updated) (JIRA)" To: issues@stdcxx.apache.org Message-ID: <176185061.80.1328474279542.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <216885660.67.1328474159700.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Updated] (STDCXX-1059) std::ios_base::setf() and std::ios_base::unsetf() do not set/clear the format flags correctly MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/STDCXX-1059?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Stefan Teleman updated STDCXX-1059: ----------------------------------- Attachment: test.cc > 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; > GoodTest gt; > std::cerr << "***** GoodTest *****" << std::endl; > std::cerr << "default flags: " << gt.flags() << std::endl; > fl = std::ios_base::dec; > gt.setf(fl); > std::cerr << "flags: " << gt.flags() << std::endl; > gt.unsetf(fl); > std::cerr << "flags: " << gt.flags() << std::endl; > fl = std::ios_base::hex; > gt.setf(fl); > std::cerr << "flags: " << gt.flags() << std::endl; > gt.unsetf(fl); > std::cerr << "flags: " << gt.flags() << std::endl; > return 0; > } > {code} > 1. Output from GCC 4.5.0: > {noformat} > [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/fmtflags][02/05/2012 15:27:01][1968]>> ./flags-gcc > ***** BadTest ***** > default flags: 0 > flags: 2 > flags: 2 > flags: 10 > flags: 10 > ***** GoodTest ***** > default flags: 0 > flags: 2 > flags: 0 > flags: 8 > flags: 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:27:05][1969]>> ./flags-ss122-stlport > ***** BadTest ***** > default flags: 0 > flags: 8 > flags: 8 > flags: 24 > flags: 24 > ***** GoodTest ***** > default flags: 0 > flags: 8 > flags: 0 > flags: 16 > flags: 0 > {noformat} > 3. Output from Sun C++ 12.2. with our patched stdcxx: > {noformat} > [steleman@darthvader][/src/steleman/programming/stdcxx-ss122/bugfixes-sunw/fmtflags][02/05/2012 15:27:12][1970]>> ./flags-ss122-stdcxx > ***** BadTest ***** > default flags: 0 > flags: 2 > flags: 2 > flags: 10 > flags: 10 > ***** GoodTest ***** > default flags: 0 > flags: 2 > flags: 0 > flags: 8 > flags: 0 > {noformat} > The defect is in > {noformat} > std::ios_base::setf(fmtflags fl); > and > std::ios_base::unsetf(fmtflags fl); > {noformat} > in the original stdcxx implementation. The member function > {noformat} > fmtflags std::ios_base::flags() const; > {noformat} > returns by value. Any bitwise operations on the anon temporary created by > this function do not affect the __fmtflags data member of std::ios_base, > which remains unchanged. > Patch for stdcxx 4.2.1 to follow. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira