Skip to content

Commit 0e0f4ba

Browse files
authored
Comply with clang-tidy's modernize use-auto rule. (#264)
1 parent 88f0311 commit 0e0f4ba

File tree

8 files changed

+36
-30
lines changed

8 files changed

+36
-30
lines changed

.clang-tidy

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ Checks: '
4242
-google-readability-avoid-underscore-in-googletest-name,
4343
-modernize-avoid-c-arrays,
4444
-modernize-use-nodiscard,
45-
-modernize-use-auto,
4645
-modernize-use-default-member-init,
4746
-modernize-use-trailing-return-type,
4847
-modernize-return-braced-init-list,
@@ -71,6 +70,13 @@ AnalyzeTemporaryDtors: true
7170

7271
#### Disabled checks and why: #####
7372
#
73+
# -readability-convert-member-functions-to-static,
74+
# This check started going off in the upgrade from clang-tidy-8 to clang-tidy-12. It is not always correct because
75+
# we hide the reference implementation in another repository.
76+
# -modernize-use-trailing-return-type,
77+
# At the time of writing (8/22), all of the core BusTub code is in compliance with this. This check only fails
78+
# because some GTest file that is generated at build time. There should be a workaround...?
79+
# (The file's name is gmock_main.cc).
7480
# -bugprone-too-small-loop-variable,
7581
# Complains about uint8_t or uint16_t when the limit on the loop is a container's .size() (size_t).
7682
# We usually do this when we know the maximum size of the container though, so propose leaving disabled.

