| 1 |
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify -Wno-strict-prototypes %s |
| 2 |
// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wno-strict-prototypes %s |
| 3 |
|
| 4 |
int x __attribute__((constructor)); // expected-warning {{'constructor' attribute only applies to functions}} |
| 5 |
int f(void) __attribute__((constructor)); |
| 6 |
int f(void) __attribute__((constructor(1))); |
| 7 |
int f(void) __attribute__((constructor(1,2))); // expected-error {{'constructor' attribute takes no more than 1 argument}} |
| 8 |
int f(void) __attribute__((constructor(1.0))); // expected-error {{'constructor' attribute requires an integer constant}} |
| 9 |
int f(void) __attribute__((constructor(0x100000000))); // expected-error {{integer constant expression evaluates to value 4294967296 that cannot be represented in a 32-bit unsigned integer type}} |
| 10 |
void knr() __attribute__((constructor)); |
| 11 |
|
| 12 |
#ifdef __cplusplus |
| 13 |
template <float P> [[gnu::constructor(P)]] void f(); // expected-error {{'gnu::constructor' attribute requires an integer constant}} |
| 14 |
template <double P> [[gnu::constructor(P)]] void f(); // expected-error {{'gnu::constructor' attribute requires an integer constant}} |
| 15 |
template <int *P> [[gnu::constructor(P)]] void f(); // expected-error {{'gnu::constructor' attribute requires an integer constant}} |
| 16 |
|
| 17 |
template <long long P> [[gnu::constructor(P)]] void f() {} // expected-error {{integer constant expression evaluates to value 4294967296 that cannot be represented in a 32-bit unsigned integer type}} |
| 18 |
template void f<1LL<<32>(); // expected-note {{in instantiation of function template specialization 'f<4294967296LL>' requested here}} |
| 19 |
template void f<101>(); |
| 20 |
|
| 21 |
template <typename T> [[gnu::constructor(static_cast<T>(1LL<<32))]] void f() {} // expected-error {{integer constant expression evaluates to value 4294967296 that cannot be represented in a 32-bit unsigned integer type}} |
| 22 |
template void f<long long>(); // expected-note {{in instantiation of function template specialization 'f<long long>' requested here}} |
| 23 |
template void f<int>(); |
| 24 |
|
| 25 |
template <typename T> |
| 26 |
[[gnu::constructor(static_cast<T>(101))]] void g() {} |
| 27 |
template void g<int>(); |
| 28 |
template void g<long long>(); |
| 29 |
|
| 30 |
template <typename T> |
| 31 |
[[gnu::constructor(static_cast<T>(T{101}))]] void h() {} |
| 32 |
template void h<int>(); |
| 33 |
template void h<long long>(); |
| 34 |
|
| 35 |
template <typename T> |
| 36 |
[[gnu::constructor(static_cast<T>(sizeof(T[101])))]] void a() {} |
| 37 |
template void a<int>(); |
| 38 |
template void a<long long>(); |
| 39 |
#endif |
| 40 |
|
| 41 |
int yd __attribute__((destructor)); // expected-warning {{'destructor' attribute only applies to functions}} |
| 42 |
int fd(void) __attribute__((destructor)); |
| 43 |
int fd(void) __attribute__((destructor(1))); |
| 44 |
int fd(void) __attribute__((destructor(1,2))); // expected-error {{'destructor' attribute takes no more than 1 argument}} |
| 45 |
int fd(void) __attribute__((destructor(1.0))); // expected-error {{'destructor' attribute requires an integer constant}} |
| 46 |
|
| 47 |
#ifdef __cplusplus |
| 48 |
template <float P> [[gnu::destructor(P)]] void fd(); // expected-error {{'gnu::destructor' attribute requires an integer constant}} |
| 49 |
template <double P> [[gnu::destructor(P)]] void fd(); // expected-error {{'gnu::destructor' attribute requires an integer constant}} |
| 50 |
template <int *P> [[gnu::destructor(P)]] void fd(); // expected-error {{'gnu::destructor' attribute requires an integer constant}} |
| 51 |
|
| 52 |
template <long long P> [[gnu::destructor(P)]] void fd() {} // expected-error {{integer constant expression evaluates to value 4294967296 that cannot be represented in a 32-bit unsigned integer type}} |
| 53 |
template void fd<1LL<<32>(); // expected-note {{in instantiation of function template specialization 'fd<4294967296LL>' requested here}} |
| 54 |
template void fd<101>(); |
| 55 |
|
| 56 |
template <typename T> [[gnu::destructor(static_cast<T>(1LL<<32))]] void fd() {} // expected-error {{integer constant expression evaluates to value 4294967296 that cannot be represented in a 32-bit unsigned integer type}} |
| 57 |
template void fd<long long>(); // expected-note {{in instantiation of function template specialization 'fd<long long>' requested here}} |
| 58 |
template void fd<int>(); |
| 59 |
|
| 60 |
template <typename T> |
| 61 |
[[gnu::destructor(static_cast<T>(101))]] void gd() {} |
| 62 |
template void gd<int>(); |
| 63 |
template void gd<long long>(); |
| 64 |
|
| 65 |
template <typename T> |
| 66 |
[[gnu::destructor(static_cast<T>(T{101}))]] void hd() {} |
| 67 |
template void hd<int>(); |
| 68 |
template void hd<long long>(); |
| 69 |
|
| 70 |
template <typename T> |
| 71 |
[[gnu::destructor(static_cast<T>(sizeof(T[101])))]] void ad() {} |
| 72 |
template void ad<int>(); |
| 73 |
template void ad<long long>(); |
| 74 |
#endif |