brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.3 KiB · fc1976b Raw
135 lines · cpp
1// RUN: %check_clang_tidy %s readability-uppercase-literal-suffix %t -- -- -target x86_64-pc-linux-gnu -I %clang_tidy_headers2 3#include "integral_constant.h"4 5void floating_point_suffix() {6  static constexpr auto v0 = 1.; // no literal7  static_assert(is_same<decltype(v0), const double>::value, "");8  static_assert(v0 == 1., "");9 10  static constexpr auto v1 = 1.e0; // no literal11  static_assert(is_same<decltype(v1), const double>::value, "");12  static_assert(v1 == 1., "");13 14  // Float15 16  static constexpr auto v2 = 1.f;17  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase18  // CHECK-FIXES: static constexpr auto v2 = 1.F;19  static_assert(is_same<decltype(v2), const float>::value, "");20  static_assert(v2 == 1.0F, "");21 22  static constexpr auto v3 = 1.e0f;23  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase24  // CHECK-FIXES: static constexpr auto v3 = 1.e0F;25  static_assert(is_same<decltype(v3), const float>::value, "");26  static_assert(v3 == 1.0F, "");27 28  static constexpr auto v4 = 1.F; // OK.29  static_assert(is_same<decltype(v4), const float>::value, "");30  static_assert(v4 == 1.0F, "");31 32  static constexpr auto v5 = 1.e0F; // OK.33  static_assert(is_same<decltype(v5), const float>::value, "");34  static_assert(v5 == 1.0F, "");35 36  // Long double37 38  static constexpr auto v6 = 1.l;39  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'l', which is not uppercase40  // CHECK-FIXES: static constexpr auto v6 = 1.L;41  static_assert(is_same<decltype(v6), const long double>::value, "");42  static_assert(v6 == 1., "");43 44  static constexpr auto v7 = 1.e0l;45  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'l', which is not uppercase46  // CHECK-FIXES: static constexpr auto v7 = 1.e0L;47  static_assert(is_same<decltype(v7), const long double>::value, "");48  static_assert(v7 == 1., "");49 50  static constexpr auto v8 = 1.L; // OK.51  static_assert(is_same<decltype(v8), const long double>::value, "");52  static_assert(v8 == 1., "");53 54  static constexpr auto v9 = 1.e0L; // OK.55  static_assert(is_same<decltype(v9), const long double>::value, "");56  static_assert(v9 == 1., "");57 58  // __float12859 60  static constexpr auto v10 = 1.q;61  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'q', which is not uppercase62  // CHECK-FIXES: static constexpr auto v10 = 1.Q;63  static_assert(is_same<decltype(v10), const __float128>::value, "");64  static_assert(v10 == 1., "");65 66  static constexpr auto v11 = 1.e0q;67  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'q', which is not uppercase68  // CHECK-FIXES: static constexpr auto v11 = 1.e0Q;69  static_assert(is_same<decltype(v11), const __float128>::value, "");70  static_assert(v11 == 1., "");71 72  static constexpr auto v12 = 1.Q; // OK.73  static_assert(is_same<decltype(v12), const __float128>::value, "");74  static_assert(v12 == 1., "");75 76  static constexpr auto v13 = 1.e0Q; // OK.77  static_assert(is_same<decltype(v13), const __float128>::value, "");78  static_assert(v13 == 1., "");79}80 81void floating_point_complex_suffix() {82  // _Complex, I83 84  static constexpr auto v14 = 1.i;85  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'i', which is not uppercase86  // CHECK-FIXES: static constexpr auto v14 = 1.I;87  static_assert(is_same<decltype(v14), const _Complex double>::value, "");88  static_assert(v14 == 1.I, "");89 90  static constexpr auto v15 = 1.e0i;91  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'i', which is not uppercase92  // CHECK-FIXES: static constexpr auto v15 = 1.e0I;93  static_assert(is_same<decltype(v15), const _Complex double>::value, "");94  static_assert(v15 == 1.I, "");95 96  static constexpr auto v16 = 1.I; // OK.97  static_assert(is_same<decltype(v16), const _Complex double>::value, "");98  static_assert(v16 == 1.I, "");99 100  static constexpr auto v17 = 1.e0I; // OK.101  static_assert(is_same<decltype(v17), const _Complex double>::value, "");102  static_assert(v17 == 1.I, "");103 104  // _Complex, J105 106  static constexpr auto v18 = 1.j;107  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'j', which is not uppercase108  // CHECK-FIXES: static constexpr auto v18 = 1.J;109  static_assert(is_same<decltype(v18), const _Complex double>::value, "");110  static_assert(v18 == 1.J, "");111 112  static constexpr auto v19 = 1.e0j;113  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'j', which is not uppercase114  // CHECK-FIXES: static constexpr auto v19 = 1.e0J;115  static_assert(is_same<decltype(v19), const _Complex double>::value, "");116  static_assert(v19 == 1.J, "");117 118  static constexpr auto v20 = 1.J; // OK.119  static_assert(is_same<decltype(v20), const _Complex double>::value, "");120  static_assert(v20 == 1.J, "");121 122  static constexpr auto v21 = 1.e0J; // OK.123  static_assert(is_same<decltype(v21), const _Complex double>::value, "");124  static_assert(v21 == 1.J, "");125}126 127void macros() {128#define PASSTHROUGH(X) X129  static constexpr auto m0 = PASSTHROUGH(1.f);130  // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: floating point literal has suffix 'f', which is not uppercase131  // CHECK-FIXES: static constexpr auto m0 = PASSTHROUGH(1.F);132  static_assert(is_same<decltype(m0), const float>::value, "");133  static_assert(m0 == 1.0F, "");134}135