mirror of
https://github.com/Garux/netradiant-custom.git
synced 2026-09-28 00:00:03 +02:00
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:
@@ -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 ){
|
||||
|
||||
Reference in New Issue
Block a user