Debian Codegraph @

gcc/testsuite/g++.dg/cpp0x/this1.C

raw
1 // PR c++/88548
2 // { dg-do compile { target c++11 } }
3
4 struct S1 {
5 int a;
6 auto m1 () -> decltype(this->a) { return 0; }
7 auto m2 () -> decltype(this) { return 0; }
8 void m3 () noexcept(noexcept(this->a)) { }
9 void m4 () noexcept(noexcept(this)) { }
10
11 static auto m5 () -> decltype(this->a) { return 0; } // { dg-error ".this. may not be used in this context" }
12 static auto m6 () -> decltype(this) { return 0; } // { dg-error ".this. may not be used in this context" }
13 static void m7 () noexcept(noexcept(this->a)) { } // { dg-error ".this. may not be used in this context" }
14 static void m8 () noexcept(noexcept(this)) { } // { dg-error ".this. may not be used in this context" }
15 };
16
17 template <typename T>
18 struct S2 {
19 static auto f1(T arg) -> decltype((arg));
20 };
21
22 struct S3 {
23 int a;
24 void f1 () noexcept(noexcept(a)) { }
25 static void f2() noexcept(noexcept(a)) { }
26 static auto f3() -> decltype(a);
27 static auto f4() -> decltype((a));
28 };
29
30 template<typename T>
31 class S4 {
32 T i;
33 friend int foo(const S4 &t) noexcept(noexcept(i)) { return t.i; }
34 };
35
36 void
37 test ()
38 {
39 S4<int> t;
40 foo(t);
41 }
42
43 struct S5 {
44 friend auto bar() -> decltype(this); // { dg-error ".this. may not be used in this context" }
45 auto bar2() -> decltype(this);
46 };