]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaCXX/return.cpp
Vendor import of clang trunk r162107:
[FreeBSD/FreeBSD.git] / test / SemaCXX / return.cpp
1 // RUN: %clang_cc1 %s -fcxx-exceptions -fexceptions -fsyntax-only -Wignored-qualifiers -verify
2
3 int test1() {
4   throw;
5 }
6
7 // PR5071
8 template<typename T> T f() { }
9
10 template<typename T>
11 void g(T t) {
12   return t * 2; // okay
13 }
14
15 template<typename T>
16 T h() {
17   return 17;
18 }
19
20 // Don't warn on cv-qualified class return types, only scalar return types.
21 namespace ignored_quals {
22 struct S {};
23 const S class_c();
24 const volatile S class_cv();
25
26 const int scalar_c(); // expected-warning{{'const' type qualifier on return type has no effect}}
27 int const scalar_c2(); // expected-warning{{'const' type qualifier on return type has no effect}}
28
29 const
30 char*
31 const // expected-warning{{'const' type qualifier on return type has no effect}}
32 f();
33
34 char
35 const*
36 const // expected-warning{{'const' type qualifier on return type has no effect}}
37 g();
38
39 char* const h(); // expected-warning{{'const' type qualifier on return type has no effect}}
40 char* volatile i(); // expected-warning{{'volatile' type qualifier on return type has no effect}}
41
42 char*
43 volatile // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
44 const
45 j();
46
47 const volatile int scalar_cv(); // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
48 }
49
50 namespace PR9328 {
51   typedef char *PCHAR;
52   class Test 
53   {
54     const PCHAR GetName() { return 0; } // expected-warning{{'const' type qualifier on return type has no effect}}
55   };
56 }
57
58 class foo  {
59   operator int * const ();
60 };
61
62 namespace PR10057 {
63   struct S {
64     ~S();
65   };
66
67   template <class VarType>
68   void Test(const VarType& value) {
69     return S() = value;
70   }
71 }
72
73 namespace return_has_expr {
74   struct S {
75     S() {
76       return 42; // expected-error {{constructor 'S' should not return a value}}
77     }
78     ~S() {
79       return 42; // expected-error {{destructor '~S' should not return a value}}
80     }
81   };
82 }