This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/52156] New: add warning for allocated array being converted to pointer to base


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*


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]