Module inheritance_safety

Module inheritance_safety 

Source
Expand description

Inheritance Safety Analysis

This module implements Rust-inspired safety checks for C++ inheritance.

Core principle: Inheritance is @unsafe by default, except when inheriting from @interface.

An @interface is a pure virtual class (like a Rust trait):

  • All methods are pure virtual (= 0)
  • No non-static data members
  • Virtual destructor required
  • Can only inherit from other @interfaces

Interface methods can be marked @safe or @unsafe. Implementations must:

  1. Match the safety annotation (if explicitly annotated)
  2. Inherit the safety annotation (if not explicitly annotated)
  3. Be validated for safety if marked @safe

Functions§

check_inheritance_safety
Run all inheritance safety checks
check_method_safety_contracts
Check that method implementations honor interface method safety contracts
check_safe_class_copy_semantics
Check that @safe classes don’t have non-deleted copy operations
check_safe_inheritance
Check that classes in @safe context only inherit from @interface classes
collect_interface_map
Build a map of interface classes for method safety checking
collect_interfaces
Build a set of interface class names from the parsed classes
validate_interface
Validate that a class marked as @interface is truly a pure interface
validate_interface_inheritance
Check that @interface classes only inherit from other @interfaces