-
Notifications
You must be signed in to change notification settings - Fork 16.5k
Closed
Closed
Copy link
Labels
clang-tidyclang:dataflowClang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.htmlClang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.htmlfalse-positiveWarning fires when it should notWarning fires when it should not
Description
On clang-tidy at bdb859c, I believe bugprone-unchecked-optional-access has a false-positive.
$ $clang_tidy '-checks=-*,bugprone-unchecked-optional-access' file_name.cpp -- clang++ -x c++ -std=c++17 file_name.cpp
file_name.cpp:19:52: warning: unchecked access to optional value [bugprone-unchecked-optional-access]
return (optional_value != absl::nullopt) ? *optional_value : 0;
Creduce'd repro:
namespace absl {
namespace a {
enum au { av };
template <au> class aw {};
template <au> class ax {};
template <typename> struct ay { static constexpr au az = av; };
template <typename> struct b { static constexpr au az = av; };
} // namespace a
struct nullopt_t {
} nullopt;
template <typename am>
class optional : a::aw<a::ay<am>::az>, a::ax<a::b<am>::az> {
public:
am operator*();
};
template <typename am> bool operator!=(am, nullopt_t);
} // namespace absl
int c(absl::optional<int> optional_value) {
return (optional_value != absl::nullopt) ? *optional_value : 0;
}Note that if the condition is changed to return optional_value ? *optional_value : 0; (and explicit operator bool() const; is added to the optional class above), the diagnostic is not issued.
cc @ymand
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
clang-tidyclang:dataflowClang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.htmlClang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.htmlfalse-positiveWarning fires when it should notWarning fires when it should not