Skip to content

thcrap_update: Use enum class, using rather than typedef, fix throw#311

Open
mikomikotaishi wants to merge 2 commits into
thpatch:masterfrom
mikomikotaishi:master
Open

thcrap_update: Use enum class, using rather than typedef, fix throw#311
mikomikotaishi wants to merge 2 commits into
thpatch:masterfrom
mikomikotaishi:master

Conversation

@mikomikotaishi

@mikomikotaishi mikomikotaishi commented Jun 18, 2026

Copy link
Copy Markdown

This PR aims to address the following:

  • Some C++ (non-C) code uses unscoped enums (enum) rather than enum class, which is more consistently used in thcrap_update; we could switch to these for type safety.
  • There is not really much reason to use typedefs over using aliases in C++, and using statements are much cleaner.
  • At one point, a throw new invalid_argument() was used, which is not only an unnecessary heap allocation but even a source of memory leaks.
  • Catching exceptions by const reference is safer as it avoids unnecessary copies and avoids object slicing risks entirely.
  • Where possible, static_cast<T>(x) is safer than using a C-style cast ((T)x).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant