diff --git a/conanfile.py b/conanfile.py index d2f45af6..365f5981 100644 --- a/conanfile.py +++ b/conanfile.py @@ -84,7 +84,13 @@ class UnitsConan(ConanFile): def package_info(self): self.cpp_info.includedirs = ['include'] if self.settings.compiler == "gcc": - self.cpp_info.cxxflags = ["-fconcepts", "-Wno-literal-suffix", "-Wno-non-template-friend"] + self.cpp_info.cxxflags = [ + "-fconcepts", + "-Wno-literal-suffix", + "-Wno-non-template-friend", + "-Wno-stringop-overflow", + "-Wno-pedantic" + ] def package_id(self): self.info.settings.clear() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 09c9c3bb..5e991385 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -65,6 +65,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) INTERFACE -Wno-literal-suffix -Wno-non-template-friend + -Wno-stringop-overflow # TODO gcc:92101 -Wno-pedantic ) diff --git a/src/include/units/bits/fixed_string.h b/src/include/units/bits/fixed_string.h index 3e2b3379..54b1fce0 100644 --- a/src/include/units/bits/fixed_string.h +++ b/src/include/units/bits/fixed_string.h @@ -27,16 +27,18 @@ namespace units { template struct basic_fixed_string { - CharT data_[N+1] = {}; + CharT data_[N + 1] = {}; - constexpr basic_fixed_string(const CharT (&txt)[N+1]) noexcept + constexpr basic_fixed_string(const CharT (&txt)[N + 1]) noexcept { - for(std::size_t i = 0; i <= N; ++i) + for(std::size_t i = 0; i < N; ++i) data_[i] = txt[i]; } [[nodiscard]] constexpr std::size_t size() const noexcept { return N; } [[nodiscard]] constexpr const CharT* c_str() const noexcept { return data_; } + [[nodiscard]] constexpr const CharT& operator[](std::size_t index) const noexcept { return data_[index]; } + [[nodiscard]] constexpr CharT operator[](std::size_t index) noexcept { return data_[index]; } // auto operator==(const basic_fixed_string &) = default; @@ -79,15 +81,14 @@ namespace units { template [[nodiscard]] constexpr friend basic_fixed_string operator+(const basic_fixed_string& lhs, const basic_fixed_string& rhs) noexcept { - CharT txt[lhs.size() + rhs.size() + 1] = {}; + CharT txt[N + N2 + 1] = {}; - size_t i = 0; - for(; i != lhs.size(); ++i) - txt[i] = lhs.c_str()[i]; - for(size_t j = 0; j != rhs.size(); ++j) - txt[i + j] = rhs.c_str()[j]; + for(size_t i = 0; i != N; ++i) + txt[i] = lhs[i]; + for(size_t i = 0; i != N2; ++i) + txt[N + i] = rhs[i]; - return basic_fixed_string(txt); + return units::basic_fixed_string(txt); } };