[Bug c/14710] New: Warning about useless casts

debian-gcc at lists dot debian dot org gcc-bugzilla@gcc.gnu.org
Wed Mar 24 06:35:00 GMT 2004


[forwarded from http://bugs.debian.org/237207]

It would be nice if there was an option to add a warning about
"useless" casts. Although they are not really incorrect, they
might become incorrect/inefficient as the program evolves. Ie;

struct A { int a; };
struct B : A { int b; };
void func(A *a) { ++a; } 

int main(int ac, char **av)
{
    A a;
    B b;

    func((A*)&a); // Useless cast since a already is an A.
    func(static_cast<A*>(&a)); // Just as useless.
    func((A*)&b); // Useless cast since b is a kind of A.
    func(static_cast<A*>(&b)); // Just as useless.

    return 0;
}

-- 
           Summary: Warning about useless casts
           Product: gcc
           Version: 3.3.4
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: debian-gcc at lists dot debian dot org
                CC: gcc-bugs at gcc dot gnu dot org


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



More information about the Gcc-bugs mailing list