[llvm-bugs] [Bug 27334] New: Left shifting beyond sizeof int seems to have no effect.

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Apr 13 05:04:54 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=27334

            Bug ID: 27334
           Summary: Left shifting beyond sizeof int seems to have no
                    effect.
           Product: clang
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: norman.wilson at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

Best way to describe is show the code.

#include <cassert>
#include <iostream>

int
main()
{
    int count = sizeof(unsigned) * 8;
    unsigned x = (~0x0u) << count;
    std::cout << std::hex << x << std::endl;
    assert(x == 0);
}

I'd have thought that this shifting would result in x being zero or is this
undefined behaviour? This is using the following version:

bash-3.2$ clang++ --version
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.3.0
Thread model: posix

-- 
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/20160413/8fa52065/attachment.html>


More information about the llvm-bugs mailing list