[llvm-bugs] [Bug 44296] New: Catch assigning to const object in ubsan

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Dec 13 11:32:54 PST 2019


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

            Bug ID: 44296
           Summary: Catch assigning to const object in ubsan
           Product: new-bugs
           Version: 9.0
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: anoyes34 at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

$ clang++ --version
clang version 9.0.0 (tags/RELEASE_900/final)
Target: x86_64-apple-darwin19.2.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin

$ cat test.cc
int main(int argc, char** argv) {
    const int x = 0;
    const_cast<int&>(x) = 1;
    return x;
}

$ clang++ -fsanitize=undefined test.cc

$ ./a.out

According to https://en.cppreference.com/w/cpp/language/const_cast this invokes
undefined behavior. I was hoping ubsan would complain, but it did not.

-- 
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/20191213/611f0fe2/attachment-0001.html>


More information about the llvm-bugs mailing list