Skip to content

[refine](core) add compile-time safety checks to assert_cast#63133

Open
Mryange wants to merge 1 commit intoapache:masterfrom
Mryange:assert_cast-dev-11
Open

[refine](core) add compile-time safety checks to assert_cast#63133
Mryange wants to merge 1 commit intoapache:masterfrom
Mryange:assert_cast-dev-11

Conversation

@Mryange
Copy link
Copy Markdown
Contributor

@Mryange Mryange commented May 11, 2026

What problem does this PR solve?

Issue Number: N/A

Problem Summary:

assert_cast previously only performed runtime type checks (via typeid comparison). 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 where TypeCheckOnRelease::DISABLE turns checks into static_cast without 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

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@Mryange
Copy link
Copy Markdown
Contributor Author

Mryange commented May 11, 2026

/review

@hello-stephen
Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Mryange
Copy link
Copy Markdown
Contributor Author

Mryange commented May 11, 2026

run buildall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants