From 0fc004c500c11289909a80c76759a4bcee30cdd5 Mon Sep 17 00:00:00 2001 From: Manuel Knoerle Date: Thu, 22 Feb 2024 09:26:39 +0100 Subject: [PATCH] fix(string_stream): add missing initializations of const format specifiers 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 --- include/etl/basic_format_spec.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/etl/basic_format_spec.h b/include/etl/basic_format_spec.h index 90a48c1ac..36c2d74c5 100644 --- a/include/etl/basic_format_spec.h +++ b/include/etl/basic_format_spec.h @@ -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);