Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save rtldg/4d5160f902afec43f4ab9f315d5df67e to your computer and use it in GitHub Desktop.

Select an option

Save rtldg/4d5160f902afec43f4ab9f315d5df67e to your computer and use it in GitHub Desktop.
From f3db078d94224f4bebd9c7a8615a277e55b92efe Mon Sep 17 00:00:00 2001
From: rtldg <rtldg@protonmail.com>
Date: Thu, 6 Mar 2025 08:14:39 +0000
Subject: [PATCH] Fix 'non-const reference cannot bind to bit-field' error with
newer clang versions
This specifically shows up when trying to use zig 0.14.0 (llvm 19.1.7) to cross-compile to Linux.
In file included from H:\code\srcwr\srcwrtimer/_external/alliedmodders/sourcemod/public/CDetour/detours.cpp:1:
In file included from H:\code\srcwr\srcwrtimer/_external/alliedmodders/sourcemod/public/CDetour/detours.h:36:
In file included from H:\code\srcwr\srcwrtimer/_external/alliedmodders/sourcemod/public/smsdk_ext.h:100:
In file included from H:\code\srcwr\srcwrtimer/_external/alliedmodders/mmsource/core/ISmmPlugin.h:39:
In file included from H:\code\srcwr\srcwrtimer/_external/alliedmodders/mmsource/core/ISmmAPI.h:47:
In file included from H:\code\srcwr\srcwrtimer/_external/alliedmodders/hl2sdk-css/public/eiface.h:16:
In file included from H:\code\srcwr\srcwrtimer/_external/alliedmodders/hl2sdk-css/public/tier1/convar.h:21:
In file included from H:\code\srcwr\srcwrtimer/_external/alliedmodders/hl2sdk-css/public/tier1/utlvector.h:25:
H:\code\srcwr\srcwrtimer/_external/alliedmodders/hl2sdk-css/public/tier1/utlblockmemory.h:141:10: error: non-const reference cannot bind to bit-field 'm_nIndexShift'
141 | V_swap( m_nIndexShift, mem.m_nIndexShift );
| ^~~~~~~~~~~~~
H:\code\srcwr\srcwrtimer/_external/alliedmodders/hl2sdk-css/public/tier1/utlblockmemory.h:111:6: note: bit-field is declared here
111 | int m_nIndexShift : 5;
| ^
H:\code\srcwr\srcwrtimer/_external/alliedmodders/hl2sdk-css/public/mathlib/mathlib.h:717:29: note: passing argument to parameter 'x' here
717 | FORCEINLINE void V_swap( T& x, T& y )
| ^ ^
---
public/tier1/utlblockmemory.h | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/public/tier1/utlblockmemory.h b/public/tier1/utlblockmemory.h
index 8d86c59e..4782e235 100644
--- a/public/tier1/utlblockmemory.h
+++ b/public/tier1/utlblockmemory.h
@@ -137,8 +137,12 @@ void CUtlBlockMemory<T,I>::Swap( CUtlBlockMemory< T, I > &mem )
{
V_swap( m_pMemory, mem.m_pMemory );
V_swap( m_nBlocks, mem.m_nBlocks );
- V_swap( m_nIndexMask, mem.m_nIndexMask );
- V_swap( m_nIndexShift, mem.m_nIndexShift );
+ int tmp = m_nIndexMask;
+ m_nIndexMask = mem.m_nIndexMask;
+ mem.m_nIndexMask = tmp;
+ tmp = m_nIndexShift;
+ m_nIndexShift = mem.m_nIndexShift;
+ mem.m_nIndexShift = tmp;
}
--
2.47.1.windows.1
diff --git a/public/bitvec.h b/public/bitvec.h
index a1a984d0..137c2d29 100644
--- a/public/bitvec.h
+++ b/public/bitvec.h
@@ -448,7 +448,7 @@ typedef CBitVec<32> CDWordBitVec;
template <typename BITCOUNTTYPE>
inline CVarBitVecBase<BITCOUNTTYPE>::CVarBitVecBase()
{
- Plat_FastMemset( this, 0, sizeof( *this ) );
+ Plat_FastMemset( (void*)this, 0, sizeof( *this ) );
}
//-----------------------------------------------------------------------------
diff --git a/public/tier1/utlsymbol.h b/public/tier1/utlsymbol.h
index d55afdc7..38c36e88 100644
--- a/public/tier1/utlsymbol.h
+++ b/public/tier1/utlsymbol.h
@@ -105,7 +105,7 @@ public:
inline bool HasElement( const char* pStr ) const
{
- return Find( pStr ) != UTL_INVAL_SYMBOL;
+ return Find( pStr ) != CUtlSymbol(UTL_INVAL_SYMBOL);
}
// Remove all symbols in the table.
diff --git a/game/server/ai_utils.h b/game/server/ai_utils.h
index 8cdde7ba..d608ba5e 100644
--- a/game/server/ai_utils.h
+++ b/game/server/ai_utils.h
@@ -70,7 +70,7 @@ public:
bool IsMarkSet()
{
- return ( m_flMarkTolerance != NO_MARK );
+ return ( m_flMarkTolerance != (float)NO_MARK );
}
bool TargetMoved( CBaseEntity *pEntity )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment