[clang] e2138ec - [clang] Use std::size (NFC)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 26 13:58:54 PST 2022
Author: Kazu Hirata
Date: 2022-11-26T13:58:48-08:00
New Revision: e2138ecc72a99cb04fc7d02e57fadcc2b7c85ad9
URL: https://github.com/llvm/llvm-project/commit/e2138ecc72a99cb04fc7d02e57fadcc2b7c85ad9
DIFF: https://github.com/llvm/llvm-project/commit/e2138ecc72a99cb04fc7d02e57fadcc2b7c85ad9.diff
LOG: [clang] Use std::size (NFC)
std::size, introduced in C++17, allows us to directly obtain the
number of elements of an array.
Added:
Modified:
clang/unittests/Tooling/CompilationDatabaseTest.cpp
clang/unittests/libclang/LibclangTest.cpp
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
Removed:
################################################################################
diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
index fb8c10df38e85..ee91af7a631fe 100644
--- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -642,7 +642,7 @@ TEST(ParseFixedCompilationDatabase, ReturnsEmptyCommandLine) {
TEST(ParseFixedCompilationDatabase, HandlesPositionalArgs) {
const char *Argv[] = {"1", "2", "--", "-c", "somefile.cpp", "-DDEF3"};
- int Argc = sizeof(Argv) / sizeof(char*);
+ int Argc = std::size(Argv);
std::string ErrorMsg;
std::unique_ptr<FixedCompilationDatabase> Database =
FixedCompilationDatabase::loadFromCommandLine(Argc, Argv, ErrorMsg);
@@ -677,7 +677,7 @@ TEST(ParseFixedCompilationDatabase, HandlesPositionalArgsSyntaxOnly) {
TEST(ParseFixedCompilationDatabase, HandlesArgv0) {
const char *Argv[] = {"1", "2", "--", "mytool", "somefile.cpp"};
- int Argc = sizeof(Argv) / sizeof(char*);
+ int Argc = std::size(Argv);
std::string ErrorMsg;
std::unique_ptr<FixedCompilationDatabase> Database =
FixedCompilationDatabase::loadFromCommandLine(Argc, Argv, ErrorMsg);
diff --git a/clang/unittests/libclang/LibclangTest.cpp b/clang/unittests/libclang/LibclangTest.cpp
index a2a17646a871b..0845476f31dea 100644
--- a/clang/unittests/libclang/LibclangTest.cpp
+++ b/clang/unittests/libclang/LibclangTest.cpp
@@ -517,7 +517,7 @@ TEST_F(LibclangReparseTest, ReparseWithModule) {
std::string ModulesCache = std::string("-fmodules-cache-path=") + TestDir;
const char *Args[] = { "-fmodules", ModulesCache.c_str(),
"-I", TestDir.c_str() };
- int NumArgs = sizeof(Args) / sizeof(Args[0]);
+ int NumArgs = std::size(Args);
ClangTU = clang_parseTranslationUnit(Index, MName.c_str(), Args, NumArgs,
nullptr, 0, TUFlags);
EXPECT_EQ(1U, clang_getNumDiagnostics(ClangTU));
@@ -557,7 +557,7 @@ TEST_F(LibclangReparseTest, clang_parseTranslationUnit2FullArgv) {
EXPECT_EQ(CXError_Success,
clang_parseTranslationUnit2FullArgv(Index, Filename.c_str(), Argv,
- sizeof(Argv) / sizeof(Argv[0]),
+ std::size(Argv),
nullptr, 0, TUFlags, &ClangTU));
EXPECT_EQ(0U, clang_getNumDiagnostics(ClangTU));
DisplayDiagnostics();
@@ -706,7 +706,7 @@ TEST_F(LibclangSerializationTest, TokenKindsAreCorrectAfterLoading) {
const char *Argv[] = {"-xc++-header", "-std=c++11"};
ClangTU = clang_parseTranslationUnit(Index, HeaderName.c_str(), Argv,
- sizeof(Argv) / sizeof(Argv[0]), nullptr,
+ std::size(Argv), nullptr,
0, TUFlags);
auto CheckTokenKinds = [=]() {
diff --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index cddbd7b17c5f6..da5d1fdc2eae3 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -598,7 +598,7 @@ static unsigned short EncodeVersions(unsigned int MinVersion,
}
unsigned VersionIDs[] = {100, 110, 120, 200, 300};
- for (unsigned I = 0; I < sizeof(VersionIDs) / sizeof(VersionIDs[0]); I++) {
+ for (unsigned I = 0; I < std::size(VersionIDs); I++) {
if (VersionIDs[I] >= MinVersion && VersionIDs[I] < MaxVersion) {
Encoded |= 1 << I;
}
More information about the cfe-commits
mailing list