p1.cpp revision 82b9fb8e7a05066e690670d2eb386a624b04f684
1// RUN: clang-cc -emit-llvm-only %s
2
3template <typename T> struct Num {
4  T value_;
5
6public:
7  Num(T value) : value_(value) {}
8  T get() const { return value_; }
9
10  template <typename U> struct Rep {
11    U count_;
12    Rep(U count) : count_(count) {}
13
14    friend Num operator*(const Num &a, const Rep &n) {
15      Num x = 0;
16      for (U count = n.count_; count; --count)
17        x += a;
18      return x;
19    }
20  };
21
22  friend Num operator+(const Num &a, const Num &b) {
23    return a.value_ + b.value_;
24  }
25
26  Num& operator+=(const Num& b) {
27    value_ += b.value_;
28    return *this;
29  }
30
31  class Representation {};
32  friend class Representation;
33};
34
35class A {
36  template <typename T> friend bool iszero(const A &a) throw();
37};
38
39int calc1() {
40  Num<int> left = -1;
41  Num<int> right = 1;
42  Num<int> result = left + right;
43  return result.get();
44}
45
46int calc2() {
47  Num<int> x = 3;
48  Num<int>::Rep<char> n = (char) 10;
49  Num<int> result = x * n;
50  return result.get();
51}
52