The following const-incorrect program compiles without error on gcc 4.1.0, and 4.3.0 20070323:
class Foo {}; class Bar : public Foo {}; static const Foo *foo = 0; static Bar *bar = static_cast<const Bar*>(foo); // Error, casts away const void func(const Foo *foo) { Bar *bar = static_cast<const Bar*>(foo); // Error, casts away const } gcc 2.95.3, 3.4.5, and 4.0.2 report errors on the commented lines above, so it looks like a compiler regression in 4.1.0. I looked hard through existing PRs, and couldn't find this reported elsewhere (the closest is PR 20475, but it's concerned with 3.4.4 and the const-ness, or otherwise, of string literals, so not the same). I'd be a little surprised if I'm the first to see it, but it's possible... -- Summary: static_cast can remove const-ness Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: simon_baldwin at yahoo dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31449