https://llvm.org/bugs/show_bug.cgi?id=24845
Bug ID: 24845 Summary: C++ says shift-overflow should produce 0 Product: clang Version: 3.4 Hardware: PC OS: FreeBSD Status: NEW Severity: normal Priority: P Component: C++ Assignee: unassignedclangb...@nondot.org Reporter: huntt...@glarp.com CC: dgre...@apple.com, llvm-bugs@lists.llvm.org Classification: Unclassified Created attachment 14887 --> https://llvm.org/bugs/attachment.cgi?id=14887&action=edit example.cc prints expressions with shift-count-overflow This may be new to C++14, but section 5.8 of draft standard (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf) allows for shifting unsigned integers by more than their size. Hence at least in C++14, with 64bit long longs: assert(~0ULL << 64 == 0) Note that the C11 standard by contrast allows for "undefined behavior" in this case. I have not check previous draft versions of the C++ standard or the actual standard to see if this clause has recently changed. The attached example.cc produces this output on my x86_64 workstation: sizeof(0ULL) = 8 ~0ULL = 0xffffffffffffffff ~0ULL << (8*sizeof(0ULL)) = 0x1 ~(~0ULL << (8*sizeof(0ULL))) = 0x1 sizeof(0U) = 4 ~0U = 0xffffffff ~0U << (8*sizeof(0U)) = 0x1 ~(~0U << (8*sizeof(0U))) = 0x1 -- 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