Skip to content

Commit

Permalink
Use if constexpr to guarantee compile-time simplification (gbdev#1590)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 authored Dec 31, 2024
1 parent 06daf2a commit 72b2a4d
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
#endif

char const *get_package_version_string() {
// The following conditional should be simplified by the compiler.
if (strlen(BUILD_VERSION_STRING) == 0) {
// Fallback if version string can't be obtained from Git
if constexpr (QUOTEDSTRLEN(BUILD_VERSION_STRING) > 0) {
return BUILD_VERSION_STRING;
}
// Fallback if version string can't be obtained from Git
#ifndef PACKAGE_VERSION_RC
return "v" EXPAND_AND_STR(PACKAGE_VERSION_MAJOR) "." EXPAND_AND_STR(PACKAGE_VERSION_MINOR
) "." EXPAND_AND_STR(PACKAGE_VERSION_PATCH);
return "v" EXPAND_AND_STR(PACKAGE_VERSION_MAJOR) "." EXPAND_AND_STR(PACKAGE_VERSION_MINOR
) "." EXPAND_AND_STR(PACKAGE_VERSION_PATCH);
#else
return "v" EXPAND_AND_STR(PACKAGE_VERSION_MAJOR) "." EXPAND_AND_STR(PACKAGE_VERSION_MINOR
) "." EXPAND_AND_STR(PACKAGE_VERSION_PATCH) "-rc" EXPAND_AND_STR(PACKAGE_VERSION_RC);
return "v" EXPAND_AND_STR(PACKAGE_VERSION_MAJOR) "." EXPAND_AND_STR(PACKAGE_VERSION_MINOR
) "." EXPAND_AND_STR(PACKAGE_VERSION_PATCH) "-rc" EXPAND_AND_STR(PACKAGE_VERSION_RC);
#endif
} else {
return BUILD_VERSION_STRING;
}
}

0 comments on commit 72b2a4d

Please sign in to comment.