src/storage/index/b_plus_tree.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ auto BPLUSTREE_TYPE::FindLeafPage(const KeyType &key, bool leftMost) -> Page * {
228228
*/
229229
INDEX_TEMPLATE_ARGUMENTS
230230
void BPLUSTREE_TYPE::UpdateRootPageId(int insert_record) {
231-
HeaderPage *header_page = static_cast<HeaderPage *>(buffer_pool_manager_->FetchPage(HEADER_PAGE_ID));
231+
auto *header_page = static_cast<HeaderPage *>(buffer_pool_manager_->FetchPage(HEADER_PAGE_ID));
232232
if (insert_record != 0) {
233233
// create a new record<index_name + root_page_id> in header_page
234234
header_page->InsertRecord(index_name_, root_page_id_);
@@ -314,7 +314,7 @@ void BPLUSTREE_TYPE::ToGraph(BPlusTreePage *page, BufferPoolManager *bpm, std::o
314314
std::string leaf_prefix("LEAF_");
315315
std::string internal_prefix("INT_");
316316
if (page->IsLeafPage()) {
317-
LeafPage *leaf = reinterpret_cast<LeafPage *>(page);
317+
auto *leaf = reinterpret_cast<LeafPage *>(page);
318318
// Print node name
319319
out << leaf_prefix << leaf->GetPageId();
320320
// Print node properties
@@ -345,7 +345,7 @@ void BPLUSTREE_TYPE::ToGraph(BPlusTreePage *page, BufferPoolManager *bpm, std::o
345345
<< leaf->GetPageId() << ";\n";
346346
}
347347
} else {
348-
InternalPage *inner = reinterpret_cast<InternalPage *>(page);
348+
auto *inner = reinterpret_cast<InternalPage *>(page);
349349
// Print node name
350350
out << internal_prefix << inner->GetPageId();
351351
// Print node properties
@@ -403,7 +403,7 @@ void BPLUSTREE_TYPE::ToGraph(BPlusTreePage *page, BufferPoolManager *bpm, std::o
403403
INDEX_TEMPLATE_ARGUMENTS
404404
void BPLUSTREE_TYPE::ToString(BPlusTreePage *page, BufferPoolManager *bpm) const {
405405
if (page->IsLeafPage()) {
406-
LeafPage *leaf = reinterpret_cast<LeafPage *>(page);
406+
auto *leaf = reinterpret_cast<LeafPage *>(page);
407407
std::cout << "Leaf Page: " << leaf->GetPageId() << " parent: " << leaf->GetParentPageId()
408408
<< " next: " << leaf->GetNextPageId() << std::endl;
409409
for (int i = 0; i < leaf->GetSize(); i++) {
@@ -412,7 +412,7 @@ void BPLUSTREE_TYPE::ToString(BPlusTreePage *page, BufferPoolManager *bpm) const
412412
std::cout << std::endl;
413413
std::cout << std::endl;
414414
} else {
415-
InternalPage *internal = reinterpret_cast<InternalPage *>(page);
415+
auto *internal = reinterpret_cast<InternalPage *>(page);
416416
std::cout << "Internal Page: " << internal->GetPageId() << " parent: " << internal->GetParentPageId() << std::endl;
417417
for (int i = 0; i < internal->GetSize(); i++) {
418418
std::cout << internal->KeyAt(i) << ": " << internal->ValueAt(i) << ",";

test/container/hash_table_page_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace bustub {
2424

2525
// NOLINTNEXTLINE
2626
TEST(HashTablePageTest, DISABLED_DirectoryPageSampleTest) {
27-
DiskManager *disk_manager = new DiskManager("test.db");
27+
auto *disk_manager = new DiskManager("test.db");
2828
auto *bpm = new BufferPoolManagerInstance(5, disk_manager);
2929

3030
// get a directory page from the BufferPoolManager
@@ -58,7 +58,7 @@ TEST(HashTablePageTest, DISABLED_DirectoryPageSampleTest) {
5858

5959
// NOLINTNEXTLINE
6060
TEST(HashTablePageTest, DISABLED_BucketPageSampleTest) {
61-
DiskManager *disk_manager = new DiskManager("test.db");
61+
auto *disk_manager = new DiskManager("test.db");
6262
auto *bpm = new BufferPoolManagerInstance(5, disk_manager);
6363

6464
// get a bucket page from the BufferPoolManager

test/recovery/recovery_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class RecoveryTest : public ::testing::Test {
4444

4545
// NOLINTNEXTLINE
4646
TEST_F(RecoveryTest, DISABLED_RedoTest) {
47-
BustubInstance *bustub_instance = new BustubInstance("test.db");
47+
auto *bustub_instance = new BustubInstance("test.db");
4848

4949
ASSERT_FALSE(enable_logging);
5050
LOG_INFO("Skip system recovering...");
@@ -133,7 +133,7 @@ TEST_F(RecoveryTest, DISABLED_RedoTest) {
133133

134134
// NOLINTNEXTLINE
135135
TEST_F(RecoveryTest, DISABLED_UndoTest) {
136-
BustubInstance *bustub_instance = new BustubInstance("test.db");
136+
auto *bustub_instance = new BustubInstance("test.db");
137137

138138
ASSERT_FALSE(enable_logging);
139139
LOG_INFO("Skip system recovering...");
@@ -212,7 +212,7 @@ TEST_F(RecoveryTest, DISABLED_UndoTest) {
212212

213213
// NOLINTNEXTLINE
214214
TEST_F(RecoveryTest, DISABLED_CheckpointTest) {
215-
BustubInstance *bustub_instance = new BustubInstance("test.db");
215+
auto *bustub_instance = new BustubInstance("test.db");
216216

217217
EXPECT_FALSE(enable_logging);
218218
LOG_INFO("Skip system recovering...");

test/storage/b_plus_tree_concurrent_test.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void InsertHelper(BPlusTree<GenericKey<8>, RID, GenericComparator<8>> *tree, con
4343
GenericKey<8> index_key;
4444
RID rid;
4545
// create transaction
46-
Transaction *transaction = new Transaction(0);
46+
auto *transaction = new Transaction(0);
4747
for (auto key : keys) {
4848
int64_t value = key & 0xFFFFFFFF;
4949
rid.Set(static_cast<int32_t>(key >> 32), value);
@@ -59,7 +59,7 @@ void InsertHelperSplit(BPlusTree<GenericKey<8>, RID, GenericComparator<8>> *tree
5959
GenericKey<8> index_key;
6060
RID rid;
6161
// create transaction
62-
Transaction *transaction = new Transaction(0);
62+
auto *transaction = new Transaction(0);
6363
for (auto key : keys) {
6464
if (static_cast<uint64_t>(key) % total_threads == thread_itr) {
6565
int64_t value = key & 0xFFFFFFFF;
@@ -76,7 +76,7 @@ void DeleteHelper(BPlusTree<GenericKey<8>, RID, GenericComparator<8>> *tree, con
7676
__attribute__((unused)) uint64_t thread_itr = 0) {
7777
GenericKey<8> index_key;
7878
// create transaction
79-
Transaction *transaction = new Transaction(0);
79+
auto *transaction = new Transaction(0);
8080
for (auto key : remove_keys) {
8181
index_key.SetFromInteger(key);
8282
tree->Remove(index_key, transaction);
@@ -90,7 +90,7 @@ void DeleteHelperSplit(BPlusTree<GenericKey<8>, RID, GenericComparator<8>> *tree
9090
__attribute__((unused)) uint64_t thread_itr) {
9191
GenericKey<8> index_key;
9292
// create transaction
93-
Transaction *transaction = new Transaction(0);
93+
auto *transaction = new Transaction(0);
9494
for (auto key : remove_keys) {
9595
if (static_cast<uint64_t>(key) % total_threads == thread_itr) {
9696
index_key.SetFromInteger(key);
@@ -105,7 +105,7 @@ TEST(BPlusTreeConcurrentTest, DISABLED_InsertTest1) {
105105
auto key_schema = ParseCreateStatement("a bigint");
106106
GenericComparator<8> comparator(key_schema.get());
107107

108-
DiskManager *disk_manager = new DiskManager("test.db");
108+
auto *disk_manager = new DiskManager("test.db");
109109
BufferPoolManager *bpm = new BufferPoolManagerInstance(50, disk_manager);
110110
// create b+ tree
111111
BPlusTree<GenericKey<8>, RID, GenericComparator<8>> tree("foo_pk", bpm, comparator);
@@ -156,7 +156,7 @@ TEST(BPlusTreeConcurrentTest, DISABLED_InsertTest2) {
156156
// create KeyComparator and index schema
157157
auto key_schema = ParseCreateStatement("a bigint");
158158
GenericComparator<8> comparator(key_schema.get());
159-
DiskManager *disk_manager = new DiskManager("test.db");
159+
auto *disk_manager = new DiskManager("test.db");
160160
BufferPoolManager *bpm = new BufferPoolManagerInstance(50, disk_manager);
161161
// create b+ tree
162162
BPlusTree<GenericKey<8>, RID, GenericComparator<8>> tree("foo_pk", bpm, comparator);
@@ -208,7 +208,7 @@ TEST(BPlusTreeConcurrentTest, DISABLED_DeleteTest1) {
208208
auto key_schema = ParseCreateStatement("a bigint");
209209
GenericComparator<8> comparator(key_schema.get());
210210

211-
DiskManager *disk_manager = new DiskManager("test.db");
211+
auto *disk_manager = new DiskManager("test.db");
212212
BufferPoolManager *bpm = new BufferPoolManagerInstance(50, disk_manager);
213213
// create b+ tree
214214
BPlusTree<GenericKey<8>, RID, GenericComparator<8>> tree("foo_pk", bpm, comparator);
@@ -250,7 +250,7 @@ TEST(BPlusTreeConcurrentTest, DISABLED_DeleteTest2) {
250250
auto key_schema = ParseCreateStatement("a bigint");
251251
GenericComparator<8> comparator(key_schema.get());
252252

253-
DiskManager *disk_manager = new DiskManager("test.db");
253+
auto *disk_manager = new DiskManager("test.db");
254254
BufferPoolManager *bpm = new BufferPoolManagerInstance(50, disk_manager);
255255
// create b+ tree
256256
BPlusTree<GenericKey<8>, RID, GenericComparator<8>> tree("foo_pk", bpm, comparator);
@@ -293,7 +293,7 @@ TEST(BPlusTreeConcurrentTest, DISABLED_MixTest) {
293293
auto key_schema = ParseCreateStatement("a bigint");
294294
GenericComparator<8> comparator(key_schema.get());
295295

296-
DiskManager *disk_manager = new DiskManager("test.db");
296+
auto *disk_manager = new DiskManager("test.db");
297297
BufferPoolManager *bpm = new BufferPoolManagerInstance(50, disk_manager);
298298
// create b+ tree
299299
BPlusTree<GenericKey<8>, RID, GenericComparator<8>> tree("foo_pk", bpm, comparator);

test/storage/b_plus_tree_delete_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ TEST(BPlusTreeTests, DISABLED_DeleteTest1) {
2525
auto key_schema = ParseCreateStatement("a bigint");
2626
GenericComparator<8> comparator(key_schema.get());
2727

28-
DiskManager *disk_manager = new DiskManager("test.db");
28+
auto *disk_manager = new DiskManager("test.db");
2929
BufferPoolManager *bpm = new BufferPoolManagerInstance(50, disk_manager);
3030
// create b+ tree
3131
BPlusTree<GenericKey<8>, RID, GenericComparator<8>> tree("foo_pk", bpm, comparator);
3232
GenericKey<8> index_key;
3333
RID rid;
3434
// create transaction
35-
Transaction *transaction = new Transaction(0);
35+
auto *transaction = new Transaction(0);
3636

3737
// create and fetch header_page
3838
page_id_t page_id;
@@ -103,14 +103,14 @@ TEST(BPlusTreeTests, DISABLED_DeleteTest2) {
103103
auto key_schema = ParseCreateStatement("a bigint");
104104
GenericComparator<8> comparator(key_schema.get());
105105

106-
DiskManager *disk_manager = new DiskManager("test.db");
106+
auto *disk_manager = new DiskManager("test.db");
107107
BufferPoolManager *bpm = new BufferPoolManagerInstance(50, disk_manager);
108108
// create b+ tree
109109
BPlusTree<GenericKey<8>, RID, GenericComparator<8>> tree("foo_pk", bpm, comparator);
110110
GenericKey<8> index_key;
111111
RID rid;
112112
// create transaction
113-
Transaction *transaction = new Transaction(0);
113+
auto *transaction = new Transaction(0);
114114

115115
// create and fetch header_page
116116
page_id_t page_id;

test/storage/b_plus_tree_insert_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ TEST(BPlusTreeTests, DISABLED_InsertTest1) {
2525
auto key_schema = ParseCreateStatement("a bigint");
2626
GenericComparator<8> comparator(key_schema.get());
2727

28-
DiskManager *disk_manager = new DiskManager("test.db");
28+
auto *disk_manager = new DiskManager("test.db");
2929
BufferPoolManager *bpm = new BufferPoolManagerInstance(50, disk_manager);
3030
// create b+ tree
3131
BPlusTree<GenericKey<8>, RID, GenericComparator<8>> tree("foo_pk", bpm, comparator, 2, 3);
3232
GenericKey<8> index_key;
3333
RID rid;
3434
// create transaction
35-
Transaction *transaction = new Transaction(0);
35+
auto *transaction = new Transaction(0);
3636

3737
// create and fetch header_page
3838
page_id_t page_id;
@@ -83,14 +83,14 @@ TEST(BPlusTreeTests, DISABLED_InsertTest2) {
8383
auto key_schema = ParseCreateStatement("a bigint");
8484
GenericComparator<8> comparator(key_schema.get());
8585

86-
DiskManager *disk_manager = new DiskManager("test.db");
86+
auto *disk_manager = new DiskManager("test.db");
8787
BufferPoolManager *bpm = new BufferPoolManagerInstance(50, disk_manager);
8888
// create b+ tree
8989
BPlusTree<GenericKey<8>, RID, GenericComparator<8>> tree("foo_pk", bpm, comparator);
9090
GenericKey<8> index_key;
9191
RID rid;
9292
// create transaction
93-
Transaction *transaction = new Transaction(0);
93+
auto *transaction = new Transaction(0);
9494

9595
// create and fetch header_page
9696
page_id_t page_id;

test/storage/b_plus_tree_print_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ TEST(BptTreeTest, DISABLED_UnitTest) {
5757
auto key_schema = ParseCreateStatement(create_stmt);
5858
GenericComparator<8> comparator(key_schema.get());
5959

60-
DiskManager *disk_manager = new DiskManager("test.db");
60+
auto *disk_manager = new DiskManager("test.db");
6161
BufferPoolManager *bpm = new BufferPoolManagerInstance(100, disk_manager);
6262
// create and fetch header_page
6363
page_id_t page_id;
6464
auto header_page = bpm->NewPage(&page_id);
6565
// create b+ tree
6666
BPlusTree<GenericKey<8>, RID, GenericComparator<8>> tree("foo_pk", bpm, comparator, leaf_max_size, internal_max_size);
6767
// create transaction
68-
Transaction *transaction = new Transaction(0);
68+
auto *transaction = new Transaction(0);
6969
while (!quit) {
7070
std::cout << "> ";
7171
std::cin >> instruction;

0 commit comments

Comments
 (0)