Answer the question
In order to leave comments, you need to log in
What C++ language operations can be potentially unsafe?
Answer the question
In order to leave comments, you need to log in
An assignment can be overloaded, so in general it can call arbitrary code that may not be safe, and therefore the operation itself cannot be considered safe.
As for the conversion of values of basic types, everything is not so simple, it can lead to errors in program logic (if some edge case was not provided), but by itself (as a single action) cannot cause exceptions and undefined behavior if the operands are themselves valid (do not throw access exceptions).
The rest of the reasoning given is generally correct, I did not notice any obvious errors.
Using dynamic_cast for reference types - an exception is thrown, which means unsafe.
Controversial: Assignment.
Yes: Using dynamic_cast to cast reference types.
Yes: Create an instance of the class.
Possible: Passing a class object to a function by value
With dynamic_cast, it is quite possible to run into a null pointer or the impossibility of casting.
When creating an instance, the constructor may fall or there may be no memory.
When assigning, in ordinary life, there should be no problems, but, in principle, they can be created by a banal redefinition of the assignment operator.
When passing by value, the copy constructor may be disabled, but this is determined at compile time, and, of course, there may not be enough memory on the stack.
Z.Y. As far as I understand, the implicit conversion of base types is checked at compile time, unless, of course, we use auto.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question