This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52156] New: add warning for allocated array being converted to pointer to base
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 07 Feb 2012 19:37:05 +0000
- Subject: [Bug c++/52156] New: add warning for allocated array being converted to pointer to base
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52156
Bug #: 52156
Summary: add warning for allocated array being converted to
pointer to base
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: enhancement
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: redi@gcc.gnu.org
struct B { int i; B() : i(0) { } };
struct D : B { int j; D() : j(1) { }};
int main()
{
B* b = new D[2]; // warning
return b[1].i;
}
It might be a good idea to warn about this code, the allocated array cannot be
safely indexed or deleted through any type except D*
There should be a warning if a new-expression allocates an array of D and the
result undergoes pointer conversion to a type that is not cv D*