| Issue |
163831
|
| Summary |
clang-tidy bugprone-unchecked-optional-access should have an option to assume '.value()' is safe
|
| Labels |
clang-tidy
|
| Assignees |
|
| Reporter |
dunhor
|
The [docs](https://clang.llvm.org/extra/clang-tidy/checks/bugprone/unchecked-optional-access.html) for `bugprone-unchecked-optional-access` say:
> Given that value() has well-defined behavior (either throwing an exception or terminating the program), why treat it the same as operator*() which causes undefined behavior (UB)? That is, why is it considered unsafe to access an optional with value(), if it’s not provably populated with a value? For that matter, why is CHECK() followed by operator*() any better than value(), given that they are semantically equivalent (on configurations that disable exceptions)?
> The answer is that we assume most users do not realize the difference between value() and operator*().
That may be a fair assessment for the general case, however it's not unreasonable to assume that some projects _do_ use `.value()` in a safe way. It would be nice if there was an option to enable this check only for `operator*`, similar to how there's similar types of options for most other checks as this allows for this check to remain enabled in more projects.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs