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

* [Bug c++/52156] add warning for allocated array being converted to pointer to base
  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 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-02-07 20:08 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52156

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-02-07
     Ever Confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-02-07 20:08:07 UTC ---
Confirmed, yes this direct assignment should have a warning.


^ 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).