https://llvm.org/bugs/show_bug.cgi?id=26395
Bug ID: 26395 Summary: Analyzer says undefined behavior in uniform_int_distribution<size_t> Product: libc++ Version: 3.7 Hardware: Macintosh OS: MacOS X Status: NEW Severity: normal Priority: P Component: All Bugs Assignee: unassignedclangb...@nondot.org Reporter: jared.gr...@gmail.com CC: llvm-bugs@lists.llvm.org, mclow.li...@gmail.com Classification: Unclassified The clang static analyzer flags this code as having undefined behavior. Note that if I change "size_t" to "unsigned" then things look fine. It looks like the engine is 32-bit but it's going to try a 64-bit shift maybe? I'm totally guessing here. .../c++/v1/algorithm:2920 warning: The result of the '>>' expression is undefined __mask0_ = __w0_ > 0 ? _Engine_result_type(~0) >> (_EDt - __w0_) : ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ To reproduce: $ cat x.cpp #include <random> #include <cstddef> size_t genRandom(size_t maxValue) { std::minstd_rand engine; std::uniform_int_distribution<size_t> dist{0, maxValue}; return dist(engine); } $ clang++ x.cpp -std=c++14 --analyze -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs