Skip to content

mx_getopt.h: Initializers use same designator multiple times. Is this defined behavior? #131

Closed
donald opened this issue Apr 14, 2022 · 1 comment

Comments

@donald
Copy link
Contributor

donald commented Apr 14, 2022

#define MX_OPTION(...) { MX_OPTION_DEFAULTS, ## __VA_ARGS__ }

To initialize a field multiple times by repeating a C11 designator seems to produce the expected results (last initalization is used). Gcc explicitly mentions that in its manual [1]. Clang produces the same code [2]. Probably all reasonable compilers will do so.

However, currently clang generates a warning ("initializer overrides prior initialization of this subobject [-Winitializer-overrides]") and gcc does so with -Wextra ("initialized field overwritten [-Woverride-init]"). I'm not sure about the standard, but the warnings might hint, that the standard does not define this.

[1]: https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html bottom of page
[2]: https://godbolt.org/z/so7KEv94T

donald added a commit that referenced this issue Apr 20, 2022
Enable -Wextra. Exclude -Wno-override-init for now, because mx_getopt.h
relies on it [1].

[1]: #131
donald added a commit that referenced this issue May 5, 2022
Enable -Wextra. Exclude -Wno-override-init for now, because mx_getopt.h
relies on it [1].

[1]: #131
donald added a commit that referenced this issue May 5, 2022
Enable -Wextra. Exclude -Wno-override-init for now, because mx_getopt.h
relies on it [1].

[1]: #131
donald added a commit that referenced this issue May 5, 2022
Enable -Wextra. Exclude -Wno-override-init for now, because mx_getopt.h
relies on it [1].

[1]: #131
donald added a commit that referenced this issue May 5, 2022
Enable -Wextra. Exclude -Wno-override-init for now, because mx_getopt.h
relies on it [1].

[1]: #131
donald added a commit that referenced this issue May 5, 2022
Enable -Wextra. Exclude -Wno-override-init for now, because mx_getopt.h
relies on it [1].

[1]: #131
donald added a commit that referenced this issue May 9, 2022
Enable -Wextra. Exclude -Wno-override-init for now, because mx_getopt.h
relies on it [1].

[1]: #131
donald added a commit to mariux64/bee that referenced this issue Jul 8, 2022
Enable -Wextra. Exclude -Wno-override-init for now, because bee_getopt.h
relies on it. See [1] for similar issue in mxq.

[1]: mariux64/mxq#131
donald added a commit to mariux64/bee that referenced this issue Jul 8, 2022
Enable -Wextra. Exclude -Wno-override-init for now, because bee_getopt.h
relies on it. See [1] for similar issue in mxq.

[1]: mariux64/mxq#131
donald added a commit to mariux64/bee that referenced this issue Jul 8, 2022
Enable -Wextra. Exclude -Wno-override-init for now, because bee_getopt.h
relies on it. See [1] for similar issue in mxq.

[1]: mariux64/mxq#131
donald added a commit to mariux64/bee that referenced this issue Jul 8, 2022
Enable -Wextra. Exclude -Wno-override-init for now, because bee_getopt.h
relies on it. See [1] for similar issue in mxq.

[1]: mariux64/mxq#131
@donald
Copy link
Contributor Author

donald commented Jan 10, 2024

Merged commit 3f89869 ("Makefile: Enable -Wextra") includes -Wno-override-init.

@donald donald closed this as completed Jan 10, 2024
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant