-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[clang-tidy] bugprone-unchecked-optional-access false positive #59705
Comments
@llvm/issue-subscribers-clang-tidy |
I seems to rather have something todo with the call to #include <optional>
#include <utility>
int g(std::optional<int>&& o) {
if (!o)
return -1;
return *std::forward<std::optional<int>>(o);
} |
It seems confused by every function which returns its input godbolt #include <optional>
template <typename T>
T identity(T t) {
return t;
}
int f(std::optional<int>&& o) {
if (!o) return -1;
return *identity(o);
} |
My best guess would be that the #include <optional>
std::optional<int> a() { return 42; }
int f() { return *a(); } Although |
But together a basic patch which handles the |
… to `std::forward` The check now understands that calling `std::forward` will not modify the underlying optional value. This fixes llvm#59705 Reviewed By: PiotrZSL Differential Revision: https://reviews.llvm.org/D147383
Clang-Tidy flags this behavior is bugprone when it check has_value through the boolean cast overload
if(!src)
and then proceeds with the optional access only in the if else branch the avoids the early return. We encountered this issue when upgrading clang-tidy here: pybind/pybind11#4387. Obviously, this is an easy fix for a nolint, but it would better if the check recognized early returns as valid checks for bugprone-unchecked-optional-access. I suspect this is actually caused by clang-tidy not recognizing theoperator!
in the flow as a valid check on the optional access. It could also have something to with the fact that std::optional is merely a template parameter in this caster.The text was updated successfully, but these errors were encountered: