111 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 = 0x0p0; // no literal7 static_assert(is_same<decltype(v0), const double>::value, "");8 static_assert(v0 == 0, "");9 10 // Float11 12 static constexpr auto v1 = 0xfp0f;13 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase14 // CHECK-FIXES: static constexpr auto v1 = 0xfp0F;15 static_assert(is_same<decltype(v1), const float>::value, "");16 static_assert(v1 == 15, "");17 18 static constexpr auto v2 = 0xfp0F; // OK19 static_assert(is_same<decltype(v2), const float>::value, "");20 static_assert(v2 == 15, "");21 22 static constexpr auto v3 = 0xfP0f;23 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase24 // CHECK-FIXES: static constexpr auto v3 = 0xfP0F;25 static_assert(is_same<decltype(v3), const float>::value, "");26 static_assert(v3 == 15, "");27 28 static constexpr auto v4 = 0xfP0F; // OK29 static_assert(is_same<decltype(v4), const float>::value, "");30 static_assert(v4 == 15, "");31 32 static constexpr auto v5 = 0xFP0f;33 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase34 // CHECK-FIXES: static constexpr auto v5 = 0xFP0F;35 static_assert(is_same<decltype(v5), const float>::value, "");36 static_assert(v5 == 15, "");37 38 static constexpr auto v6 = 0xFP0F; // OK39 static_assert(is_same<decltype(v6), const float>::value, "");40 static_assert(v6 == 15, "");41 42 static constexpr auto v7 = 0xFp0f;43 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'f', which is not uppercase44 // CHECK-FIXES: static constexpr auto v7 = 0xFp0F;45 static_assert(is_same<decltype(v7), const float>::value, "");46 static_assert(v7 == 15, "");47 48 static constexpr auto v8 = 0xFp0F; // OK49 static_assert(is_same<decltype(v8), const float>::value, "");50 static_assert(v8 == 15, "");51 52 // long double53 54 static constexpr auto v9 = 0xfp0l;55 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'l', which is not uppercase56 // CHECK-FIXES: static constexpr auto v9 = 0xfp0L;57 static_assert(is_same<decltype(v9), const long double>::value, "");58 static_assert(v9 == 0xfp0, "");59 60 static constexpr auto v10 = 0xfp0L; // OK.61 static_assert(is_same<decltype(v10), const long double>::value, "");62 static_assert(v10 == 0xfp0, "");63 64 // __float12865 66 static constexpr auto v11 = 0xfp0q;67 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'q', which is not uppercase68 // CHECK-FIXES: static constexpr auto v11 = 0xfp0Q;69 static_assert(is_same<decltype(v11), const __float128>::value, "");70 static_assert(v11 == 0xfp0, "");71 72 static constexpr auto v12 = 0xfp0Q; // OK.73 static_assert(is_same<decltype(v12), const __float128>::value, "");74 static_assert(v12 == 0xfp0, "");75}76 77void floating_point_complex_suffix() {78 // _Complex, I79 80 static constexpr auto v14 = 0xfp0i;81 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'i', which is not uppercase82 // CHECK-FIXES: static constexpr auto v14 = 0xfp0I;83 static_assert(is_same<decltype(v14), const _Complex double>::value, "");84 static_assert(v14 == 0xfp0I, "");85 86 static constexpr auto v16 = 0xfp0I; // OK.87 static_assert(is_same<decltype(v16), const _Complex double>::value, "");88 static_assert(v16 == 0xfp0I, "");89 90 // _Complex, J91 92 static constexpr auto v18 = 0xfp0j;93 // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'j', which is not uppercase94 // CHECK-FIXES: static constexpr auto v18 = 0xfp0J;95 static_assert(is_same<decltype(v18), const _Complex double>::value, "");96 static_assert(v18 == 0xfp0J, "");97 98 static constexpr auto v20 = 0xfp0J; // OK.99 static_assert(is_same<decltype(v20), const _Complex double>::value, "");100 static_assert(v20 == 0xfp0J, "");101}102 103void macros() {104#define PASSTHROUGH(X) X105 static constexpr auto m0 = PASSTHROUGH(0x0p0f);106 // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: floating point literal has suffix 'f', which is not uppercase107 // CHECK-FIXES: static constexpr auto m0 = PASSTHROUGH(0x0p0F);108 static_assert(is_same<decltype(m0), const float>::value, "");109 static_assert(m0 == 0x0p0F, "");110}111