[llvm-bugs] [Bug 25816] New: No Warning when converting an array of a subclass to its parent

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Dec 13 16:40:59 PST 2015


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

            Bug ID: 25816
           Summary: No Warning when converting an array of a subclass to
                    its parent
           Product: clang
           Version: 3.7
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: llvm-bugs at bluematt.me
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

Without bringing up the deadly "warn when using arrays in function
declarations" quagmire, if you are converting an array of one type to that of
another due to pointer decay, there should probably at least be a huge warning.

eg the following prints "1 2" to the surprise of many unthinking programmers.

#include <stdio.h>

class A {
public:
    int a;
};

class B : public A {
public:
    int b;
};

void go(A b[2]) {
    fprintf(stderr, "%d %d\n", b[0].a, b[1].a);
}

int main() {
    B bs[2];
    bs[0].a = 1;
    bs[0].b = 2;
    bs[1].a = 3;
    bs[1].b = 4;
    go(bs);
}

-- 
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/20151214/02a7ccd0/attachment.html>


More information about the llvm-bugs mailing list