Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Expand Up @@ -29,67 +29,67 @@ std::string bar();
void tests(std::string s, global_string s2, std::string_view sv) {
s.find("a") == 0;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StartsWith instead of find() == 0 [abseil-string-find-startswith]
// CHECK-FIXES: {{^[[:space:]]*}}absl::StartsWith(s, "a");{{$}}
// CHECK-FIXES: absl::StartsWith(s, "a");

s.find(s) == 0;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StartsWith
// CHECK-FIXES: {{^[[:space:]]*}}absl::StartsWith(s, s);{{$}}
// CHECK-FIXES: absl::StartsWith(s, s);

s.find("aaa") != 0;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StartsWith
// CHECK-FIXES: {{^[[:space:]]*}}!absl::StartsWith(s, "aaa");{{$}}
// CHECK-FIXES: !absl::StartsWith(s, "aaa");

s.find(foo(foo(bar()))) != 0;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StartsWith
// CHECK-FIXES: {{^[[:space:]]*}}!absl::StartsWith(s, foo(foo(bar())));{{$}}
// CHECK-FIXES: !absl::StartsWith(s, foo(foo(bar())));

if (s.find("....") == 0) { /* do something */ }
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use absl::StartsWith
// CHECK-FIXES: {{^[[:space:]]*}}if (absl::StartsWith(s, "....")) { /* do something */ }{{$}}
// CHECK-FIXES: if (absl::StartsWith(s, "....")) { /* do something */ }

0 != s.find("a");
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StartsWith
// CHECK-FIXES: {{^[[:space:]]*}}!absl::StartsWith(s, "a");{{$}}
// CHECK-FIXES: !absl::StartsWith(s, "a");

s2.find("a") == 0;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StartsWith
// CHECK-FIXES: {{^[[:space:]]*}}absl::StartsWith(s2, "a");{{$}}
// CHECK-FIXES: absl::StartsWith(s2, "a");

s.rfind("a", 0) == 0;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StartsWith instead of rfind() == 0 [abseil-string-find-startswith]
// CHECK-FIXES: {{^[[:space:]]*}}absl::StartsWith(s, "a");{{$}}
// CHECK-FIXES: absl::StartsWith(s, "a");

s.rfind(s, 0) == 0;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StartsWith
// CHECK-FIXES: {{^[[:space:]]*}}absl::StartsWith(s, s);{{$}}
// CHECK-FIXES: absl::StartsWith(s, s);

s.rfind("aaa", 0) != 0;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StartsWith
// CHECK-FIXES: {{^[[:space:]]*}}!absl::StartsWith(s, "aaa");{{$}}
// CHECK-FIXES: !absl::StartsWith(s, "aaa");

s.rfind(foo(foo(bar())), 0) != 0;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StartsWith
// CHECK-FIXES: {{^[[:space:]]*}}!absl::StartsWith(s, foo(foo(bar())));{{$}}
// CHECK-FIXES: !absl::StartsWith(s, foo(foo(bar())));

if (s.rfind("....", 0) == 0) { /* do something */ }
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use absl::StartsWith
// CHECK-FIXES: {{^[[:space:]]*}}if (absl::StartsWith(s, "....")) { /* do something */ }{{$}}
// CHECK-FIXES: if (absl::StartsWith(s, "....")) { /* do something */ }

0 != s.rfind("a", 0);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StartsWith
// CHECK-FIXES: {{^[[:space:]]*}}!absl::StartsWith(s, "a");{{$}}
// CHECK-FIXES: !absl::StartsWith(s, "a");

s2.rfind("a", 0) == 0;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StartsWith
// CHECK-FIXES: {{^[[:space:]]*}}absl::StartsWith(s2, "a");{{$}}
// CHECK-FIXES: absl::StartsWith(s2, "a");

sv.find("a") == 0;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StartsWith
// CHECK-FIXES: {{^[[:space:]]*}}absl::StartsWith(sv, "a");{{$}}
// CHECK-FIXES: absl::StartsWith(sv, "a");

sv.rfind("a", 0) != 0;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StartsWith
// CHECK-FIXES: {{^[[:space:]]*}}!absl::StartsWith(sv, "a");{{$}}
// CHECK-FIXES: !absl::StartsWith(sv, "a");

// expressions that don't trigger the check are here.
A_MACRO(s.find("a"), 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ void f__o__o(void);
void f_________oo(void);
void __foo(void);
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '__foo', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}void foo(void);{{$}}
// CHECK-FIXES: void foo(void);
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@

#define _MACRO(m) int m = 0
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses identifier '_MACRO', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}#define MACRO(m) int m = 0{{$}}
// CHECK-FIXES: #define MACRO(m) int m = 0

