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

            Bug ID: 57599
           Summary: g++ accepts invalid dynamic_cast of a const type to a
                    regular type
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: abel at gcc dot gnu.org

The following code is accepted by g++ (versions 3.3, 4.6, 4.7 at least, I
didn't check trunk) but seems to be invalid c++ and is rejected by clang 3.2,
icc 13, msvc 12:

class A {
};

class B : public A {
};

int main() {
    A* a;
    B* b = new B();
    a = dynamic_cast<const A*>(b);
    return 0;
}

An expected error is along the lines of (icc):
error: a value of type "const A *" cannot be assigned to an entity of type "A
*"

Reply via email to