Skip to content

Commit f9824b5

Browse files
committed
Fix member shadowing and type conversion warnings under strict compiler checks
1 parent 6b908ef commit f9824b5

4 files changed

Lines changed: 16 additions & 10 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ target_include_directories(pcg-cpp INTERFACE
1515

1616
target_compile_features(pcg-cpp INTERFACE cxx_std_11)
1717

18+
if(MSVC)
19+
target_compile_options(pcg-cpp INTERFACE /W4) # /Wall is extremely noisy on MSVC
20+
else()
21+
target_compile_options(pcg-cpp INTERFACE -Wall -Wextra -Wpedantic)
22+
endif()
23+
1824
# Options
1925
option(PCG_CPP_BUILD_SAMPLES "Build samples" ON)
2026
option(PCG_CPP_BUILD_TESTS "Build tests" ON)

include/pcg_extras.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,10 @@ SrcIter uneven_copy_impl(
401401
typedef typename std::iterator_traits<SrcIter>::value_type src_t;
402402
typedef typename std::iterator_traits<DestIter>::value_type dest_t;
403403

404-
constexpr bitcount_t SRC_SIZE = sizeof(src_t);
405-
constexpr bitcount_t DEST_SIZE = sizeof(dest_t);
406-
constexpr bitcount_t DEST_BITS = DEST_SIZE * 8;
407-
constexpr bitcount_t SCALE = SRC_SIZE / DEST_SIZE;
404+
constexpr size_t SRC_SIZE = sizeof(src_t);
405+
constexpr size_t DEST_SIZE = sizeof(dest_t);
406+
constexpr bitcount_t DEST_BITS = bitcount_t(DEST_SIZE * 8);
407+
constexpr size_t SCALE = SRC_SIZE / DEST_SIZE;
408408

409409
size_t count = 0;
410410
src_t value = 0;
@@ -437,10 +437,10 @@ SrcIter uneven_copy_impl(
437437

438438
while (dest_first != dest_last) {
439439
dest_t value(0UL);
440-
unsigned int shift = 0;
440+
size_t shift = 0;
441441

442442
for (size_t i = 0; i < SCALE; ++i) {
443-
value |= dest_t(*src_first++) << shift;
443+
value |= dest_t(*src_first++) << bitcount_t(shift);
444444
shift += SRC_BITS;
445445
}
446446

include/pcg_random.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,8 @@ itype engine<xtype,itype,output_mixin,output_previous,stream_mixin,
676676
itype cur_state, itype newstate, itype cur_mult, itype cur_plus, itype mask)
677677
{
678678
constexpr itype ONE = 1u; // itype could be weird, so use constant
679-
bool is_mcg = cur_plus == itype(0);
680-
itype the_bit = is_mcg ? itype(4u) : itype(1u);
679+
bool is_mcg_internal = cur_plus == itype(0);
680+
itype the_bit = is_mcg_internal ? itype(4u) : itype(1u);
681681
itype distance = 0u;
682682
while ((cur_state & mask) != (newstate & mask)) {
683683
if ((cur_state & the_bit) != (newstate & the_bit)) {
@@ -689,7 +689,7 @@ itype engine<xtype,itype,output_mixin,output_previous,stream_mixin,
689689
cur_plus = (cur_mult+ONE)*cur_plus;
690690
cur_mult *= cur_mult;
691691
}
692-
return is_mcg ? distance >> 2 : distance;
692+
return is_mcg_internal ? distance >> 2 : distance;
693693
}
694694

695695
template <typename xtype, typename itype,

sample/cppref-sample.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int main()
6363

6464
std::map<int, int> hist;
6565
for (int n = 0; n < 10000; ++n) {
66-
++hist[std::round(normal_dist(rng))];
66+
++hist[int(std::round(normal_dist(rng)))];
6767
}
6868
std::cout << "Normal distribution around " << mean << ":\n";
6969
for (auto p : hist) {

0 commit comments

Comments
 (0)