| 1 |
// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify %s |
| 2 |
|
| 3 |
// Check that we emit the correct warnings in various situations where the C++11 |
| 4 |
// spelling of the `address_space` attribute is applied to a declaration instead |
| 5 |
// of a type. Also check that the attribute can instead be applied to the type. |
| 6 |
|
| 7 |
void f([[clang::address_space(1)]] int* param) { // expected-warning {{applying attribute 'clang::address_space' to a declaration is deprecated; apply it to the type instead}} |
| 8 |
[[clang::address_space(1)]] int* local1; // expected-warning {{applying attribute 'clang::address_space' to a declaration is deprecated; apply it to the type instead}} |
| 9 |
int* local2 [[clang::address_space(1)]]; // expected-error {{automatic variable qualified with an address space}} expected-warning {{applying attribute 'clang::address_space' to a declaration is deprecated; apply it to the type instead}} |
| 10 |
int [[clang::address_space(1)]] * local3; |
| 11 |
int* [[clang::address_space(1)]] local4; // expected-error {{automatic variable qualified with an address space}} |
| 12 |
|
| 13 |
for ([[clang::address_space(1)]] int* p = nullptr; p; ++p) {} // expected-warning {{applying attribute 'clang::address_space' to a declaration is deprecated; apply it to the type instead}} |
| 14 |
for (; [[clang::address_space(1)]] int* p = nullptr; ) {} // expected-warning {{applying attribute 'clang::address_space' to a declaration is deprecated; apply it to the type instead}} |
| 15 |
while([[clang::address_space(1)]] int* p = nullptr) {} // expected-warning {{applying attribute 'clang::address_space' to a declaration is deprecated; apply it to the type instead}} |
| 16 |
if ([[clang::address_space(1)]] int* p = nullptr) {} // expected-warning {{applying attribute 'clang::address_space' to a declaration is deprecated; apply it to the type instead}} |
| 17 |
try { |
| 18 |
} catch([[clang::address_space(1)]] int& i) { // expected-warning {{applying attribute 'clang::address_space' to a declaration is deprecated; apply it to the type instead}} |
| 19 |
} |
| 20 |
|
| 21 |
for (int [[clang::address_space(1)]] * p = nullptr; p; ++p) {} |
| 22 |
for (; int [[clang::address_space(1)]] * p = nullptr; ) {} |
| 23 |
while(int [[clang::address_space(1)]] * p = nullptr) {} |
| 24 |
if (int [[clang::address_space(1)]] * p = nullptr) {} |
| 25 |
try { |
| 26 |
} catch(int [[clang::address_space(1)]] & i) { |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
[[clang::address_space(1)]] int* return_value(); // expected-warning {{applying attribute 'clang::address_space' to a declaration is deprecated; apply it to the type instead}} |
| 31 |
int [[clang::address_space(1)]] * return_value(); |
| 32 |
|
| 33 |
[[clang::address_space(1)]] int global1; // expected-warning {{applying attribute 'clang::address_space' to a declaration is deprecated; apply it to the type instead}} |
| 34 |
int global2 [[clang::address_space(1)]]; // expected-warning {{applying attribute 'clang::address_space' to a declaration is deprecated; apply it to the type instead}} |
| 35 |
int [[clang::address_space(1)]] global3; |
| 36 |
int [[clang::address_space(1)]] global4; |
| 37 |
|
| 38 |
struct [[clang::address_space(1)]] S { // expected-error {{'clang::address_space' attribute cannot be applied to a declaration}} |
| 39 |
[[clang::address_space(1)]] int* member_function_1(); // expected-warning {{applying attribute 'clang::address_space' to a declaration is deprecated; apply it to the type instead}} |
| 40 |
int [[clang::address_space(1)]] * member_function_2(); |
| 41 |
}; |
| 42 |
|
| 43 |
template <class T> |
| 44 |
[[clang::address_space(1)]] T var_template_1; // expected-warning {{applying attribute 'clang::address_space' to a declaration is deprecated; apply it to the type instead}} |
| 45 |
template <class T> |
| 46 |
T [[clang::address_space(1)]] var_template_2; |
| 47 |
|
| 48 |
using void_ptr [[clang::address_space(1)]] = void *; // expected-warning {{applying attribute 'clang::address_space' to a declaration is deprecated; apply it to the type instead}} |
| 49 |
// Intentionally using the same alias name to check that the aliases define the |
| 50 |
// same type. |
| 51 |
using void_ptr = void [[clang::address_space(1)]] *; |
| 52 |
|
| 53 |
namespace N {} |
| 54 |
[[clang::address_space(1)]] using namespace N; // expected-error {{'clang::address_space' attribute cannot be applied to a declaration}} |