blob: 580f0a7233e2cafe804a02f3abdea0cab2713d43 [file] [log] [blame]
Richard Smith8c952cd2013-03-28 02:51:21 +00001// RUN: %clang_cc1 %s -std=c++11 -fcxx-exceptions -fexceptions -fsyntax-only -Wignored-qualifiers -verify
Mike Stumpb1682c52009-07-22 23:56:57 +00002
3int test1() {
4 throw;
5}
Douglas Gregor1be8aee2009-10-01 23:25:31 +00006
7// PR5071
8template<typename T> T f() { }
9
10template<typename T>
11void g(T t) {
12 return t * 2; // okay
13}
14
15template<typename T>
16T h() {
17 return 17;
18}
Chandler Carruth5495f372010-07-14 06:36:18 +000019
20// Don't warn on cv-qualified class return types, only scalar return types.
21namespace ignored_quals {
22struct S {};
23const S class_c();
24const volatile S class_cv();
25
26const int scalar_c(); // expected-warning{{'const' type qualifier on return type has no effect}}
Chandler Carruthd067c072011-02-23 18:51:59 +000027int const scalar_c2(); // expected-warning{{'const' type qualifier on return type has no effect}}
28
29const
30char*
31const // expected-warning{{'const' type qualifier on return type has no effect}}
32f();
33
34char
35const*
36const // expected-warning{{'const' type qualifier on return type has no effect}}
37g();
38
39char* const h(); // expected-warning{{'const' type qualifier on return type has no effect}}
40char* volatile i(); // expected-warning{{'volatile' type qualifier on return type has no effect}}
41
Hans Wennborga08fcb82011-06-03 17:37:26 +000042char*
43volatile // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
44const
45j();
46
Chandler Carruth5495f372010-07-14 06:36:18 +000047const volatile int scalar_cv(); // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
Richard Smith8c952cd2013-03-28 02:51:21 +000048
49// FIXME: Maintain enough information that we can point the diagnostic at the 'volatile' keyword.
50const
51int S::*
52volatile
53mixed_ret(); // expected-warning {{'volatile' type qualifier on return type has no effect}}
54
55const int volatile // expected-warning {{'const volatile' type qualifiers on return type have no effect}}
56 (((parens())));
57
Richard Smitheb82a532013-03-28 03:27:52 +000058_Atomic(int) atomic();
Richard Smith8c952cd2013-03-28 02:51:21 +000059
60_Atomic // expected-warning {{'_Atomic' type qualifier on return type has no effect}}
61 int
62 atomic();
63
64auto
65 trailing_return_type() -> // expected-warning {{'const' type qualifier on return type has no effect}}
66 const int;
67
68const int ret_array()[4]; // expected-error {{cannot return array}}
Chandler Carruth5495f372010-07-14 06:36:18 +000069}
Douglas Gregorfff95132011-03-01 17:04:42 +000070
71namespace PR9328 {
72 typedef char *PCHAR;
73 class Test
74 {
75 const PCHAR GetName() { return 0; } // expected-warning{{'const' type qualifier on return type has no effect}}
76 };
77}
Rafael Espindola1e153942011-03-11 04:56:58 +000078
79class foo {
Richard Smith8c952cd2013-03-28 02:51:21 +000080 operator const int ();
Rafael Espindola1e153942011-03-11 04:56:58 +000081 operator int * const ();
82};
Nick Lewycky8d794612011-06-01 07:44:31 +000083
84namespace PR10057 {
85 struct S {
86 ~S();
87 };
88
89 template <class VarType>
90 void Test(const VarType& value) {
91 return S() = value;
92 }
93}
Hans Wennborg150fee82011-06-30 17:20:18 +000094
95namespace return_has_expr {
96 struct S {
97 S() {
98 return 42; // expected-error {{constructor 'S' should not return a value}}
99 }
100 ~S() {
101 return 42; // expected-error {{destructor '~S' should not return a value}}
102 }
103 };
104}