Use static_assert in sqlite_result_code.cc
Implementation changes in (D)CHECK_EQ trigger dead-code warnings when a statement is compile-time correct. We should just static_assert for stronger guarantees. Bug: None Change-Id: I259ffdb6d936a53757450cebae9e5a6a9c0a2fc3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6342470 Commit-Queue: Greg Thompson <grt@chromium.org> Reviewed-by: Greg Thompson <grt@chromium.org> Auto-Submit: Peter Boström <pbos@chromium.org> Cr-Commit-Position: refs/heads/main@{#1430731}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
1563c4e1a3
commit
7bf135558a
@ -308,6 +308,22 @@ file lock requests"
|
||||
static_cast<int>(SqliteLoggedResultCode::kIoCorruptFileSystem)},
|
||||
};
|
||||
|
||||
// Number of #defines in https://www.sqlite.org/c3ref/c_abort.html
|
||||
//
|
||||
// This number is also stated at
|
||||
// https://www.sqlite.org/rescode.html#primary_result_code_list
|
||||
static constexpr int kPrimaryResultCodes = 31;
|
||||
|
||||
// Number of #defines in https://www.sqlite.org/c3ref/c_abort_rollback.html
|
||||
//
|
||||
// This number is also stated at
|
||||
// https://www.sqlite.org/rescode.html#extended_result_code_list
|
||||
static constexpr int kExtendedResultCodes = 74;
|
||||
|
||||
static_assert(std::size(kResultCodeMapping) ==
|
||||
size_t{kPrimaryResultCodes + kExtendedResultCodes},
|
||||
"Mapping table has incorrect number of entries");
|
||||
|
||||
// Looks up a `sqlite_result_code` in the mapping tables.
|
||||
//
|
||||
// Returns an entry in kResultCodeMapping or kUnknownResultCodeMappingEntry.
|
||||
@ -447,22 +463,6 @@ void CheckSqliteLoggedResultCodeForTesting() {
|
||||
<< "Unmapped SQLite result code: " << result_code
|
||||
<< " SQLite message: " << error_message;
|
||||
}
|
||||
|
||||
// Number of #defines in https://www.sqlite.org/c3ref/c_abort.html
|
||||
//
|
||||
// This number is also stated at
|
||||
// https://www.sqlite.org/rescode.html#primary_result_code_list
|
||||
static constexpr int kPrimaryResultCodes = 31;
|
||||
|
||||
// Number of #defines in https://www.sqlite.org/c3ref/c_abort_rollback.html
|
||||
//
|
||||
// This number is also stated at
|
||||
// https://www.sqlite.org/rescode.html#extended_result_code_list
|
||||
static constexpr int kExtendedResultCodes = 74;
|
||||
|
||||
DCHECK_EQ(std::size(kResultCodeMapping),
|
||||
size_t{kPrimaryResultCodes + kExtendedResultCodes})
|
||||
<< "Mapping table has incorrect number of entries";
|
||||
}
|
||||
|
||||
} // namespace sql
|
||||
|
Reference in New Issue
Block a user