From e1b1fd72dc7c50a51dbfd3e165aeeaa0e8536fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Blissing?= Date: Thu, 17 Aug 2023 10:03:52 +0200 Subject: [PATCH] Wrap std::numeric_limits::max() in parenthesis The windows.h header file defines the macro max. If the max macro is include it will lead to name collisions with the std::numeric_limits::max() function. One solution is to define NOMINMAX before the inclusion of windows.h. However, that might be a demanding task for a large codebase. Defining the NOMINMAX as global define may also break previous code. Another to solution to the problem is to wrap the numeric_limits function in parenthesis to instruct the compiler to treat it as a function and not a macro. This commit wraps the std::numeric_limits::max() calls in the public interfacing header files, with parenthesis. --- public/client/TracyLock.hpp | 8 ++++---- public/client/TracyProfiler.hpp | 10 +++++----- public/client/TracyScoped.hpp | 4 ++-- public/common/TracyProtocol.hpp | 2 +- public/tracy/TracyLua.hpp | 10 +++++----- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/public/client/TracyLock.hpp b/public/client/TracyLock.hpp index 296a41ba..d12a3c16 100644 --- a/public/client/TracyLock.hpp +++ b/public/client/TracyLock.hpp @@ -21,7 +21,7 @@ public: , m_active( false ) #endif { - assert( m_id != std::numeric_limits::max() ); + assert( m_id != (std::numeric_limits::max)() ); auto item = Profiler::QueueSerial(); MemWrite( &item->hdr.type, QueueType::LockAnnounce ); @@ -154,7 +154,7 @@ public: tracy_force_inline void CustomName( const char* name, size_t size ) { - assert( size < std::numeric_limits::max() ); + assert( size < (std::numeric_limits::max)() ); auto ptr = (char*)tracy_malloc( size ); memcpy( ptr, name, size ); auto item = Profiler::QueueSerial(); @@ -235,7 +235,7 @@ public: , m_active( false ) #endif { - assert( m_id != std::numeric_limits::max() ); + assert( m_id != (std::numeric_limits::max)() ); auto item = Profiler::QueueSerial(); MemWrite( &item->hdr.type, QueueType::LockAnnounce ); @@ -450,7 +450,7 @@ public: tracy_force_inline void CustomName( const char* name, size_t size ) { - assert( size < std::numeric_limits::max() ); + assert( size < (std::numeric_limits::max)() ); auto ptr = (char*)tracy_malloc( size ); memcpy( ptr, name, size ); auto item = Profiler::QueueSerial(); diff --git a/public/client/TracyProfiler.hpp b/public/client/TracyProfiler.hpp index 9b8f8433..1b825ea3 100644 --- a/public/client/TracyProfiler.hpp +++ b/public/client/TracyProfiler.hpp @@ -289,7 +289,7 @@ public: { #ifndef TRACY_NO_FRAME_IMAGE auto& profiler = GetProfiler(); - assert( profiler.m_frameCount.load( std::memory_order_relaxed ) < std::numeric_limits::max() ); + assert( profiler.m_frameCount.load( std::memory_order_relaxed ) < (std::numeric_limits::max)() ); # ifdef TRACY_ON_DEMAND if( !profiler.IsConnected() ) return; # endif @@ -363,7 +363,7 @@ public: static tracy_force_inline void Message( const char* txt, size_t size, int callstack ) { - assert( size < std::numeric_limits::max() ); + assert( size < (std::numeric_limits::max)() ); #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; #endif @@ -400,7 +400,7 @@ public: static tracy_force_inline void MessageColor( const char* txt, size_t size, uint32_t color, int callstack ) { - assert( size < std::numeric_limits::max() ); + assert( size < (std::numeric_limits::max)() ); #ifdef TRACY_ON_DEMAND if( !GetProfiler().IsConnected() ) return; #endif @@ -443,7 +443,7 @@ public: static tracy_force_inline void MessageAppInfo( const char* txt, size_t size ) { - assert( size < std::numeric_limits::max() ); + assert( size < (std::numeric_limits::max)() ); auto ptr = (char*)tracy_malloc( size ); memcpy( ptr, txt, size ); TracyLfqPrepare( QueueType::MessageAppInfo ); @@ -738,7 +738,7 @@ public: static tracy_force_inline uint64_t AllocSourceLocation( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz ) { const auto sz32 = uint32_t( 2 + 4 + 4 + functionSz + 1 + sourceSz + 1 + nameSz ); - assert( sz32 <= std::numeric_limits::max() ); + assert( sz32 <= (std::numeric_limits::max)() ); const auto sz = uint16_t( sz32 ); auto ptr = (char*)tracy_malloc( sz ); memcpy( ptr, &sz, 2 ); diff --git a/public/client/TracyScoped.hpp b/public/client/TracyScoped.hpp index bc130791..d2274e40 100644 --- a/public/client/TracyScoped.hpp +++ b/public/client/TracyScoped.hpp @@ -108,7 +108,7 @@ public: tracy_force_inline void Text( const char* txt, size_t size ) { - assert( size < std::numeric_limits::max() ); + assert( size < (std::numeric_limits::max)() ); if( !m_active ) return; #ifdef TRACY_ON_DEMAND if( GetProfiler().ConnectionId() != m_connectionId ) return; @@ -123,7 +123,7 @@ public: tracy_force_inline void Name( const char* txt, size_t size ) { - assert( size < std::numeric_limits::max() ); + assert( size < (std::numeric_limits::max)() ); if( !m_active ) return; #ifdef TRACY_ON_DEMAND if( GetProfiler().ConnectionId() != m_connectionId ) return; diff --git a/public/common/TracyProtocol.hpp b/public/common/TracyProtocol.hpp index 04c98690..5eb1639d 100644 --- a/public/common/TracyProtocol.hpp +++ b/public/common/TracyProtocol.hpp @@ -16,7 +16,7 @@ using lz4sz_t = uint32_t; enum { TargetFrameSize = 256 * 1024 }; enum { LZ4Size = Lz4CompressBound( TargetFrameSize ) }; -static_assert( LZ4Size <= std::numeric_limits::max(), "LZ4Size greater than lz4sz_t" ); +static_assert( LZ4Size <= (std::numeric_limits::max)(), "LZ4Size greater than lz4sz_t" ); static_assert( TargetFrameSize * 2 >= 64 * 1024, "Not enough space for LZ4 stream buffer" ); enum { HandshakeShibbolethSize = 8 }; diff --git a/public/tracy/TracyLua.hpp b/public/tracy/TracyLua.hpp index 6ee2e308..c972ffb2 100644 --- a/public/tracy/TracyLua.hpp +++ b/public/tracy/TracyLua.hpp @@ -173,10 +173,10 @@ static tracy_force_inline void SendLuaCallstack( lua_State* L, uint32_t depth ) { const uint32_t line = dbg[i].currentline; memcpy( dst, &line, 4 ); dst += 4; - assert( fsz[i] <= std::numeric_limits::max() ); + assert( fsz[i] <= (std::numeric_limits::max)() ); memcpy( dst, fsz+i, 2 ); dst += 2; memcpy( dst, func[i], fsz[i] ); dst += fsz[i]; - assert( ssz[i] <= std::numeric_limits::max() ); + assert( ssz[i] <= (std::numeric_limits::max)() ); memcpy( dst, ssz+i, 2 ); dst += 2; memcpy( dst, dbg[i].source, ssz[i] ), dst += ssz[i]; } @@ -333,7 +333,7 @@ static inline int LuaZoneText( lua_State* L ) auto txt = lua_tostring( L, 1 ); const auto size = strlen( txt ); - assert( size < std::numeric_limits::max() ); + assert( size < (std::numeric_limits::max)() ); auto ptr = (char*)tracy_malloc( size ); memcpy( ptr, txt, size ); @@ -358,7 +358,7 @@ static inline int LuaZoneName( lua_State* L ) auto txt = lua_tostring( L, 1 ); const auto size = strlen( txt ); - assert( size < std::numeric_limits::max() ); + assert( size < (std::numeric_limits::max)() ); auto ptr = (char*)tracy_malloc( size ); memcpy( ptr, txt, size ); @@ -378,7 +378,7 @@ static inline int LuaMessage( lua_State* L ) auto txt = lua_tostring( L, 1 ); const auto size = strlen( txt ); - assert( size < std::numeric_limits::max() ); + assert( size < (std::numeric_limits::max)() ); auto ptr = (char*)tracy_malloc( size ); memcpy( ptr, txt, size );