| 1 |
// RUN: %clang_cc1 %s -std=c++11 -fcxx-exceptions -fexceptions -fsyntax-only -Wignored-qualifiers -verify |
| 2 |
// RUN: %clang_cc1 %s -std=c++14 -fcxx-exceptions -fexceptions -fsyntax-only -Wignored-qualifiers -verify |
| 3 |
|
| 4 |
int test1() { |
| 5 |
throw; |
| 6 |
} |
| 7 |
|
| 8 |
// PR5071 |
| 9 |
template<typename T> T f() { } |
| 10 |
|
| 11 |
template<typename T> |
| 12 |
void g(T t) { |
| 13 |
return t * 2; // okay |
| 14 |
} |
| 15 |
|
| 16 |
template<typename T> |
| 17 |
T h() { |
| 18 |
return 17; |
| 19 |
} |
| 20 |
|
| 21 |
// Don't warn on cv-qualified class return types, only scalar return types. |
| 22 |
namespace ignored_quals { |
| 23 |
struct S {}; |
| 24 |
const S class_c(); |
| 25 |
const volatile S class_cv(); |
| 26 |
|
| 27 |
const int scalar_c(); // expected-warning{{'const' type qualifier on return type has no effect}} |
| 28 |
int const scalar_c2(); // expected-warning{{'const' type qualifier on return type has no effect}} |
| 29 |
|
| 30 |
const |
| 31 |
char* |
| 32 |
const // expected-warning{{'const' type qualifier on return type has no effect}} |
| 33 |
f(); |
| 34 |
|
| 35 |
char |
| 36 |
const* |
| 37 |
const // expected-warning{{'const' type qualifier on return type has no effect}} |
| 38 |
g(); |
| 39 |
|
| 40 |
char* const h(); // expected-warning{{'const' type qualifier on return type has no effect}} |
| 41 |
char* volatile i(); // expected-warning{{'volatile' type qualifier on return type has no effect}} |
| 42 |
|
| 43 |
char* |
| 44 |
volatile // expected-warning{{'const volatile' type qualifiers on return type have no effect}} |
| 45 |
const |
| 46 |
j(); |
| 47 |
|
| 48 |
const volatile int scalar_cv(); // expected-warning{{'const volatile' type qualifiers on return type have no effect}} |
| 49 |
|
| 50 |
// FIXME: Maintain enough information that we can point the diagnostic at the 'volatile' keyword. |
| 51 |
const |
| 52 |
int S::* |
| 53 |
volatile |
| 54 |
mixed_ret(); // expected-warning {{'volatile' type qualifier on return type has no effect}} |
| 55 |
|
| 56 |
const int volatile // expected-warning {{'const volatile' type qualifiers on return type have no effect}} |
| 57 |
(((parens()))); |
| 58 |
|
| 59 |
_Atomic(int) atomic(); |
| 60 |
|
| 61 |
_Atomic // expected-warning {{'_Atomic' type qualifier on return type has no effect}} |
| 62 |
int |
| 63 |
atomic(); |
| 64 |
|
| 65 |
auto trailing_return_type() -> |
| 66 |
const int; // expected-warning {{'const' type qualifier on return type has no effect}} |
| 67 |
|
| 68 |
auto trailing_return_type_lambda = [](const int &x) -> |
| 69 |
const int // expected-warning {{'const' type qualifier on return type has no effect}} |
| 70 |
{ return x; }; |
| 71 |
|
| 72 |
const int ret_array()[4]; // expected-error {{cannot return array}} |
| 73 |
} |
| 74 |
|
| 75 |
namespace PR9328 { |
| 76 |
typedef char *PCHAR; |
| 77 |
class Test |
| 78 |
{ |
| 79 |
const PCHAR GetName() { return 0; } // expected-warning{{'const' type qualifier on return type has no effect}} |
| 80 |
}; |
| 81 |
} |
| 82 |
|
| 83 |
class foo { |
| 84 |
operator const int (); |
| 85 |
operator int * const (); |
| 86 |
}; |
| 87 |
|
| 88 |
namespace PR10057 { |
| 89 |
struct S { |
| 90 |
~S(); |
| 91 |
}; |
| 92 |
|
| 93 |
template <class VarType> |
| 94 |
void Test(const VarType& value) { |
| 95 |
return S() = value; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
namespace return_has_expr { |
| 100 |
struct S { |
| 101 |
S() { |
| 102 |
return 42; // expected-error {{constructor 'S' should not return a value}} |
| 103 |
} |
| 104 |
~S() { |
| 105 |
return 42; // expected-error {{destructor '~S' should not return a value}} |
| 106 |
} |
| 107 |
}; |
| 108 |
} |
| 109 |
|
| 110 |
// pr17759 |
| 111 |
namespace ctor_returns_void { |
| 112 |
void f() {} |
| 113 |
struct S { |
| 114 |
S() { return f(); } // expected-error {{constructor 'S' must not return void expression}} |
| 115 |
~S() { return f(); } // expected-error {{destructor '~S' must not return void expression}} |
| 116 |
}; |
| 117 |
|
| 118 |
template <typename T> struct ST { |
| 119 |
ST() { return f(); } // expected-error {{constructor 'ST<T>' must not return void expression}} |
| 120 |
// expected-error@-1 {{constructor 'ST' must not return void expression}} |
| 121 |
~ST() { return f(); } // expected-error {{destructor '~ST<T>' must not return void expression}} |
| 122 |
// expected-error@-1 {{destructor '~ST' must not return void expression}} |
| 123 |
}; |
| 124 |
|
| 125 |
ST<int> st; // expected-note {{in instantiation of member function 'ctor_returns_void::ST<int>::ST'}} |
| 126 |
// expected-note@-1 {{in instantiation of member function 'ctor_returns_void::ST<int>::~ST'}} |
| 127 |
} |
| 128 |
|
| 129 |
void cxx_unresolved_expr() { |
| 130 |
// The use of an undeclared variable tricks clang into building a |
| 131 |
// CXXUnresolvedConstructExpr, and the missing ')' gives it an invalid source |
| 132 |
// location for its rparen. Check that emitting a diag on the range of the |
| 133 |
// expr doesn't assert. |
| 134 |
return int(undeclared, 4; // expected-error {{use of undeclared identifier 'undeclared'}} |
| 135 |
} |
| 136 |
|
| 137 |
#if __cplusplus >= 201402L |
| 138 |
namespace GH43054 { |
| 139 |
struct S{}; |
| 140 |
const auto foo() { return 0; } // expected-warning {{'const' type qualifier on return type has no effect}} |
| 141 |
const auto bar() { return S{}; } |
| 142 |
template <typename T> |
| 143 |
const auto baz() { return T{}; } |
| 144 |
|
| 145 |
void test() { |
| 146 |
baz<int>(); |
| 147 |
baz<S>(); |
| 148 |
|
| 149 |
[]() -> const auto { // expected-warning {{'const' type qualifier on return type has no effect}} |
| 150 |
return 0; |
| 151 |
}(); |
| 152 |
|
| 153 |
[]() -> const auto { |
| 154 |
return S{}; |
| 155 |
}(); |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
#endif |