public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/58850] New: Conversion error in chrono
@ 2013-10-23  1:30 galens at capaccess dot org
  2013-10-23 10:07 ` [Bug libstdc++/58850] " paolo.carlini at oracle dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: galens at capaccess dot org @ 2013-10-23  1:30 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58850

            Bug ID: 58850
           Summary: Conversion error in chrono
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: galens at capaccess dot org

Created attachment 31077
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31077&action=edit
minimal_test_case.cpp

I noticed an odd error when using chrono::duration_cast<> to cast a home-made
Years object (typedef of chrono::duration<long long,std::ratio<36*24*36525,1>>)
to chrono::minutes and chrono::seconds


the conversion to seconds works fine; however, when converting this value into
minutes, I found a (presumably overflow) error.

I've attached a small .cpp  that creates a Years object of 12067, and converts
it to seconds and minutes.  The following is the output I get:
(and yes, I know that a year isn't actually 365.25 days; the rounding is fine
for my purposes)

<output>
Years: 12067
seconds:     380805559200
Minutes * 60:     123107521440
Minutes:     2051792024
Seconds / 60:     6346759320
</output>

Platform:
Fedora 19 3.11.2 x86_64
GCC 3.9.0 ( locally built, but the only difference from a normal build was
"../configure --enable-languages=c++" )


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/58850] Conversion error in chrono
  2013-10-23  1:30 [Bug libstdc++/58850] New: Conversion error in chrono galens at capaccess dot org
@ 2013-10-23 10:07 ` paolo.carlini at oracle dot com
  2013-10-23 10:24 ` paolo.carlini at oracle dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-23 10:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58850

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|galens at capaccess dot org        |

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> ---
The issue boils down to how minutes and hours are defined in our current code:

    /// minutes
    typedef duration<int, ratio< 60>>     minutes;

    /// hours
    typedef duration<int, ratio<3600>>     hours;

See? This, on Linux for sure, *is* conforming because the letter of C++11 says
at least 29 bits and at least 23 bits for those types, does *not* say, eg, 64.
Still I wonder if we couldn't just use int64_t for all the typedefs and be done
with it?!?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/58850] Conversion error in chrono
  2013-10-23  1:30 [Bug libstdc++/58850] New: Conversion error in chrono galens at capaccess dot org
  2013-10-23 10:07 ` [Bug libstdc++/58850] " paolo.carlini at oracle dot com
@ 2013-10-23 10:24 ` paolo.carlini at oracle dot com
  2013-10-23 13:34 ` paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-23 10:24 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58850

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Jon, shall we change this?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/58850] Conversion error in chrono
  2013-10-23  1:30 [Bug libstdc++/58850] New: Conversion error in chrono galens at capaccess dot org
  2013-10-23 10:07 ` [Bug libstdc++/58850] " paolo.carlini at oracle dot com
  2013-10-23 10:24 ` paolo.carlini at oracle dot com
@ 2013-10-23 13:34 ` paolo.carlini at oracle dot com
  2013-10-23 15:31 ` paolo at gcc dot gnu.org
  2013-10-23 15:32 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-23 13:34 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58850

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2013-10-23
           Assignee|unassigned at gcc dot gnu.org      |paolo.carlini at oracle dot com
   Target Milestone|---                         |4.9.0
     Ever confirmed|0                           |1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/58850] Conversion error in chrono
  2013-10-23  1:30 [Bug libstdc++/58850] New: Conversion error in chrono galens at capaccess dot org
                   ` (2 preceding siblings ...)
  2013-10-23 13:34 ` paolo.carlini at oracle dot com
@ 2013-10-23 15:31 ` paolo at gcc dot gnu.org
  2013-10-23 15:32 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: paolo at gcc dot gnu.org @ 2013-10-23 15:31 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58850

--- Comment #3 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Wed Oct 23 15:31:26 2013
New Revision: 203978

URL: http://gcc.gnu.org/viewcvs?rev=203978&root=gcc&view=rev
Log:
2013-10-23  Paolo Carlini  <paolo.carlini@oracle.com>

    PR libstdc++/58850
    * include/std/chrono (minutes, hours): Change typedefs to uniformly
    use int64_t.
    * testsuite/20_util/duration/arithmetic/58850.cc: New.

Added:
    trunk/libstdc++-v3/testsuite/20_util/duration/arithmetic/58850.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/std/chrono


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/58850] Conversion error in chrono
  2013-10-23  1:30 [Bug libstdc++/58850] New: Conversion error in chrono galens at capaccess dot org
                   ` (3 preceding siblings ...)
  2013-10-23 15:31 ` paolo at gcc dot gnu.org
@ 2013-10-23 15:32 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-23 15:32 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58850

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Done.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-10-23 15:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-23  1:30 [Bug libstdc++/58850] New: Conversion error in chrono galens at capaccess dot org
2013-10-23 10:07 ` [Bug libstdc++/58850] " paolo.carlini at oracle dot com
2013-10-23 10:24 ` paolo.carlini at oracle dot com
2013-10-23 13:34 ` paolo.carlini at oracle dot com
2013-10-23 15:31 ` paolo at gcc dot gnu.org
2013-10-23 15:32 ` paolo.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).