[clang-tidy] `bugprone-unchecked-optional-access`: handle inheritance from `BloombergLP::bslstl::Optional_Base` to prevent false-positives for allocator-aware BDE types (#168863) ### Problem `bugprone-unchecked-optional-access` produces a lot of false positives if type inside of `bsl::optional` or `bdlb::NullableValue` is **allocator-aware**. This is a very common pattern, especially due to frequent use of `bsl::string`. [Compiler explorer example to showcase false-positives with BDE library](https://compiler-explorer.com/z/P4zh7KbGx) ### Context https://github.com/llvm/llvm-project/pull/101450 added support for analysing `bsl::optional` access patterns. However, mock `bsl::optional` type has been very simplified for testing purposes which lead to missing false-positives related to _inheritance_ logic for this type. [According to this article](https://bloomberg.github.io/bde/articles/bsl_optional.html#interoperability-between-bsl-optional-and-bdlb-nullablevalue), there are two ways of inheritance for `bsl::optional` and `bdlb::NullableValue`: 1. C++17 non-allocator-aware type ` bdlb::NullableValue<T> -> bsl::optional<T> -> std::optional<T>` 2. C++17 **Allocator-Aware**, and pre-C++17 `bdlb::NullableValue<T> -> bsl::optional<T>` But this is not a full picture :( In practice, there is an additional layer in the inheritance chain: `BloombergLP::bslstl::Optional_Base`. Thus, the actual inheritance structure is: 1. C++17 non-allocator-aware `bdlb::NullableValue<T> -> bsl::optional<T> -> BloombergLP::bslstl::Optional_Base<T, false> -> std::optional<T>` 2. C++17 **Allocator-Aware**, and pre-C++17 `bdlb::NullableValue<T> -> bsl::optional<T> -> BloombergLP::bslstl::Optional_Base<T, true>` [Source code to show this inheritance](https://github.com/bloomberg/bde/blob/f8b09a9298a5a76741c0820344c8850bf0b2e177/groups/bsl/bslstl/bslstl_optional.h#L1851) ### Root cause IIUC, because of this inheritance logic, function calls to `bsl::optional::has_value()` are processed like: 1. `std::optional::has_value()` for non-allocator-aware type. 2. `BloombergLP::bslstl::Optional_Base::has_value()` for allocator-aware type. Obviously, similar conversion are true for other common methods like `.value()` **This PR tries to solve this issue by improving mocks and adding `BloombergLP::bslstl::Optional_Base<T>` to list of supported optional types**
Welcome to the LLVM project!
This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.
The LLVM project has multiple components. The core of the project is itself called “LLVM”. This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.
C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.
Other components include: the libc++ C++ standard library, the LLD linker, and more.
Consult the Getting Started with LLVM page for information on building and running LLVM.
For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.
Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.
The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.