Skip to content
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

fix(string_stream): add missing initializations of const format specifiers #849

Conversation

KnoerleMaTLS
Copy link
Contributor

This pull request introduces a possible fix for the issue #848 by adding the missing initializers.

…fiers

The const variables "left" and "right" are const default initialized.
The C++ standard states the following:
"A class type T is const-default-constructible if default-initialization
of T would invoke a user-provided constructor of T."
Since the "left_soec" and "right_spec" structs are PODs they are not
initialized per default. Due to the "constness" the variable can not be
modified later one, therefore the POD is in a state in which it is not
useful at all.
Since the mentioned structs are empty there would be no problem
in this case. This is an issue in the C++ standard (CWG Issue 253).
Some compilers already handle this issue with their own solution
despite the fact, that the standard did not provide a solution yet.
For some exotic compilers  (e.g. Tasking for TriCore) the include of
the "string_stream" header caused compilation errors:
"const variable "etl::left" requires an initializer -- class "etl::private_basic_format_spec::left_spec" has no user-provided default constructor"

References:
https://en.cppreference.com/w/cpp/language/default_initialization
https://cplusplus.github.io/CWG/issues/253.html
https://stackoverflow.com/questions/7411515/why-does-c-require-a-user-provided-default-constructor-to-default-construct-a
https://stackoverflow.com/questions/24943665/why-is-a-constructor-necessary-in-a-const-member-struct
Copy link

Review changes with SemanticDiff.

@jwellbelove
Copy link
Contributor

Were you getting warning from the compiler?

@KnoerleMaTLS
Copy link
Contributor Author

Warning about what/where?
Regarding the propsed fix?

@jwellbelove
Copy link
Contributor

Did you get errors or warnings about 'missing initializers'?
left_spec & right_spec have default constructors, so they shouldn't need explicit initialisation.

@KnoerleMaTLS
Copy link
Contributor Author

Yeah, i got compiler errors about missing initializers for left and right.
Please check #848 for further details.

Yes, the structs left_spec and right_spec have compiler generated default constructors, but regarding the C++ standard this is not enough to initialize a const object ("default-initialization of a const object could not call an implicitly declared default constructor").
I also tried to explain this in more detail in the mentioned issue.

@jwellbelove jwellbelove changed the base branch from master to development March 8, 2024 09:41
@jwellbelove jwellbelove changed the base branch from development to pull-request/#849-fix-string_stream-add-missing-initializations-of-const-format-specifiers March 9, 2024 14:55
@jwellbelove jwellbelove merged commit 7c24f66 into ETLCPP:pull-request/#849-fix-string_stream-add-missing-initializations-of-const-format-specifiers Mar 9, 2024
62 of 63 checks passed
jwellbelove pushed a commit that referenced this pull request Mar 10, 2024
…izations-of-const-format-specifiers' into development

# Conflicts:
#	support/Release notes.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants