Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
// RUN: %check_clang_tidy %s cert-dcl16-c %t -- -- -I %clang_tidy_headers
// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
// RUN: clang-tidy %t.cpp -checks='-*,cert-dcl16-c' -fix -- -I %clang_tidy_headers
// RUN: clang-tidy %t.cpp -checks='-*,cert-dcl16-c' -warnings-as-errors='-*,cert-dcl16-c' -- -I %clang_tidy_headers

#include "integral_constant.h"

void integer_suffix() {
static constexpr auto v0 = __LINE__; // synthetic
static_assert(v0 == 9 || v0 == 5, "");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm removing this assert (here and in 2 other places) because it depends on absolute line numbers. I considered changing it to relative numbers (static_assert(v0 == (__LINE__ - 1), "");), but I think it's better to remove it, because all we care about is that the check doesn't fire here, we don't care about line numbers at all.


static constexpr auto v1 = __cplusplus; // synthetic, long

static constexpr auto v2 = 1; // no literal
Expand All @@ -29,9 +24,6 @@ void integer_suffix() {

static constexpr auto v5 = 1l;
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'l', which is not uppercase
// CHECK-MESSAGES-NEXT: static constexpr auto v5 = 1l;
// CHECK-MESSAGES-NEXT: ^~
// CHECK-MESSAGES-NEXT: {{^ *| *}}L{{$}}
// CHECK-FIXES: static constexpr auto v5 = 1L;
static_assert(is_same<decltype(v5), const long>::value, "");
static_assert(v5 == 1, "");
Expand All @@ -44,9 +36,6 @@ void integer_suffix() {

static constexpr auto v7 = 1ll;
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'll', which is not uppercase
// CHECK-MESSAGES-NEXT: static constexpr auto v7 = 1ll;
// CHECK-MESSAGES-NEXT: ^~~
// CHECK-MESSAGES-NEXT: {{^ *| *}}LL{{$}}
// CHECK-FIXES: static constexpr auto v7 = 1LL;
static_assert(is_same<decltype(v7), const long long>::value, "");
static_assert(v7 == 1, "");
Expand Down Expand Up @@ -77,27 +66,18 @@ void integer_suffix() {

static constexpr auto v13 = 1lu;
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'lu', which is not uppercase
// CHECK-MESSAGES-NEXT: static constexpr auto v13 = 1lu;
// CHECK-MESSAGES-NEXT: ^~~
// CHECK-MESSAGES-NEXT: {{^ *| *}}LU{{$}}
// CHECK-FIXES: static constexpr auto v13 = 1LU;
static_assert(is_same<decltype(v13), const unsigned long>::value, "");
static_assert(v13 == 1, "");

static constexpr auto v14 = 1Lu;
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'Lu', which is not uppercase
// CHECK-MESSAGES-NEXT: static constexpr auto v14 = 1Lu;
// CHECK-MESSAGES-NEXT: ^~~
// CHECK-MESSAGES-NEXT: {{^ *| *}}LU{{$}}
// CHECK-FIXES: static constexpr auto v14 = 1LU;
static_assert(is_same<decltype(v14), const unsigned long>::value, "");
static_assert(v14 == 1, "");

static constexpr auto v15 = 1lU;
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'lU', which is not uppercase
// CHECK-MESSAGES-NEXT: static constexpr auto v15 = 1lU;
// CHECK-MESSAGES-NEXT: ^~~
// CHECK-MESSAGES-NEXT: {{^ *| *}}LU{{$}}
// CHECK-FIXES: static constexpr auto v15 = 1LU;
static_assert(is_same<decltype(v15), const unsigned long>::value, "");
static_assert(v15 == 1, "");
Expand Down Expand Up @@ -128,27 +108,18 @@ void integer_suffix() {

static constexpr auto v21 = 1llu;
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'llu', which is not uppercase
// CHECK-MESSAGES-NEXT: static constexpr auto v21 = 1llu;
// CHECK-MESSAGES-NEXT: ^~~~
// CHECK-MESSAGES-NEXT: {{^ *| *}}LLU{{$}}
// CHECK-FIXES: static constexpr auto v21 = 1LLU;
static_assert(is_same<decltype(v21), const unsigned long long>::value, "");
static_assert(v21 == 1, "");

static constexpr auto v22 = 1LLu;
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'LLu', which is not uppercase
// CHECK-MESSAGES-NEXT: static constexpr auto v22 = 1LLu;
// CHECK-MESSAGES-NEXT: ^~~~
// CHECK-MESSAGES-NEXT: {{^ *| *}}LLU{{$}}
// CHECK-FIXES: static constexpr auto v22 = 1LLU;
static_assert(is_same<decltype(v22), const unsigned long long>::value, "");
static_assert(v22 == 1, "");

static constexpr auto v23 = 1llU;
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: integer literal has suffix 'llU', which is not uppercase
// CHECK-MESSAGES-NEXT: static constexpr auto v23 = 1llU;
// CHECK-MESSAGES-NEXT: ^~~~
// CHECK-MESSAGES-NEXT: {{^ *| *}}LLU{{$}}
// CHECK-FIXES: static constexpr auto v23 = 1LLU;
static_assert(is_same<decltype(v23), const unsigned long long>::value, "");
static_assert(v23 == 1, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@
// 3. Deleting this message.

// RUN: %check_clang_tidy -std=c23-or-later %s readability-uppercase-literal-suffix %t
// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.c
// RUN: clang-tidy %t.c -checks='-*,readability-uppercase-literal-suffix' -fix -- -std=c23
// RUN: clang-tidy %t.c -checks='-*,readability-uppercase-literal-suffix' -warnings-as-errors='-*,readability-uppercase-literal-suffix' -- -std=c23

void bit_precise_literal_suffix() {
// _BitInt()

static constexpr auto v1 = 1wb;
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'wb', which is not uppercase
// CHECK-MESSAGES-NEXT: static constexpr auto v1 = 1wb;
// CHECK-MESSAGES-NEXT: ^~~
// CHECK-MESSAGES-NEXT: WB{{$}}
// CHECK-FIXES: static constexpr auto v1 = 1WB;
static_assert(v1 == 1WB);

Expand All @@ -26,25 +20,16 @@ void bit_precise_literal_suffix() {

static constexpr auto v3 = 1wbu;
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'wbu', which is not uppercase
// CHECK-MESSAGES-NEXT: static constexpr auto v3 = 1wbu;
// CHECK-MESSAGES-NEXT: ^~~~
// CHECK-MESSAGES-NEXT: WBU{{$}}
// CHECK-FIXES: static constexpr auto v3 = 1WBU;
static_assert(v3 == 1WBU);

static constexpr auto v4 = 1WBu;
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'WBu', which is not uppercase
// CHECK-MESSAGES-NEXT: static constexpr auto v4 = 1WBu;
// CHECK-MESSAGES-NEXT: ^~~~
// CHECK-MESSAGES-NEXT: WBU{{$}}
// CHECK-FIXES: static constexpr auto v4 = 1WBU;
static_assert(v4 == 1WBU);

static constexpr auto v5 = 1wbU;
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'wbU', which is not uppercase
// CHECK-MESSAGES-NEXT: static constexpr auto v5 = 1wbU;
// CHECK-MESSAGES-NEXT: ^~~~
// CHECK-MESSAGES-NEXT: WBU{{$}}
// CHECK-FIXES: static constexpr auto v5 = 1WBU;
static_assert(v5 == 1WBU);

Expand All @@ -55,25 +40,16 @@ void bit_precise_literal_suffix() {

static constexpr auto v7 = 1uwb;
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'uwb', which is not uppercase
// CHECK-MESSAGES-NEXT: static constexpr auto v7 = 1uwb;
// CHECK-MESSAGES-NEXT: ^~~~
// CHECK-MESSAGES-NEXT: UWB{{$}}
// CHECK-FIXES: static constexpr auto v7 = 1UWB;
static_assert(v7 == 1UWB);

static constexpr auto v8 = 1uWB;
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'uWB', which is not uppercase
// CHECK-MESSAGES-NEXT: static constexpr auto v8 = 1uWB;
// CHECK-MESSAGES-NEXT: ^~~~
// CHECK-MESSAGES-NEXT: UWB{{$}}
// CHECK-FIXES: static constexpr auto v8 = 1UWB;
static_assert(v8 == 1UWB);

static constexpr auto v9 = 1Uwb;
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: integer literal has suffix 'Uwb', which is not uppercase
// CHECK-MESSAGES-NEXT: static constexpr auto v9 = 1Uwb;
// CHECK-MESSAGES-NEXT: ^~~~
// CHECK-MESSAGES-NEXT: UWB{{$}}
// CHECK-FIXES: static constexpr auto v9 = 1UWB;
static_assert(v9 == 1UWB);

Expand All @@ -87,17 +63,11 @@ void decimal_floating_point_suffix() {
#if 0
static constexpr auto v1 = 1.df;
// DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'df', which is not uppercase
// DISABLED-CHECK-MESSAGES-NEXT: static constexpr auto v1 = 1.df;
// DISABLED-CHECK-MESSAGES-NEXT: ^ ~
// DISABLED-CHECK-MESSAGES-NEXT: DF{{$}}
// DISABLED-CHECK-FIXES: static constexpr auto v1 = 1.DF;
static_assert(v1 == 1.DF);

static constexpr auto v2 = 1.e0df;
// DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'df', which is not uppercase
// DISABLED-CHECK-MESSAGES-NEXT: static constexpr auto v2 = 1.e0df;
// DISABLED-CHECK-MESSAGES-NEXT: ^ ~
// DISABLED-CHECK-MESSAGES-NEXT: DF{{$}}
// DISABLED-CHECK-FIXES: static constexpr auto v2 = 1.e0DF;
static_assert(v2 == 1.DF);

Expand All @@ -113,17 +83,11 @@ void decimal_floating_point_suffix() {
#if 0
static constexpr auto v5 = 1.dd;
// DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'dd', which is not uppercase
// DISABLED-CHECK-MESSAGES-NEXT: static constexpr auto v5 = 1.dd;
// DISABLED-CHECK-MESSAGES-NEXT: ^ ~
// DISABLED-CHECK-MESSAGES-NEXT: DD{{$}}
// DISABLED-CHECK-FIXES: static constexpr auto v5 = 1.DD;
static_assert(v5 == 1.DD);

static constexpr auto v6 = 1.e0dd;
// DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'dd', which is not uppercase
// DISABLED-CHECK-MESSAGES-NEXT: static constexpr auto v6 = 1.e0dd;
// DISABLED-CHECK-MESSAGES-NEXT: ^ ~
// DISABLED-CHECK-MESSAGES-NEXT: DD{{$}}
// DISABLED-CHECK-FIXES: static constexpr auto v6 = 1.e0DD;
static_assert(v6 == 1.DD);

Expand All @@ -139,17 +103,11 @@ void decimal_floating_point_suffix() {
#if 0
static constexpr auto v9 = 1.dl;
// DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:30: warning: floating point literal has suffix 'dl', which is not uppercase
// DISABLED-CHECK-MESSAGES-NEXT: static constexpr auto v9 = 1.dl;
// DISABLED-CHECK-MESSAGES-NEXT: ^ ~
// DISABLED-CHECK-MESSAGES-NEXT: DL{{$}}
// DISABLED-CHECK-FIXES: static constexpr auto v9 = 1.DL;
static_assert(v9 == 1.DL);

static constexpr auto v10 = 1.e0dl;
// DISABLED-CHECK-MESSAGES: :[[@LINE-1]]:31: warning: floating point literal has suffix 'dl', which is not uppercase
// DISABLED-CHECK-MESSAGES-NEXT: static constexpr auto v10 = 1.e0dl;
// DISABLED-CHECK-MESSAGES-NEXT: ^ ~
// DISABLED-CHECK-MESSAGES-NEXT: DL{{$}}
// DISABLED-CHECK-FIXES: static constexpr auto v10 = 1.e0DL;
static_assert(v10 == 1.DL);

Expand Down
Loading
Loading