Skip to content

Commit

Permalink
Fix clang build
Browse files Browse the repository at this point in the history
The build failed with the following error:
non-constant-expression cannot be narrowed from type 'unsigned long' to
'uint32' (aka 'unsigned int') in initializer list [-Wc++11-narrowing]

This comes from the switch to C++11, the fix is to explicitely cast the
type (we know that it'll still fit into the smaller type).
  • Loading branch information
Cyberium authored and DasBlub committed Oct 13, 2015
1 parent a516667 commit 731e86d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions dep/src/g3dlite/uint128.cpp
Expand Up @@ -17,8 +17,9 @@ static void addAndCarry(const uint64& _a, const uint64& _b, uint64& carry, uint6

// Break each number into 4 32-bit chunks. Since we are using uints, right-shifting will fill with zeros.
// This eliminates the need to and with 0xFFFFFFFF.
uint32 a [2] = {_a & 0xFFFFFFFF, _a >> 32};
uint32 b [2] = {_b & 0xFFFFFFFF, _b >> 32};
/* G3DFIX: fix adding explicit use of static_cast */
uint32 a [2] = {static_cast<unsigned int>(_a & 0xFFFFFFFF), static_cast<unsigned int>(_a >> 32)};
uint32 b [2] = {static_cast<unsigned int>(_b & 0xFFFFFFFF), static_cast<unsigned int>(_b >> 32)};

uint64 tmp = uint64(a[0]) + b[0];

Expand All @@ -35,8 +36,9 @@ void multiplyAndCarry(const uint64& _a, const uint64& _b, uint64& carry, uint64&

// Break each number into 4 32-bit chunks. Since we are using uints, right-shifting will fill with zeros.
// This eliminates the need to and with 0xFFFFFFFF.
uint32 a [2] = {_a & 0xFFFFFFFF, _a >> 32};
uint32 b [2] = {_b & 0xFFFFFFFF, _b >> 32};
/* G3DFIX: fix adding explicit use of static_cast */
uint32 a[2] = { static_cast<unsigned int>(_a & 0xFFFFFFFF), static_cast<unsigned int>(_a >> 32) };
uint32 b[2] = { static_cast<unsigned int>(_b & 0xFFFFFFFF), static_cast<unsigned int>(_b >> 32) };

uint64 prod [2][2];
for(int i = 0; i < 2; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion src/game/vmap/RegularGrid.h
Expand Up @@ -107,7 +107,7 @@ class RegularGrid2D

static Cell ComputeCell(float fx, float fy)
{
Cell c = {fx* (1.f / CELL_SIZE) + (CELL_NUMBER / 2), fy* (1.f / CELL_SIZE) + (CELL_NUMBER / 2)};
Cell c = { static_cast<int>(fx* (1.f / CELL_SIZE) + (CELL_NUMBER / 2)), static_cast<int>(fy* (1.f / CELL_SIZE) + (CELL_NUMBER / 2)) };
return c;
}

Expand Down

0 comments on commit 731e86d

Please sign in to comment.