[openjk] 02/32: snd_mem: fix build failure on big-endian CPUs with C++11 compilers

Simon McVittie smcv at debian.org
Sun Mar 12 18:03:01 UTC 2017


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch debian/master
in repository openjk.

commit b0935c7ebb206f251ef8c31c35fa69e6e2a523c2
Author: Simon McVittie <smcv at debian.org>
Date:   Sat Oct 29 13:07:04 2016 +0100

    snd_mem: fix build failure on big-endian CPUs with C++11 compilers
    
    The Debian powerpc, mips and s390x builds failed with:
    
    .../code/client/snd_mem.cpp: In function 'qboolean S_LoadSound_Actual(sfx_t*)':
    .../code/client/snd_mem.cpp:843:54: error: invalid operands of types '__gnu_cxx::__enable_if<true, double>::__type {aka double}' and 'int' to binary 'operator>>'
            if (sfx->fVolRange < (abs(sfx->pSoundData[i]) >> 8))
                                  ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
    .../code/client/snd_mem.cpp:845:50: error: invalid operands of types '__gnu_cxx::__enable_if<true, double>::__type {aka double}' and 'int' to binary 'operator>>'
             sfx->fVolRange = abs(sfx->pSoundData[i]) >> 8;
                              ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
    
    This appears to be because sfx->pSoundData[i] is of type short. C++98
    only provided int abs(int), long abs(long), float abs(float),
    double abs(double) and long double abs(long double) overloads, but
    C++11 also provides double abs(T) for all integral types T, including
    short. double is not a valid left-hand side for operator>> so
    compilation fails.
---
 code/client/snd_mem.cpp   | 6 ++++--
 codemp/client/snd_mem.cpp | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/code/client/snd_mem.cpp b/code/client/snd_mem.cpp
index 821c842..f2a003e 100644
--- a/code/client/snd_mem.cpp
+++ b/code/client/snd_mem.cpp
@@ -840,9 +840,11 @@ static qboolean S_LoadSound_Actual( sfx_t *sfx )
 						for (int i = 0; i < sfx->iSoundLengthInSamples; i++)
 						{
 							sfx->pSoundData[i] = LittleShort(sfx->pSoundData[i]);
-							if (sfx->fVolRange < (abs(sfx->pSoundData[i]) >> 8))
+							// C++11 defines double abs(short) which is not what we want here,
+							// because double >> int is not defined. Force interpretation as int
+							if (sfx->fVolRange < (abs(static_cast<int>(sfx->pSoundData[i])) >> 8))
 							{
-								sfx->fVolRange = abs(sfx->pSoundData[i]) >> 8;
+								sfx->fVolRange = abs(static_cast<int>(sfx->pSoundData[i])) >> 8;
 							}
 						}
 #endif
diff --git a/codemp/client/snd_mem.cpp b/codemp/client/snd_mem.cpp
index 62adbdd..ba07a33 100644
--- a/codemp/client/snd_mem.cpp
+++ b/codemp/client/snd_mem.cpp
@@ -839,9 +839,11 @@ static qboolean S_LoadSound_Actual( sfx_t *sfx )
 						for (int i = 0; i < sfx->iSoundLengthInSamples; i++)
 						{
 							sfx->pSoundData[i] = LittleShort(sfx->pSoundData[i]);
-							if (sfx->fVolRange < (abs(sfx->pSoundData[i]) >> 8))
+							// C++11 defines double abs(short) which is not what we want here,
+							// because double >> int is not defined. Force interpretation as int
+							if (sfx->fVolRange < (abs(static_cast<int>(sfx->pSoundData[i])) >> 8))
 							{
-								sfx->fVolRange = abs(sfx->pSoundData[i]) >> 8;
+								sfx->fVolRange = abs(static_cast<int>(sfx->pSoundData[i])) >> 8;
 							}
 						}
 #endif

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/openjk.git



More information about the Pkg-games-commits mailing list