llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.14k stars 11.11k forks source link

Extend `bugprone-unchecked-optional-access` to All Types #96984

Open WSUFan opened 4 weeks ago

WSUFan commented 4 weeks ago

Currently, the bugprone-unchecked-optional-access check only applies to optional-like types. However, why don't we extend this check to all types? This would allow user-defined types to be verified with specific methods before they are used.

For example, consider pointer usage. When using pointers, we should first check if the pointer is not null. In my view, these two cases (optional and pointer) are similar because both require validation before use to prevent potential runtime errors.

Extending bugprone-unchecked-optional-access to all types could provide the following benefits:

  1. Enhanced Safety: Automatically checking user-defined types before use can prevent common runtime errors, increasing the overall safety of the code.
  2. Consistency: Having a uniform check for all types ensures that the same standards are applied throughout the codebase, improving maintainability.
  3. Early Error Detection: By ensuring all types are checked, potential issues can be caught early in the development process, reducing debugging time.
llvmbot commented 4 weeks ago

@llvm/issue-subscribers-clang-tidy

Author: None (WSUFan)

Currently, the `bugprone-unchecked-optional-access` check only applies to optional-like types. However, why don't we extend this check to all types? This would allow user-defined types to be verified with specific methods before they are used. For example, consider pointer usage. When using pointers, we should first check if the pointer is not null. In my view, these two cases (optional and pointer) are similar because both require validation before use to prevent potential runtime errors. Extending bugprone-unchecked-optional-access to all types could provide the following benefits: 1. Enhanced Safety: Automatically checking user-defined types before use can prevent common runtime errors, increasing the overall safety of the code. 2. Consistency: Having a uniform check for all types ensures that the same standards are applied throughout the codebase, improving maintainability. 3. Early Error Detection: By ensuring all types are checked, potential issues can be caught early in the development process, reducing debugging time.