brintos

brintos / llvm-project-archived public Read only

0
0
Text · 10.3 KiB · 6602fd9 Raw
265 lines · cpp
1// TODO: When Clang adds support for C++23 floating-point types, enable these tests by:2//    1. Removing all the #if 0 + #endif guards.3//    2. Removing all occurrences of the string "DISABLED-" in this file.4//    3. Deleting this message.5// These suffixes may be relevant to C too: https://github.com/llvm/llvm-project/issues/973356 7// RUN: %check_clang_tidy -std=c++23-or-later %s readability-uppercase-literal-suffix %t -- -- -target aarch64-linux-gnu -I %clang_tidy_headers8 9#include "integral_constant.h"10#include <cstddef>11#if 012#include <stdfloat>13#endif14 15void normal_literals() {16  // std::bfloat16_t17 18#if 019  static constexpr auto v1 = 1.bf16;20  // DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'bf16', which is not uppercase21  // DISABLED-CHECK-FIXES: static constexpr auto v1 = 1.BF16;22  static_assert(is_same<decltype(v1), const std::bfloat16_t>::value, "");23  static_assert(v1 == 1.BF16, "");24 25  static constexpr auto v2 = 1.e0bf16;26  // DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'bf16', which is not uppercase27  // DISABLED-CHECK-FIXES: static constexpr auto v2 = 1.e0BF16;28  static_assert(is_same<decltype(v2), const std::bfloat16_t>::value, "");29  static_assert(v2 == 1.BF16, "");30 31  static constexpr auto v3 = 1.BF16; // OK.32  static_assert(is_same<decltype(v3), const std::bfloat16_t>::value, "");33  static_assert(v3 == 1.BF16, "");34 35  static constexpr auto v4 = 1.e0BF16; // OK.36  static_assert(is_same<decltype(v4), const std::bfloat16_t>::value, "");37  static_assert(v4 == 1.BF16, "");38#endif39 40  // _Float16/std::float16_t41 42  static constexpr auto v5 = 1.f16;43  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f16', which is not uppercase44  // CHECK-FIXES: static constexpr auto v5 = 1.F16;45  static_assert(is_same<decltype(v5), const _Float16>::value, "");46  static_assert(v5 == 1.F16, "");47 48  static constexpr auto v6 = 1.e0f16;49  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f16', which is not uppercase50  // CHECK-FIXES: static constexpr auto v6 = 1.e0F16;51  static_assert(is_same<decltype(v6), const _Float16>::value, "");52  static_assert(v6 == 1.F16, "");53 54  static constexpr auto v7 = 1.F16; // OK.55  static_assert(is_same<decltype(v7), const _Float16>::value, "");56  static_assert(v7 == 1.F16, "");57 58  static constexpr auto v8 = 1.e0F16; // OK.59  static_assert(is_same<decltype(v8), const _Float16>::value, "");60  static_assert(v8 == 1.F16, "");61 62  // std::float32_t63 64#if 065  static constexpr auto v9 = 1.f32;66  // DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f32', which is not uppercase67  // DISABLED-CHECK-FIXES: static constexpr auto v9 = 1.F32;68  static_assert(is_same<decltype(v9), const std::float32_t>::value, "");69  static_assert(v9 == 1.F32, "");70 71  static constexpr auto v10 = 1.e0f32;72  // DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'f32', which is not uppercase73  // DISABLED-CHECK-FIXES: static constexpr auto v10 = 1.e0F32;74  static_assert(is_same<decltype(v10), const std::float32_t>::value, "");75  static_assert(v10 == 1.F32, "");76 77  static constexpr auto v11 = 1.F32; // OK.78  static_assert(is_same<decltype(v11), const std::float32_t>::value, "");79  static_assert(v11 == 1.F32, "");80 81  static constexpr auto v12 = 1.e0F32; // OK.82  static_assert(is_same<decltype(v12), const std::float32_t>::value, "");83  static_assert(v12 == 1.F32, "");84#endif85 86  // std::float64_t87 88#if 089  static constexpr auto v13 = 1.f64;90  // DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'f64', which is not uppercase91  // DISABLED-CHECK-FIXES: static constexpr auto v13 = 1.F64;92  static_assert(is_same<decltype(v13), const std::float64_t>::value, "");93  static_assert(v13 == 1.F64, "");94 95  static constexpr auto v14 = 1.e0f64;96  // DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'f64', which is not uppercase97  // DISABLED-CHECK-FIXES: static constexpr auto v14 = 1.e0F64;98  static_assert(is_same<decltype(v14), const std::float64_t>::value, "");99  static_assert(v14 == 1.F64, "");100 101  static constexpr auto v15 = 1.F64; // OK.102  static_assert(is_same<decltype(v15), const std::float64_t>::value, "");103  static_assert(v15 == 1.F64, "");104 105  static constexpr auto v16 = 1.e0F64; // OK.106  static_assert(is_same<decltype(v16), const std::float64_t>::value, "");107  static_assert(v16 == 1.F64, "");108#endif109 110  // std::float128_t111 112#if 0113  static constexpr auto v17 = 1.f128;114  // DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'f128', which is not uppercase115  // DISABLED-CHECK-FIXES: static constexpr auto v17 = 1.F128;116  static_assert(is_same<decltype(v17), const std::float128_t>::value, "");117  static_assert(v17 == 1.F128, "");118 119  static constexpr auto v18 = 1.e0f128;120  // DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'f128', which is not uppercase121  // DISABLED-CHECK-FIXES: static constexpr auto v18 = 1.e0F128;122  static_assert(is_same<decltype(v18), const std::float128_t>::value, "");123  static_assert(v18 == 1.F128, "");124 125  static constexpr auto v19 = 1.F128; // OK.126  static_assert(is_same<decltype(v19), const std::float128_t>::value, "");127  static_assert(v19 == 1.F128, "");128 129  static constexpr auto v20 = 1.e0F128; // OK.130  static_assert(is_same<decltype(v20), const std::float128_t>::value, "");131  static_assert(v20 == 1.F128, "");132#endif133}134 135void hexadecimal_literals() {136  // std::bfloat16_t137 138#if 0139  static constexpr auto v1 = 0xfp0bf16;140  // DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'bf16', which is not uppercase141  // DISABLED-CHECK-FIXES: static constexpr auto v1 = 0xfp0BF16;142  static_assert(is_same<decltype(v1), const std::bfloat16_t>::value, "");143  static_assert(v1 == 0xfp0BF16, "");144 145  static constexpr auto v2 = 0xfp0BF16; // OK.146  static_assert(is_same<decltype(v2), const std::bfloat16_t>::value, "");147  static_assert(v2 == 0xfp0BF16, "");148#endif149 150  // _Float16/std::float16_t151 152  static constexpr auto v3 = 0xfp0f16;153  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f16', which is not uppercase154  // CHECK-FIXES: static constexpr auto v3 = 0xfp0F16;155  static_assert(is_same<decltype(v3), const _Float16>::value, "");156  static_assert(v3 == 0xfp0F16, "");157 158  static constexpr auto v4 = 0xfp0F16; // OK.159  static_assert(is_same<decltype(v4), const _Float16>::value, "");160  static_assert(v4 == 0xfp0F16, "");161 162  // std::float32_t163 164#if 0165  static constexpr auto v5 = 0xfp0f32;166  // DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f32', which is not uppercase167  // DISABLED-CHECK-FIXES: static constexpr auto v5 = 0xfp0F32;168  static_assert(is_same<decltype(v5), const std::float32_t>::value, "");169  static_assert(v5 == 0xfp0F32, "");170 171  static constexpr auto v6 = 0xfp0F32; // OK.172  static_assert(is_same<decltype(v6), const std::float32_t>::value, "");173  static_assert(v6 == 0xfp0F32, "");174#endif175 176  // std::float64_t177 178#if 0179  static constexpr auto v7 = 0xfp0f64;180  // DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f64', which is not uppercase181  // DISABLED-CHECK-FIXES: static constexpr auto v7 = 0xfp0F64;182  static_assert(is_same<decltype(v7), const std::float64_t>::value, "");183  static_assert(v7 == 0xfp0F64, "");184 185  static constexpr auto v8 = 0xfp0F64; // OK.186  static_assert(is_same<decltype(v8), const std::float64_t>::value, "");187  static_assert(v8 == 0xfp0F64, "");188#endif189 190  // std::float128_t191 192#if 0193  static constexpr auto v9 = 0xfp0f128;194  // DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f128', which is not uppercase195  // DISABLED-CHECK-FIXES: static constexpr auto v9 = 0xfp0F128;196  static_assert(is_same<decltype(v9), const std::float128_t>::value, "");197  static_assert(v9 == 0xfp0F128, "");198 199  static constexpr auto v10 = 0xfp0F128; // OK.200  static_assert(is_same<decltype(v10), const std::float128_t>::value, "");201  static_assert(v10 == 0xfp0F128, "");202#endif203 204}205 206void size_t_suffix() {207  // Signed208 209  static constexpr auto v29 = 1z;210  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'z', which is not uppercase211  // CHECK-FIXES: static constexpr auto v29 = 1Z;212  static_assert(v29 == 1Z, "");213 214  static constexpr auto v30 = 1Z; // OK.215  static_assert(v30 == 1Z, "");216 217  // size_t Unsigned218 219  static constexpr auto v31 = 1zu;220  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'zu', which is not uppercase221  // CHECK-FIXES: static constexpr auto v31 = 1ZU;222  static_assert(is_same<decltype(v31), const size_t>::value, "");223  static_assert(v31 == 1ZU, "");224 225  static constexpr auto v32 = 1Zu;226  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'Zu', which is not uppercase227  // CHECK-FIXES: static constexpr auto v32 = 1ZU;228  static_assert(is_same<decltype(v32), const size_t>::value, "");229  static_assert(v32 == 1ZU, "");230 231  static constexpr auto v33 = 1zU;232  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'zU', which is not uppercase233  // CHECK-FIXES: static constexpr auto v33 = 1ZU;234  static_assert(is_same<decltype(v33), const size_t>::value, "");235  static_assert(v33 == 1ZU, "");236 237  static constexpr auto v34 = 1ZU; // OK.238  static_assert(is_same<decltype(v34), const size_t>::value, "");239  static_assert(v34 == 1ZU, "");240 241  // Unsigned size_t242 243  static constexpr auto v35 = 1uz;244  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'uz', which is not uppercase245  // CHECK-FIXES: static constexpr auto v35 = 1UZ;246  static_assert(is_same<decltype(v35), const size_t>::value, "");247  static_assert(v35 == 1UZ);248 249  static constexpr auto v36 = 1uZ;250  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'uZ', which is not uppercase251  // CHECK-FIXES: static constexpr auto v36 = 1UZ;252  static_assert(is_same<decltype(v36), const size_t>::value, "");253  static_assert(v36 == 1UZ);254 255  static constexpr auto v37 = 1Uz;256  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'Uz', which is not uppercase257  // CHECK-FIXES: static constexpr auto v37 = 1UZ;258  static_assert(is_same<decltype(v37), const size_t>::value, "");259  static_assert(v37 == 1UZ);260 261  static constexpr auto v38 = 1UZ; // OK.262  static_assert(is_same<decltype(v38), const size_t>::value, "");263  static_assert(v38 == 1UZ);264}265