Skip to content

Commit

Permalink
Codechange: replace cpp_lengthof with safe alternatives
Browse files Browse the repository at this point in the history
  • Loading branch information
rubidium42 committed Apr 20, 2024
1 parent a1a01e2 commit c377c47
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/industry_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2380,8 +2380,8 @@ struct CargoesField {
}
};

static_assert(MAX_CARGOES >= cpp_lengthof(IndustrySpec, produced_cargo));
static_assert(MAX_CARGOES >= cpp_lengthof(IndustrySpec, accepts_cargo));
static_assert(MAX_CARGOES >= std::tuple_size_v<decltype(IndustrySpec::produced_cargo)>);
static_assert(MAX_CARGOES >= std::tuple_size_v<decltype(IndustrySpec::accepts_cargo)>);

Dimension CargoesField::legend; ///< Dimension of the legend blob.
Dimension CargoesField::cargo_border; ///< Dimensions of border between cargo lines and industry boxes.
Expand Down
2 changes: 1 addition & 1 deletion src/newgrf_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,6 @@ struct PersistentStorage : PersistentStorageArray<int32_t, 256>, PersistentStora
}
};

static_assert(cpp_lengthof(OldPersistentStorage, storage) <= cpp_lengthof(PersistentStorage, storage));
static_assert(std::tuple_size_v<decltype(OldPersistentStorage::storage)> <= std::tuple_size_v<decltype(PersistentStorage::storage)>);

#endif /* NEWGRF_STORAGE_H */
8 changes: 0 additions & 8 deletions src/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,6 @@ char (&ArraySizeHelper(T (&array)[N]))[N];
*/
#define cpp_sizeof(base, variable) (sizeof(std::declval<base>().variable))

/**
* Gets the length of an array variable within a class.
* @param base The class the variable is in.
* @param variable The array variable to get the size of.
* @return the length of the array
*/
#define cpp_lengthof(base, variable) (cpp_sizeof(base, variable) / cpp_sizeof(base, variable[0]))


/* take care of some name clashes on MacOS */
#if defined(__APPLE__)
Expand Down

0 comments on commit c377c47

Please sign in to comment.