[llvm-bugs] [Bug 37201] New: Should clang warn when modifying a sub-field of a constant sub-object?

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Apr 22 13:40:57 PDT 2018


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

            Bug ID: 37201
           Summary: Should clang warn when modifying a sub-field of a
                    constant sub-object?
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: lebedev.ri at gmail.com
                CC: llvm-bugs at lists.llvm.org

https://godbolt.org/g/t5Z2Rp

struct A {
    int v;
};

struct B {
    A& a0;
    A* a1;
};

struct C {
    C(const B& b_) : b0(b_), b1(&b_) {
        const B b(b_);
        b.a0.v = 0; b.a1->v = 0;
    }
    ~C() {
        b0.a0.v = 0; b0.a1->v = 0;
        b1->a0.v = 0; b1->a1->v = 0;
    }

    const B& b0;
    const B* b1;
};

I was surprised not to see a warning per each ".v = 0".

-- 
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/20180422/5b81b593/attachment.html>


More information about the llvm-bugs mailing list