summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/opt/reload3.C
blob: 12f3e66f369ea7680aa4bcc749a5e1ee7386b7df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// PR target/38287
// { dg-do run }
// { dg-options "-O2 -mcpu=v8 -fPIC" { target { { sparc*-*-* } && { ilp32 && fpic } } } }

#include <cstdlib>

class QTime
{
public:
    explicit QTime(int ms = 0) : ds(ms) {}
    static QTime currentTime() { return QTime(); }
    QTime addMSecs(int ms) const;
    int msecs() const { return ds; }
private:
    unsigned ds;
};

static const unsigned MSECS_PER_DAY = 86400000;

QTime QTime::addMSecs(int ms) const
{
    QTime t;
    if ( ms < 0 ) {
        // % not well-defined for -ve, but / is.
        int negdays = (MSECS_PER_DAY-ms) / MSECS_PER_DAY;
        t.ds = ((int)ds + ms + negdays*MSECS_PER_DAY)
                % MSECS_PER_DAY;
    } else {
        t.ds = ((int)ds + ms) % MSECS_PER_DAY;
    }
    return t;
}

int main()
{
  if (QTime(1).addMSecs(1).msecs() != 2)
    abort ();
  return 0;
}