• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
testA(A & a)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();
fB21   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 
test_C(C<int> ci)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 
test()58   void test() {
59     A<int> i, j;
60     i.swap(j);
61   }
62 }
63 
64 namespace PR15290 {
65   template<typename T>
66   class A {
67     T v_;
add_to_v(A & t)68     friend int add_to_v(A &t) noexcept(noexcept(v_ + 42))
69     {
70       return t.v_ + 42;
71     }
72   };
f()73   void f()
74   {
75     A<int> t;
76     add_to_v(t);
77   }
78 }
79 
80 namespace 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 
h()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 
gStatic::X2101     auto g(T x) -> decltype(f(x)) { return 0; }
102   };
103 
test_X2()104   void test_X2() {
105     X2<int>().g(0);
106   }
107 }
108 
109 namespace PR12564 {
110   struct Base {
barPR12564::Base111     void bar(Base&) {} // FIXME: expected-note {{here}}
112   };
113 
114   struct Derived : Base {
115     // FIXME: This should be accepted.
fooPR12564::Derived116     void foo(Derived& d) noexcept(noexcept(d.bar(d))) {} // expected-error {{cannot bind to a value of unrelated type}}
117   };
118 }
119