Skip to content

Commit

Permalink
fix(string_stream): add missing initializations of const format speci…
Browse files Browse the repository at this point in the history
…fiers (#849)

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
  • Loading branch information
KnoerleMaTLS committed Mar 9, 2024
1 parent a98d387 commit 7c24f66
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/etl/basic_format_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ namespace etl
static ETL_CONSTANT private_basic_format_spec::base_spec hex(16U);

//*********************************
static ETL_CONSTANT private_basic_format_spec::left_spec left;
static ETL_CONSTANT private_basic_format_spec::left_spec left = private_basic_format_spec::left_spec();

//*********************************
static ETL_CONSTANT private_basic_format_spec::right_spec right;
static ETL_CONSTANT private_basic_format_spec::right_spec right = private_basic_format_spec::right_spec();

//*********************************
static ETL_CONSTANT private_basic_format_spec::boolalpha_spec boolalpha(true);
Expand Down

0 comments on commit 7c24f66

Please sign in to comment.