[llvm-bugs] [Bug 24845] New: C++ says shift-overflow should produce 0
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Sep 16 10:34:35 PDT 2015
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: unassignedclangbugs at nondot.org
Reporter: huntting at glarp.com
CC: dgregor at apple.com, llvm-bugs at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150916/b0357460/attachment.html>
More information about the llvm-bugs
mailing list