namespace _Ns {
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration uses identifier '_Ns', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}namespace Ns {{{$}}
// CHECK-FIXES: namespace Ns {

class _Object {
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_Object', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}class Object {{{$}}
// CHECK-FIXES: class Object {
int _Member;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_Member', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}} int Member;{{$}}
// CHECK-FIXES: int Member;
};

float _Global;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_Global', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}float Global;{{$}}
// CHECK-FIXES: float Global;

void _Function() {}
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_Function', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}void Function() {}{{$}}
// CHECK-FIXES: void Function() {}

using _Alias = int;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_Alias', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}using Alias = int;{{$}}
// CHECK-FIXES: using Alias = int;

template <typename _TemplateParam>
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: declaration uses identifier '_TemplateParam', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}template <typename TemplateParam>{{$}}
// CHECK-FIXES: template <typename TemplateParam>
struct S {};

} // namespace _Ns
Expand All @@ -45,34 +45,34 @@ struct S {};

#define __macro(m) int m = 0
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses identifier '__macro', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}#define _macro(m) int m = 0{{$}}
// CHECK-FIXES: #define _macro(m) int m = 0

namespace __ns {
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration uses identifier '__ns', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}namespace ns {{{$}}
// CHECK-FIXES: namespace ns {
class __object {
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '__object', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}class _object {{{$}}
// CHECK-FIXES: class _object {
int __member;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '__member', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}} int _member;{{$}}
// CHECK-FIXES: int _member;
};

float __global;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '__global', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}float _global;{{$}}
// CHECK-FIXES: float _global;

void __function() {}
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '__function', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}void _function() {}{{$}}
// CHECK-FIXES: void _function() {}

using __alias = int;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '__alias', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}using _alias = int;{{$}}
// CHECK-FIXES: using _alias = int;

template <typename __templateParam>
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: declaration uses identifier '__templateParam', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}template <typename _templateParam>{{$}}
// CHECK-FIXES: template <typename _templateParam>
struct S {};

} // namespace __ns
Expand All @@ -81,34 +81,34 @@ struct S {};

#define macro___m(m) int m = 0
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses identifier 'macro___m', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}#define macro_m(m) int m = 0{{$}}
// CHECK-FIXES: #define macro_m(m) int m = 0

namespace ns___n {
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration uses identifier 'ns___n', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}namespace ns_n {{{$}}
// CHECK-FIXES: namespace ns_n {
class object___o {
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier 'object___o', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}class object_o {{{$}}
// CHECK-FIXES: class object_o {
int member___m;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier 'member___m', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}} int member_m;{{$}}
// CHECK-FIXES: int member_m;
};

float global___g;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier 'global___g', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}float global_g;{{$}}
// CHECK-FIXES: float global_g;

void function___f() {}
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier 'function___f', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}void function_f() {}{{$}}
// CHECK-FIXES: void function_f() {}

using alias___a = int;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier 'alias___a', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}using alias_a = int;{{$}}
// CHECK-FIXES: using alias_a = int;

template <typename templateParam___t>
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: declaration uses identifier 'templateParam___t', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}template <typename templateParam_t>{{$}}
// CHECK-FIXES: template <typename templateParam_t>
struct S {};

} // namespace ns___n
Expand All @@ -121,55 +121,55 @@ struct S {};

