-
Notifications
You must be signed in to change notification settings - Fork 36.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use C++20 consteval to verify translation strings #30379
Comments
diff --git a/src/util/translation.h b/src/util/translation.h
index d33fd2d0a0..7d82264a43 100644
--- a/src/util/translation.h
+++ b/src/util/translation.h
@@ -71,7 +71,7 @@ const extern std::function<std::string(const char*)> G_TRANSLATION_FUN;
* Translation function.
* If no translation function is set, simply return the input.
*/
-inline bilingual_str _(const char* psz)
+inline consteval bilingual_str _(const char* psz)
{
return bilingual_str{psz, G_TRANSLATION_FUN ? (G_TRANSLATION_FUN)(psz) : psz};
} does not work:
So I guess this needs a clang-tidy plugin. |
nvm, I'll open a pull request soon. |
Clang-tidy plugin is not actually required because #30383 can catch the errors, IIUC. |
This was referenced Jul 31, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is possible to write
_(str_ptr)
, which is wrong, see #30267 (comment).I am not familiar with the translation build system integration, but it would be good to effectively change the signature of
_
fromauto _(const char*)
toconsteval auto _(const char*)
.My understanding is that this would catch this error at compile time, saving review effort and follow-up fixup changes.
Assumed compiler error message:
The text was updated successfully, but these errors were encountered: