Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaCXX / size_t-literal.cpp
blob73be677d47bd2740656579ec0aae3c21560e6991
1 // RUN: %clang_cc1 -std=c++23 -triple x86_64-linux -Wpre-c++23-compat -fsyntax-only -verify=cxx23 %s
2 // RUN: %clang_cc1 -std=c++20 -triple x86_64-linux -fsyntax-only -verify=cxx20 %s
3 // RUN: %clang_cc1 -std=c++23 -triple i686-linux -fsyntax-only -verify=cxx23-32 %s
4 // RUN: %clang_cc1 -x c -std=c11 -fsyntax-only -verify=c11 %s
6 #ifdef __cplusplus
8 typedef __SIZE_TYPE__ size_t;
9 // Assume ptrdiff_t is the signed integer type corresponding to size_t.
10 typedef __PTRDIFF_TYPE__ ssize_t;
12 template <typename, typename>
13 struct is_same { static constexpr bool value = false; };
15 template <typename T>
16 struct is_same<T, T> { static constexpr bool value = true; };
18 void SSizeT(void) {
19 auto a1 = 1z;
20 // cxx23-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++23}}
21 // cxx20-warning@-2 {{'size_t' suffix for literals is a C++23 extension}}
22 static_assert(is_same<decltype(a1), ssize_t>::value);
24 auto a2 = 1Z;
25 // cxx23-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++23}}
26 // cxx20-warning@-2 {{'size_t' suffix for literals is a C++23 extension}}
27 static_assert(is_same<decltype(a2), ssize_t>::value);
30 void SizeT(void) {
31 auto a1 = 1uz;
32 // cxx23-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++23}}
33 // cxx20-warning@-2 {{'size_t' suffix for literals is a C++23 extension}}
34 static_assert(is_same<decltype(a1), size_t>::value);
36 auto a2 = 1uZ;
37 // cxx23-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++23}}
38 // cxx20-warning@-2 {{'size_t' suffix for literals is a C++23 extension}}
39 static_assert(is_same<decltype(a2), size_t>::value);
41 auto a3 = 1Uz;
42 // cxx23-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++23}}
43 // cxx20-warning@-2 {{'size_t' suffix for literals is a C++23 extension}}
44 static_assert(is_same<decltype(a3), size_t>::value);
46 auto a4 = 1UZ;
47 // cxx23-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++23}}
48 // cxx20-warning@-2 {{'size_t' suffix for literals is a C++23 extension}}
49 static_assert(is_same<decltype(a4), size_t>::value);
51 auto a5 = 1zu;
52 // cxx23-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++23}}
53 // cxx20-warning@-2 {{'size_t' suffix for literals is a C++23 extension}}
54 static_assert(is_same<decltype(a5), size_t>::value);
56 auto a6 = 1Zu;
57 // cxx23-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++23}}
58 // cxx20-warning@-2 {{'size_t' suffix for literals is a C++23 extension}}
59 static_assert(is_same<decltype(a6), size_t>::value);
61 auto a7 = 1zU;
62 // cxx23-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++23}}
63 // cxx20-warning@-2 {{'size_t' suffix for literals is a C++23 extension}}
64 static_assert(is_same<decltype(a7), size_t>::value);
66 auto a8 = 1ZU;
67 // cxx23-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++23}}
68 // cxx20-warning@-2 {{'size_t' suffix for literals is a C++23 extension}}
69 static_assert(is_same<decltype(a8), size_t>::value);
72 void oor(void) {
73 #if __i386__
74 (void)3'000'000'000z; // cxx23-32-error {{signed 'size_t' literal is out of range of possible signed 'size_t' values}}
75 (void)3'000'000'000uz;
76 (void)5'000'000'000uz; // cxx23-32-error {{'size_t' literal is out of range of possible 'size_t' values}}
78 (void)0x80000000z;
79 (void)0x80000000uz;
80 (void)0x180000000uz; //cxx23-32-error {{'size_t' literal is out of range of possible 'size_t' values}}
81 #endif
84 #else
86 void f(void) {
87 (void)1z; // c11-error {{'size_t' suffix for literals is a C++23 feature}}
88 (void)1Z; // c11-error {{'size_t' suffix for literals is a C++23 feature}}
89 (void)1uz; // c11-error {{'size_t' suffix for literals is a C++23 feature}}
90 (void)1uZ; // c11-error {{'size_t' suffix for literals is a C++23 feature}}
91 (void)1Uz; // c11-error {{'size_t' suffix for literals is a C++23 feature}}
92 (void)1UZ; // c11-error {{'size_t' suffix for literals is a C++23 feature}}
93 (void)1zu; // c11-error {{'size_t' suffix for literals is a C++23 feature}}
94 (void)1Zu; // c11-error {{'size_t' suffix for literals is a C++23 feature}}
95 (void)1zU; // c11-error {{'size_t' suffix for literals is a C++23 feature}}
96 (void)1ZU; // c11-error {{'size_t' suffix for literals is a C++23 feature}}
99 #endif