<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - C++ says shift-overflow should produce 0"
href="https://llvm.org/bugs/show_bug.cgi?id=24845">24845</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>C++ says shift-overflow should produce 0
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.4
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>FreeBSD
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>huntting@glarp.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=14887" name="attach_14887" title="example.cc prints expressions with shift-count-overflow">attachment 14887</a> <a href="attachment.cgi?id=14887&action=edit" title="example.cc prints expressions with shift-count-overflow">[details]</a></span>
example.cc prints expressions with shift-count-overflow
This may be new to C++14, but section 5.8 of draft standard
(<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf</a>) 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</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>