[refine](core) add compile-time safety checks to assert_cast#63133
Open
Mryange wants to merge 1 commit intoapache:masterfrom
Open
[refine](core) add compile-time safety checks to assert_cast#63133Mryange wants to merge 1 commit intoapache:masterfrom
Mryange wants to merge 1 commit intoapache:masterfrom
Conversation
Contributor
Author
|
/review |
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
There was a problem hiding this comment.
Review result: no blocking issues found in the actual PR diff. The change adds compile-time constraints to assert_cast and is consistent with the helper's existing downcast-only runtime contract; representative usages are class pointer/reference downcasts from common base types.
Critical checkpoints:
- Goal/test: The PR aims to reject unrelated/upcast assert_cast misuse at compile time. The code implements that for class pointer/reference downcasts. No dedicated test was added; given this is a compile-time constraint in a heavily used template, existing BE compilation should cover compatibility.
- Scope/focus: The change is small and focused in be/src/core/assert_cast.h.
- Concurrency/lifecycle/config/compatibility: Not applicable; no runtime state, persistence, protocol, or config changes.
- Parallel code paths: Not applicable; this is the single assert_cast implementation.
- Error handling: Runtime error behavior is unchanged for valid template instantiations that keep checks enabled.
- Memory/data correctness: Not applicable; no allocation, storage, or data visibility changes.
- Performance: No runtime overhead added beyond compile-time static_asserts.
- Observability: Not applicable.
User focus: No additional user-provided review focus was present.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Issue Number: N/A
Problem Summary:
assert_castpreviously only performed runtime type checks (viatypeidcomparison). Misuse — such as casting between unrelated types or upcasting — would only be caught at runtime, making it easy for incorrect usage to slip into release builds whereTypeCheckOnRelease::DISABLEturns checks intostatic_castwithout any verification.This catches invalid casts at build time instead of producing undefined behavior or hard-to-diagnose runtime errors.
Release note
None
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)