Files
TheRock/compiler/amd-llvm/clang-tools-extra/test/clang-tidy/checkers/abseil/str-cat-append.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

130 lines
3.7 KiB
C++

// RUN: %check_clang_tidy %s abseil-str-cat-append %t
typedef unsigned __INT16_TYPE__ char16;
typedef unsigned __INT32_TYPE__ char32;
typedef __SIZE_TYPE__ size;
namespace std {
template <typename T>
class allocator {};
template <typename T>
class char_traits {};
template <typename C, typename T, typename A>
struct basic_string {
typedef basic_string<C, T, A> _Type;
basic_string();
basic_string(const C* p, const A& a = A());
const C* c_str() const;
const C* data() const;
_Type& append(const C* s);
_Type& append(const C* s, size n);
_Type& assign(const C* s);
_Type& assign(const C* s, size n);
int compare(const _Type&) const;
int compare(const C* s) const;
int compare(size pos, size len, const _Type&) const;
int compare(size pos, size len, const C* s) const;
size find(const _Type& str, size pos = 0) const;
size find(const C* s, size pos = 0) const;
size find(const C* s, size pos, size n) const;
_Type& insert(size pos, const _Type& str);
_Type& insert(size pos, const C* s);
_Type& insert(size pos, const C* s, size n);
_Type& operator+=(const _Type& str);
_Type& operator+=(const C* s);
_Type& operator=(const _Type& str);
_Type& operator=(const C* s);
};
typedef basic_string<char, std::char_traits<char>, std::allocator<char>> string;
typedef basic_string<wchar_t, std::char_traits<wchar_t>,
std::allocator<wchar_t>>
wstring;
typedef basic_string<char16, std::char_traits<char16>, std::allocator<char16>>
u16string;
typedef basic_string<char32, std::char_traits<char32>, std::allocator<char32>>
u32string;
} // namespace std
std::string operator+(const std::string&, const std::string&);
std::string operator+(const std::string&, const char*);
std::string operator+(const char*, const std::string&);
bool operator==(const std::string&, const std::string&);
bool operator==(const std::string&, const char*);
bool operator==(const char*, const std::string&);
namespace llvm {
struct StringRef {
StringRef(const char* p);
StringRef(const std::string&);
};
} // namespace llvm
namespace absl {
struct AlphaNum {
AlphaNum(int i);
AlphaNum(double f);
AlphaNum(const char* c_str);
AlphaNum(const std::string& str);
private:
AlphaNum(const AlphaNum&);
AlphaNum& operator=(const AlphaNum&);
};
std::string StrCat(const AlphaNum& A);
std::string StrCat(const AlphaNum& A, const AlphaNum& B);
template <typename A>
void Foo(A& a) {
a = StrCat(a);
}
void Bar() {
std::string A, B;
Foo<std::string>(A);
std::string C = StrCat(A);
A = StrCat(A);
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: call to 'absl::StrCat' has no effect
A = StrCat(A, B);
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: call 'absl::StrAppend' instead of 'absl::StrCat' when appending to a string to avoid a performance penalty
// CHECK-FIXES: absl::StrAppend(&A, B);
B = StrCat(A, B);
#define M(X) X = StrCat(X, A)
M(B);
// CHECK-MESSAGES: [[@LINE-1]]:5: warning: call 'absl::StrAppend' instead of 'absl::StrCat' when appending to a string to avoid a performance penalty
// CHECK-FIXES: #define M(X) X = StrCat(X, A)
}
void Regression_SelfAppend() {
std::string A;
A = StrCat(A, A);
}
} // namespace absl
void OutsideAbsl() {
std::string A, B;
A = absl::StrCat(A, B);
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: call 'absl::StrAppend' instead of 'absl::StrCat' when appending to a string to avoid a performance penalty
// CHECK-FIXES: absl::StrAppend(&A, B);
}
void OutsideUsingAbsl() {
std::string A, B;
using absl::StrCat;
A = StrCat(A, B);
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: call 'absl::StrAppend' instead of 'absl::StrCat' when appending to a string to avoid a performance penalty
// CHECK-FIXES: absl::StrAppend(&A, B);
}