Fix static inline template in defs.hpp#1962
Merged
dsnopek merged 1 commit intogodotengine:masterfrom Mar 31, 2026
Merged
Conversation
Ivorforce
approved these changes
Mar 31, 2026
Member
Ivorforce
left a comment
There was a problem hiding this comment.
All changes look like a strict improvement to me.
dsnopek
approved these changes
Mar 31, 2026
Collaborator
dsnopek
left a comment
There was a problem hiding this comment.
Thanks! These changes make sense to me and I can confirm that they mostly match what's in the engine
Assuming godotengine/godot#118027 doesn't take excessively long to be merged, I think we should off on merging here until that one is merged first
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I was using clang-18 + C++module to build my gdextension lib and encountered a compile error in binding a method normally. A MRE is given as follow:
compile
The error looks like this
After some tests I realized that the fact
nearest_power_of_2_templatedusesstatic inlineAND is a template is key of the issue.I am not sure if this is a real error by C++ standard or just a clang bug for module, but it is true that (global function)
static inlinedoes not make too much sense in modern C++ and is equivalent toinline. In this particular case, I propose to just useconstexprinstead, which is fully compatible and allows compile-time evaluation. This is the first motivation.The second motivation is that the Engine codebase uses no
staticfrom the beginning, justinline. Meanwhile, the Engine has other functions (e.g.get_shift_from_power_of_2) marked withconstexprwhilegodot-cppdoes not. So I propose we useconstexpras a unified solution.With this PR the code in
godot-cppbecomes consistent withgodot, except thatgodothas noconstexprin the two template functionsis_power_of_2nearest_power_of_2_templated. I intend to propose this change togodotas well.