Analyzer ignores qualifiers when checking for casts.
Fixes false positive analyzer warnings caused by type qualifiers in certain code assignments.
The GCC analyzer incorrectly flagged assignments that differed only in type qualifiers (e.g., const) as casts, leading to spurious warnings. This was particularly problematic in scenarios like constructing objects where this (a T *const) was copied into a T * temporary. This commit modifies the is_any_cast_p function to compare only the base types, resolving these false positives.
In Details
The analyzer::is_any_cast_p function in region-model.cc now correctly handles type qualifiers. Previously, it treated a copy between types differing only in qualifiers (e.g., T *const vs. T *) as a cast. This led to false positives, notably in constructors returning this which would be copied into a temporary T *. The fix compares the main variants of the LHS and RHS types, ignoring qualifiers.
- analyzer
- A GCC component that statically analyzes code to find potential bugs, such as use-after-free, buffer overflows, and uninitialized values, without executing the code.
- type qualifiers
- Keywords like
constandvolatilethat add information about how a type can be used or accessed.constindicates that the value cannot be modified through that type.