brintos

brintos / llvm-project-archived public Read only

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