public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52156] New: add warning for allocated array being converted to pointer to base
@ 2012-02-07 19:37 redi at gcc dot gnu.org
2012-02-07 20:08 ` [Bug c++/52156] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2012-02-07 19:37 UTC (permalink / raw)
To: gcc-bugs
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*
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-02-07 20:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-07 19:37 [Bug c++/52156] New: add warning for allocated array being converted to pointer to base redi at gcc dot gnu.org
2012-02-07 20:08 ` [Bug c++/52156] " pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).