Conversation
Initialize all fields in the macro. Otherwise, g++ -Wall -Wextra complains that some fields are not initialized [-Werror=missing-field-initializers]: error: missing initializer for member ‘PySlot::sl_flags’ error: missing initializer for member ‘PySlot::<anonymous>’ error: missing initializer for member ‘PySlot::<anonymous>’
Member
Author
|
Note: I found this issue while working on adding support for the limited C API to pythoncapi-compat which builds its C/C++ extension with |
Member
Author
|
I created this PR to just fix I also prepared draft PR #158867 which enables |
vstinner
commented
Oct 5, 2026
| {.sl_id=(NAME), .sl_flags=PySlot_STATIC, .sl_ptr=(VALUE)} | ||
|
|
||
| #define PySlot_END {0} | ||
| #define PySlot_END {0, 0, {0}, {0}} |
Member
Author
There was a problem hiding this comment.
I'm not 100% sure that this syntax works on all C/C++ compilers. In C, it's common to use {0}. A more ugly alternative is to have a separated implementation for C++:
#ifdef __cplusplus
# define PySlot_END {0, 0, {0}, {0}}
#else
# define PySlot_END {0}
#endif
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.
Initialize all fields in the macro. Otherwise, g++ -Wall -Wextra complains that some fields are not initialized
[-Werror=missing-field-initializers]:
error: missing initializer for member ‘PySlot::sl_flags’
error: missing initializer for member ‘PySlot::’
error: missing initializer for member ‘PySlot::’