-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[clang-tidy] bugprone-unchecked-optional-access
: support detection of unsafe std::expected
access
#135045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@llvm/issue-subscribers-clang-tidy Author: Valentyn Yukhymenko (BaLiKfromUA)
I'd like to propose extending the existing clang-tidy check `bugprone-unchecked-optional-access` to also detect unsafe access to `std::expected<T, E>` values.
Just like From my experience with I am planning to work on draft PR in upcoming weeks, but want to start this issue to gather feedback. I tried to search for existing opened issues but didn't find any. Main questions for me:
If we are happy to start supporting |
I think that writing a new |
@vbvictor thanks for feedback!
I agree — having a dedicated check for That said, my main concern is maintainability: almost every false-positive fix or improvement made to I will try to implement PoC as a separate check to see what we really need to duplicate. |
Sounds good! If we are going to add it to Worth considering is that |
I'd like to propose extending the existing clang-tidy check
bugprone-unchecked-optional-access
to also detect unsafe access tostd::expected<T, E>
values.Just like
std::optional<T>
,std::expected<T, E>
requires validation (e.g. via.has_value()
oroperator bool()
) before accessing the contained value via.value()
,operator*()
, oroperator->()
. The same misuse patterns apply and can be caught using the same logic currently implemented inbugprone-unchecked-optional-access
.From my experience with
bugprone-unchecked-optional-access
implementation, code change should be quite straightforward.I am planning to work on draft PR in upcoming weeks, but want to start this issue to gather feedback. I tried to search for existing opened issues but didn't find any.
Main questions from me:
bugprone-unchecked-optional-access
, or would a new check likebugprone-unchecked-expected-access
be preferable?std::expected
-specific behaviors or edge cases I may have overlooked?If we are happy to start supporting
std::expected<T, E>
, IMO we also should supporttl::expected<T,E>
(link) because it is widely used in codebases which don't use C++ 23.The text was updated successfully, but these errors were encountered: