This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/68888] New: No Warning when converting an array of a subclass to its parent
- From: "gcc-bugs at bluematt dot me" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 14 Dec 2015 00:45:50 +0000
- Subject: [Bug c++/68888] New: No Warning when converting an array of a subclass to its parent
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68888
Bug ID: 68888
Summary: No Warning when converting an array of a subclass to
its parent
Product: gcc
Version: 5.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gcc-bugs at bluematt dot me
Target Milestone: ---
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);
}