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