1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
2 
3 struct 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 
12 void 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 
19 struct B {
20   char g();
21   template<class T> auto f(T t) -> decltype(t + g())
22   { return t + g(); }
23 };
24 
25 template auto B::f(int t) -> decltype(t + g());
26 
27 template<typename T>
28 struct 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 
37 void 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 
45 namespace 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 
64 namespace Static {
65   struct X1 {
66     int m;
67     static auto f() -> decltype(m); // expected-error{{'this' cannot be implicitly used in a static member function declaration}}
68     static auto g() -> decltype(this->m); // expected-error{{'this' cannot be used in a static member function declaration}}
69 
70     static int h();
71 
72     static int i() noexcept(noexcept(m + 2)); // expected-error{{'this' cannot be implicitly used in a static member function declaration}}
73   };
74 
75   auto X1::h() -> decltype(m) { return 0; } // expected-error{{'this' cannot be implicitly used in a static member function declaration}}
76 
77   template<typename T>
78   struct X2 {
79     int m;
80 
81     T f(T*);
82     static T f(int);
83 
84     auto g(T x) -> decltype(f(x)) { return 0; }
85   };
86 
87   void test_X2() {
88     X2<int>().g(0);
89   }
90 }
91 
92 namespace PR12564 {
93   struct Base {
94     void bar(Base&) {} // FIXME: expected-note {{here}}
95   };
96 
97   struct Derived : Base {
98     // FIXME: This should be accepted.
99     void foo(Derived& d) noexcept(noexcept(d.bar(d))) {} // expected-error {{cannot bind to a value of unrelated type}}
100   };
101 }
102