Files
TheRock/compiler/amd-llvm/clang-tools-extra/test/clang-tidy/checkers/abseil/faster-strsplit-delimiter.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

125 lines
4.5 KiB
C++

// RUN: %check_clang_tidy -std=c++11-or-later %s abseil-faster-strsplit-delimiter %t
namespace absl {
class string_view {
public:
string_view();
string_view(const char *);
};
namespace strings_internal {
struct Splitter {};
struct MaxSplitsImpl {
MaxSplitsImpl();
~MaxSplitsImpl();
};
} // namespace strings_internal
template <typename Delim>
strings_internal::Splitter StrSplit(absl::string_view, Delim) {
return {};
}
template <typename Delim, typename Pred>
strings_internal::Splitter StrSplit(absl::string_view, Delim, Pred) {
return {};
}
class ByAnyChar {
public:
explicit ByAnyChar(absl::string_view);
~ByAnyChar();
};
template <typename Delim>
strings_internal::MaxSplitsImpl MaxSplits(Delim, int) {
return {};
}
} // namespace absl
void SplitDelimiters() {
absl::StrSplit("ABC", "A");
// CHECK-MESSAGES: [[@LINE-1]]:25: warning: absl::StrSplit() called with a string literal consisting of a single character; consider using the character overload [abseil-faster-strsplit-delimiter]
// CHECK-FIXES: absl::StrSplit("ABC", 'A');
absl::StrSplit("ABC", "\x01");
// CHECK-MESSAGES: [[@LINE-1]]:25: warning: absl::StrSplit() called with a string literal consisting of a single character; consider using the character overload [abseil-faster-strsplit-delimiter]
// CHECK-FIXES: absl::StrSplit("ABC", '\x01');
absl::StrSplit("ABC", "\001");
// CHECK-MESSAGES: [[@LINE-1]]:25: warning: absl::StrSplit() called with a string literal consisting of a single character; consider using the character overload [abseil-faster-strsplit-delimiter]
// CHECK-FIXES: absl::StrSplit("ABC", '\001');
absl::StrSplit("ABC", R"(A)");
// CHECK-MESSAGES: [[@LINE-1]]:25: warning: absl::StrSplit() called with a string literal consisting of a single character; consider using the character overload [abseil-faster-strsplit-delimiter]
// CHECK-FIXES: absl::StrSplit("ABC", 'A');
absl::StrSplit("ABC", R"(')");
// CHECK-MESSAGES: [[@LINE-1]]:25: warning: absl::StrSplit() called with a string literal consisting of a single character; consider using the character overload [abseil-faster-strsplit-delimiter]
// CHECK-FIXES: absl::StrSplit("ABC", '\'');
absl::StrSplit("ABC", R"(
)");
// CHECK-MESSAGES: [[@LINE-2]]:25: warning: absl::StrSplit() called with a string literal consisting of a single character; consider using the character overload [abseil-faster-strsplit-delimiter]
// CHECK-FIXES: absl::StrSplit("ABC", '\n');
absl::StrSplit("ABC", R"delimiter(A)delimiter");
// CHECK-MESSAGES: [[@LINE-1]]:25: warning: absl::StrSplit() called with a string literal consisting of a single character; consider using the character overload [abseil-faster-strsplit-delimiter]
// CHECK-FIXES: absl::StrSplit("ABC", 'A');
absl::StrSplit("ABC", absl::ByAnyChar("\n"));
// CHECK-MESSAGES: [[@LINE-1]]:41: warning: absl::StrSplit()
// CHECK-FIXES: absl::StrSplit("ABC", '\n');
// Works with predicate
absl::StrSplit("ABC", "A", [](absl::string_view) { return true; });
// CHECK-MESSAGES: [[@LINE-1]]:25: warning: absl::StrSplit()
// CHECK-FIXES: absl::StrSplit("ABC", 'A', [](absl::string_view) { return true; });
// Doesn't do anything with other strings lengths.
absl::StrSplit("ABC", "AB");
absl::StrSplit("ABC", absl::ByAnyChar(""));
absl::StrSplit("ABC", absl::ByAnyChar(" \t"));
// Escapes a single quote in the resulting character literal.
absl::StrSplit("ABC", "'");
// CHECK-MESSAGES: [[@LINE-1]]:25: warning: absl::StrSplit()
// CHECK-FIXES: absl::StrSplit("ABC", '\'');
absl::StrSplit("ABC", "\"");
// CHECK-MESSAGES: [[@LINE-1]]:25: warning: absl::StrSplit()
// CHECK-FIXES: absl::StrSplit("ABC", '\"');
absl::StrSplit("ABC", absl::MaxSplits("\t", 1));
// CHECK-MESSAGES: [[@LINE-1]]:41: warning: absl::MaxSplits()
// CHECK-FIXES: absl::StrSplit("ABC", absl::MaxSplits('\t', 1));
auto delim = absl::MaxSplits(absl::ByAnyChar(" "), 1);
// CHECK-MESSAGES: [[@LINE-1]]:48: warning: absl::MaxSplits()
// CHECK-FIXES: auto delim = absl::MaxSplits(' ', 1);
}
#define MACRO(str) absl::StrSplit("ABC", str)
void Macro() {
MACRO("A");
}
template <typename T>
void FunctionTemplate() {
// This one should not warn because ByAnyChar is a dependent type.
absl::StrSplit("TTT", T("A"));
// This one will warn, but we are checking that we get a correct warning only
// once.
absl::StrSplit("TTT", "A");
// CHECK-MESSAGES: [[@LINE-1]]:25: warning: absl::StrSplit()
// CHECK-FIXES: absl::StrSplit("TTT", 'A');
}
void FunctionTemplateCaller() {
FunctionTemplate<absl::ByAnyChar>();
FunctionTemplate<absl::string_view>();
}