Fix StringFixedSize infinite template recursion

On MSC, `sizeof...(Args) != 1 ||` does not short-circuit properly, so
`std::tuple_element_t<0, std::tuple<Args...>>` is treated as an
out-of-bounds access.

This felt like a good use-case for concepts, but the fix could also have
been done while keeping std::enable_if.
This commit is contained in:
Willi Schinmeyer
2024-12-04 11:30:59 +05:00
committed by Garux
parent 2019293ae5
commit 14e1cc95ad
+6 -4
View File
@@ -24,6 +24,7 @@
#include "stream/textstream.h"
#include "string/string.h"
#include "inout.h"
#include <type_traits>
/// \brief A TextOutputStream which writes to a null terminated fixed length char array.
@@ -37,10 +38,11 @@ public:
StringFixedSize() {
clear();
}
template<typename Arg, typename ... Args, typename = std::enable_if_t<sizeof...(Args) != 0 || //prevent override of copy constructor
!std::is_same_v<StringFixedSize, std::decay_t<Arg>>>>
explicit StringFixedSize( Arg&& arg, Args&& ... args ){
operator()( std::forward<Arg>( arg ), std::forward<Args>( args ) ... );
template<typename ... Args>
// prevent override of copy constructor
requires ( !std::is_same_v<std::tuple<std::decay_t<Args>...>, std::tuple<StringFixedSize>> )
explicit StringFixedSize(Args&& ... args) {
operator()( std::forward<Args>( args ) ... );
}
std::size_t write( const char* buffer, std::size_t length ) override {
if( m_length + length < SIZE ){