Richard Smith | 8c952cd | 2013-03-28 02:51:21 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -std=c++11 -fcxx-exceptions -fexceptions -fsyntax-only -Wignored-qualifiers -verify |
Mike Stump | b1682c5 | 2009-07-22 23:56:57 +0000 | [diff] [blame] | 2 | |
| 3 | int test1() { |
| 4 | throw; |
| 5 | } |
Douglas Gregor | 1be8aee | 2009-10-01 23:25:31 +0000 | [diff] [blame] | 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 | } |
Chandler Carruth | 5495f37 | 2010-07-14 06:36:18 +0000 | [diff] [blame] | 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}} |
Chandler Carruth | d067c07 | 2011-02-23 18:51:59 +0000 | [diff] [blame] | 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 | |
Hans Wennborg | a08fcb8 | 2011-06-03 17:37:26 +0000 | [diff] [blame] | 42 | char* |
| 43 | volatile // expected-warning{{'const volatile' type qualifiers on return type have no effect}} |
| 44 | const |
| 45 | j(); |
| 46 | |
Chandler Carruth | 5495f37 | 2010-07-14 06:36:18 +0000 | [diff] [blame] | 47 | const volatile int scalar_cv(); // expected-warning{{'const volatile' type qualifiers on return type have no effect}} |
Richard Smith | 8c952cd | 2013-03-28 02:51:21 +0000 | [diff] [blame] | 48 | |
| 49 | // FIXME: Maintain enough information that we can point the diagnostic at the 'volatile' keyword. |
| 50 | const |
| 51 | int S::* |
| 52 | volatile |
| 53 | mixed_ret(); // expected-warning {{'volatile' type qualifier on return type has no effect}} |
| 54 | |
| 55 | const int volatile // expected-warning {{'const volatile' type qualifiers on return type have no effect}} |
| 56 | (((parens()))); |
| 57 | |
Richard Smith | eb82a53 | 2013-03-28 03:27:52 +0000 | [diff] [blame] | 58 | _Atomic(int) atomic(); |
Richard Smith | 8c952cd | 2013-03-28 02:51:21 +0000 | [diff] [blame] | 59 | |
| 60 | _Atomic // expected-warning {{'_Atomic' type qualifier on return type has no effect}} |
| 61 | int |
| 62 | atomic(); |
| 63 | |
| 64 | auto |
| 65 | trailing_return_type() -> // expected-warning {{'const' type qualifier on return type has no effect}} |
| 66 | const int; |
| 67 | |
| 68 | const int ret_array()[4]; // expected-error {{cannot return array}} |
Chandler Carruth | 5495f37 | 2010-07-14 06:36:18 +0000 | [diff] [blame] | 69 | } |
Douglas Gregor | fff9513 | 2011-03-01 17:04:42 +0000 | [diff] [blame] | 70 | |
| 71 | namespace 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 Espindola | 1e15394 | 2011-03-11 04:56:58 +0000 | [diff] [blame] | 78 | |
| 79 | class foo { |
Richard Smith | 8c952cd | 2013-03-28 02:51:21 +0000 | [diff] [blame] | 80 | operator const int (); |
Rafael Espindola | 1e15394 | 2011-03-11 04:56:58 +0000 | [diff] [blame] | 81 | operator int * const (); |
| 82 | }; |
Nick Lewycky | 8d79461 | 2011-06-01 07:44:31 +0000 | [diff] [blame] | 83 | |
| 84 | namespace 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 Wennborg | 150fee8 | 2011-06-30 17:20:18 +0000 | [diff] [blame] | 94 | |
| 95 | namespace 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 | } |