This is the mail archive of the gcc-help@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]

Re: dynamic_cast from a const class


On 12.06.2013 16:12, Florian Weimer wrote:
On 06/11/2013 07:23 PM, david.hagood@gmail.com wrote:

The dynamic_cast operator shall not cast away constness (5.2.11).


class A {
};

class B : public A {
};

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


You aren't casting *away* const-ness, you are adding const-ness (and then
discarding it when you assign to A - which should be an error).

I agree about the error partâAndrey, could you please file a bug?


Done, PR57599. C++ quirks make me be never sure whether something is actually a bug, so I wanted to double check..

Andrey


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