p3-0x.cpp revision e79ce292d93f955c1219c3977c02199bd3dc6544
1// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
2
3struct A {
4  int &f(int*);
5  float &f(int*) const noexcept;
6
7  int *ptr;
8  auto g1() noexcept(noexcept(f(ptr))) -> decltype(f(this->ptr));
9  auto g2() const noexcept(noexcept(f((*this).ptr))) -> decltype(f(ptr));
10};
11
12void testA(A &a) {
13  int &ir = a.g1();
14  float &fr = a.g2();
15  static_assert(!noexcept(a.g1()), "exception-specification failure");
16  static_assert(noexcept(a.g2()), "exception-specification failure");
17}
18
19struct B {
20  char g();
21  template<class T> auto f(T t) -> decltype(t + g())
22  { return t + g(); }
23};
24
25template auto B::f(int t) -> decltype(t + g());
26
27template<typename T>
28struct C {
29  int &f(T*);
30  float &f(T*) const noexcept;
31
32  T* ptr;
33  auto g1() noexcept(noexcept(f(ptr))) -> decltype(f((*this).ptr));
34  auto g2() const noexcept(noexcept(f(((this))->ptr))) -> decltype(f(ptr));
35};
36
37void test_C(C<int> ci) {
38  int *p = 0;
39  int &ir = ci.g1();
40  float &fr = ci.g2();
41  static_assert(!noexcept(ci.g1()), "exception-specification failure");
42  static_assert(noexcept(ci.g2()), "exception-specification failure");
43}
44
45namespace PR10036 {
46  template <class I>
47  void
48  iter_swap(I x, I y) noexcept;
49
50  template <class T>
51  class A
52  {
53    T t_;
54  public:
55    void swap(A& a) noexcept(noexcept(iter_swap(&t_, &a.t_)));
56  };
57
58  void test() {
59    A<int> i, j;
60    i.swap(j);
61  }
62}
63
64namespace PR15290 {
65  template<typename T>
66  class A {
67    T v_;
68    friend int add_to_v(A &t) noexcept(noexcept(v_ + 42))
69    {
70      return t.v_ + 42;
71    }
72  };
73  void f()
74  {
75    A<int> t;
76    add_to_v(t);
77  }
78}
79
80namespace Static {
81  struct X1 {
82    int m;
83    // FIXME: This should be accepted.
84    static auto f() -> decltype(m); // expected-error{{'this' cannot be implicitly used in a static member function declaration}}
85    static auto g() -> decltype(this->m); // expected-error{{'this' cannot be used in a static member function declaration}}
86
87    static int h();
88
89    static int i() noexcept(noexcept(m + 2)); // expected-error{{'this' cannot be implicitly used in a static member function declaration}}
90  };
91
92  auto X1::h() -> decltype(m) { return 0; } // expected-error{{'this' cannot be implicitly used in a static member function declaration}}
93
94  template<typename T>
95  struct X2 {
96    int m;
97
98    T f(T*);
99    static T f(int);
100
101    auto g(T x) -> decltype(f(x)) { return 0; }
102  };
103
104  void test_X2() {
105    X2<int>().g(0);
106  }
107}
108
109namespace PR12564 {
110  struct Base {
111    void bar(Base&) {} // FIXME: expected-note {{here}}
112  };
113
114  struct Derived : Base {
115    // FIXME: This should be accepted.
116    void foo(Derived& d) noexcept(noexcept(d.bar(d))) {} // expected-error {{cannot bind to a value of unrelated type}}
117  };
118}
119
120namespace rdar13473493 {
121  template <typename F>
122  class wrap
123  {
124  public:
125    template <typename... Args>
126    auto operator()(Args&&... args) const -> decltype(wrapped(args...)) // expected-note{{candidate template ignored: substitution failure [with Args = <int>]: use of undeclared identifier 'wrapped'}}
127    {
128      return wrapped(args...);
129    }
130
131  private:
132    F wrapped;
133  };
134
135  void test(wrap<int (*)(int)> w) {
136    w(5); // expected-error{{no matching function for call to object of type 'wrap<int (*)(int)>'}}
137  }
138}
139