mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
Closed #83.
This commit is contained in:
parent
26fc14cc8a
commit
6156e95782
|
@ -5867,7 +5867,7 @@ This code may work as expected for years, just to fail on a new machine, new com
|
||||||
|
|
||||||
If you implement your own RTTI, be careful.
|
If you implement your own RTTI, be careful.
|
||||||
|
|
||||||
##### Exception
|
##### Exceptions
|
||||||
|
|
||||||
If your implementation provided a really slow `dynamic_cast`, you may have to use a workaround.
|
If your implementation provided a really slow `dynamic_cast`, you may have to use a workaround.
|
||||||
However, all workarounds that cannot be statically resolved involve explicit casting (typically `static_cast`) and are error-prone.
|
However, all workarounds that cannot be statically resolved involve explicit casting (typically `static_cast`) and are error-prone.
|
||||||
|
@ -5879,6 +5879,8 @@ We are of the opinion that current implementations of `dynamic_cast` are unneces
|
||||||
For example, under suitable conditions, it is possible to perform a `dynamic_cast` in [fast constant time](http://www.stroustrup.com/fast_dynamic_casting.pdf).
|
For example, under suitable conditions, it is possible to perform a `dynamic_cast` in [fast constant time](http://www.stroustrup.com/fast_dynamic_casting.pdf).
|
||||||
However, compatibility makes changes difficult even if all agree that an effort to optimize is worthwhile.
|
However, compatibility makes changes difficult even if all agree that an effort to optimize is worthwhile.
|
||||||
|
|
||||||
|
In very rare cases, if you have measured that the `dynamic_cast` overhead is material, you have other means to statically guarantee that a downcast will succeed (e.g., you are using CRTP carefully), and there is no virtual inheritance involved, consider tactically resorting `static_cast` with a prominent comment and disclaimer summarizing this paragraph and that human attention is needed under maintenance because the type system can't verify correctness. Even so, in our experience such "I know what I'm doing" situations are still a known bug source.
|
||||||
|
|
||||||
##### Enforcement
|
##### Enforcement
|
||||||
|
|
||||||
Flag all uses of `static_cast` for downcasts, including C-style casts that perform a `static_cast`.
|
Flag all uses of `static_cast` for downcasts, including C-style casts that perform a `static_cast`.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user