[Bug libstdc++/85749] Possible -Wsign-conversion false negative with std::default_random_engine
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85749 Jonathan Wakely changed: What|Removed |Added Status|ASSIGNED|RESOLVED Resolution|--- |FIXED Target Milestone|--- |9.0 --- Comment #4 from Jonathan Wakely --- Fixed on trunk.
[Bug libstdc++/85749] Possible -Wsign-conversion false negative with std::default_random_engine
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85749 --- Comment #3 from Jonathan Wakely --- Author: redi Date: Tue May 15 15:36:46 2018 New Revision: 260263 URL: https://gcc.gnu.org/viewcvs?rev=260263=gcc=rev Log: PR libstdc++/85749 constrain seed sequences for random number engines Constrain constructors and member functions of random number engines so that functions taking seed sequences can only be called with types that meet the seed sequence requirements. PR libstdc++/85749 * include/bits/random.h (__detail::__is_seed_seq): New SFINAE helper. (linear_congruential_engine, mersenne_twister_engine) (subtract_with_carry_engine, discard_block_engine) (independent_bits_engine, shuffle_order_engine): Use __is_seed_seq to constrain function templates taking seed sequences. * include/bits/random.tcc (linear_congruential_engine::seed(_Sseq&)) (mersenne_twister_engine::seed(_Sseq&)) (subtract_with_carry_engine::seed(_Sseq&)): Change return types to match declarations. * include/ext/random (simd_fast_mersenne_twister_engine): Use __is_seed_seq to constrain function templates taking seed sequences. * include/ext/random.tcc (simd_fast_mersenne_twister_engine::seed): Change return type to match declaration. * testsuite/26_numerics/random/discard_block_engine/cons/seed_seq2.cc: New. * testsuite/26_numerics/random/independent_bits_engine/cons/ seed_seq2.cc: New. * testsuite/26_numerics/random/linear_congruential_engine/cons/ seed_seq2.cc: New. * testsuite/26_numerics/random/mersenne_twister_engine/cons/ seed_seq2.cc: New. * testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error lineno. * testsuite/26_numerics/random/shuffle_order_engine/cons/seed_seq2.cc: New. * testsuite/26_numerics/random/subtract_with_carry_engine/cons/ seed_seq2.cc: New. * testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/ seed_seq2.cc: New. Added: trunk/libstdc++-v3/testsuite/26_numerics/random/discard_block_engine/cons/seed_seq2.cc trunk/libstdc++-v3/testsuite/26_numerics/random/independent_bits_engine/cons/seed_seq2.cc trunk/libstdc++-v3/testsuite/26_numerics/random/linear_congruential_engine/cons/seed_seq2.cc trunk/libstdc++-v3/testsuite/26_numerics/random/mersenne_twister_engine/cons/seed_seq2.cc trunk/libstdc++-v3/testsuite/26_numerics/random/shuffle_order_engine/cons/seed_seq2.cc trunk/libstdc++-v3/testsuite/26_numerics/random/subtract_with_carry_engine/cons/seed_seq2.cc trunk/libstdc++-v3/testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/seed_seq2.cc Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/include/bits/random.h trunk/libstdc++-v3/include/bits/random.tcc trunk/libstdc++-v3/include/ext/random trunk/libstdc++-v3/include/ext/random.tcc trunk/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
[Bug libstdc++/85749] Possible -Wsign-conversion false negative with std::default_random_engine
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85749 Jonathan Wakely changed: What|Removed |Added Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
[Bug libstdc++/85749] Possible -Wsign-conversion false negative with std::default_random_engine
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85749 Jonathan Wakely changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2018-05-11 Component|c++ |libstdc++ Ever confirmed|0 |1 --- Comment #2 from Jonathan Wakely --- There's also a template constructor, which is the one that gets used: template::value> ::type> explicit linear_congruential_engine(_Sseq& __q) { seed(__q); } The conversion to unsigned now happens when calling seed(__q), which is in the std::lib code and so gets suppressed because it's in a system header (and using -Wsystem-headers produces a lot of warnings from the std::lib code). That constructor is only supposed to be used for seed sequence types, but nothign in the standard actually ensures that, and so it gets used for your example too. That might be a defect in the standard. I'm going to re-assign this to libstdc++, so we can make that constructor less greedy.