[llvm-bugs] [Bug 25886] New: UBSan: missing check for modifying a const object through a const_cast

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Dec 18 10:03:00 PST 2015


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

            Bug ID: 25886
           Summary: UBSan: missing check for modifying a const object
                    through a const_cast
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: gonzalobg88 at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

The following UB is not currently caught by UBSan:

struct A {
  const int b = 10;
};

int main() {
  const int c = 25;
  const_cast<int&>(c) = 20;  // UB
  A a;  
  const_cast<int&>(a.b) = c;  // UB
  return a.b;
}

This is UB per [dcl.type.cv]/4.

-- 
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/20151218/5c0fff2a/attachment.html>


More information about the llvm-bugs mailing list