Issue 151287
Summary [clang-tidy] False positive bugprone-unchecked-optional-access with call to non-const member
Labels clang-tidy
Assignees
Reporter chrchr-github
    ~~~c++
#include <optional>

struct S {    
    int f();
    void g() { ++i; }
 std::optional<int> o;
    int i{};
};

int S::f() {
    if (!o.has_value())
        return 0;
    g();
    return *o;
}
~~~
~~~
<source>:14:13: warning: unchecked access to optional value [bugprone-unchecked-optional-access]
   14 |     return *o;
      | ^
1 warning generated.
~~~
https://godbolt.org/z/66EYve5Tj
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to