namespace _ns {
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration uses identifier '_ns', which is reserved in the global namespace [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}namespace ns {{{$}}
// CHECK-FIXES: namespace ns {
int _i;
// no warning
} // namespace _ns
class _object {
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_object', which is reserved in the global namespace [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}class object {{{$}}
// CHECK-FIXES: class object {
int _member;
// no warning
};
float _global;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_global', which is reserved in the global namespace [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}float global;{{$}}
// CHECK-FIXES: float global;
void _function() {}
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_function', which is reserved in the global namespace [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}void function() {}{{$}}
// CHECK-FIXES: void function() {}
using _alias = int;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_alias', which is reserved in the global namespace [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}using alias = int;{{$}}
// CHECK-FIXES: using alias = int;
template <typename _templateParam> // no warning, template params are not in the global namespace
struct S {};

void _float() {}
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_float', which is reserved in the global namespace; cannot be fixed because 'float' would conflict with a keyword [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}void _float() {}{{$}}
// CHECK-FIXES: void _float() {}

#define SOME_MACRO
int SOME__MACRO;
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration uses identifier 'SOME__MACRO', which is a reserved identifier; cannot be fixed because 'SOME_MACRO' would conflict with a macro definition [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}int SOME__MACRO;{{$}}
// CHECK-FIXES: int SOME__MACRO;

void _TWO__PROBLEMS() {}
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_TWO__PROBLEMS', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}void TWO_PROBLEMS() {}{{$}}
// CHECK-FIXES: void TWO_PROBLEMS() {}
void _two__problems() {}
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_two__problems', which is a reserved identifier [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}void two_problems() {}{{$}}
// CHECK-FIXES: void two_problems() {}

int __;
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration uses identifier '__', which is a reserved identifier; cannot be fixed automatically [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}int __;{{$}}
// CHECK-FIXES: int __;

int _________;
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration uses identifier '_________', which is a reserved identifier; cannot be fixed automatically [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}int _________;{{$}}
// CHECK-FIXES: int _________;

int _;
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration uses identifier '_', which is reserved in the global namespace; cannot be fixed automatically [bugprone-reserved-identifier]
// CHECK-FIXES: {{^}}int _;{{$}}
// CHECK-FIXES: int _;

// This should not trigger a warning
// https://github.com/llvm/llvm-project/issues/52895
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ void f(int a, double b, const char *cpc, const void *cpv, X *pX) {
Typedef1 t1;
(Typedef2)t1;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: C-style casts are discouraged; use static_cast (if needed, the cast may be redundant) [google-readability-casting]
// CHECK-FIXES: {{^}} static_cast<Typedef2>(t1);
// CHECK-FIXES: static_cast<Typedef2>(t1);
(const char*)t1;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: {{.*}}; use static_cast (if needed
// CHECK-FIXES: {{^}} static_cast<const char*>(t1);
// CHECK-FIXES: static_cast<const char*>(t1);
(Typedef1)cpc;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: {{.*}}; use static_cast (if needed
// CHECK-FIXES: {{^}} static_cast<Typedef1>(cpc);
// CHECK-FIXES: static_cast<Typedef1>(cpc);
(Typedef1)t1;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant cast to the same type
// CHECK-FIXES: {{^}} t1;
// CHECK-FIXES: t1;

char *pc = (char*)cpc;
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: C-style casts are discouraged; use const_cast [google-readability-casting]
// CHECK-FIXES: char *pc = const_cast<char*>(cpc);
typedef char Char;
Char *pChar = (Char*)pc;
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: {{.*}}; use static_cast (if needed
// CHECK-FIXES: {{^}} Char *pChar = static_cast<Char*>(pc);
// CHECK-FIXES: Char *pChar = static_cast<Char*>(pc);

(Char)*cpc;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: {{.*}}; use static_cast (if needed
// CHECK-FIXES: {{^}} static_cast<Char>(*cpc);
// CHECK-FIXES: static_cast<Char>(*cpc);

(char)*pChar;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: {{.*}}; use static_cast (if needed
// CHECK-FIXES: {{^}} static_cast<char>(*pChar);
// CHECK-FIXES: static_cast<char>(*pChar);

(const char*)cpv;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: {{.*}}; use static_cast [
Expand Down Expand Up @@ -124,24 +124,24 @@ void f(int a, double b, const char *cpc, const void *cpv, X *pX) {

e = (Enum)Enum1;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant cast to the same type
// CHECK-FIXES: {{^}} e = Enum1;
// CHECK-FIXES: e = Enum1;

e = (Enum)e;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant cast to the same type
// CHECK-FIXES: {{^}} e = e;
// CHECK-FIXES: e = e;

e = (Enum) e;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant cast to the same type
// CHECK-FIXES: {{^}} e = e;
// CHECK-FIXES: e = e;

e = (Enum) (e);
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant cast to the same type
// CHECK-FIXES: {{^}} e = (e);
// CHECK-FIXES: e = (e);

static const int kZero = 0;
(int)kZero;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant cast to the same type
// CHECK-FIXES: {{^}} kZero;
// CHECK-FIXES: kZero;

int b2 = static_cast<double>(b);
int b3 = b;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const int *getCIntPtr();
void foo() {
auto NakedPtr = getIntPtr();
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto NakedPtr' can be declared as 'auto *NakedPtr'
// CHECK-FIXES: {{^}} auto *NakedPtr = getIntPtr();
// CHECK-FIXES: auto *NakedPtr = getIntPtr();
auto NakedConstPtr = getCIntPtr();
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto NakedConstPtr' can be declared as 'const auto *NakedConstPtr'
// CHECK-FIXES: {{^}} const auto *NakedConstPtr = getCIntPtr();
// CHECK-FIXES: const auto *NakedConstPtr = getCIntPtr();
auto *Ptr = getIntPtr();
auto *ConstPtr = getCIntPtr();
auto &NakedRef = *getIntPtr();
Expand Down
Loading
Loading