<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/56296>56296</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
bugprone-unchecked-optional-access crashes with "Assertion `Cond != nullptr' failed"
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
gburgessiv
</td>
</tr>
</table>
<pre>
When evaluating this check on Chromium, I noted a few crashes. A creduce'd test-case for one of them is below; it repros on 206a6037a093a73d928a60c3012593f921a4f639:
```cpp
typedef int a;
namespace {
namespace base {
template <typename> class Optional {
public:
operator bool();
};
Optional<a> b(char *);
namespace {
using af = char;
af ag() {
for (;;)
;
char ah[4];
Optional ai = b(ah);
!ai;
}
} // namespace
} // namespace base
} // namespace
```
```
$ clang-tidy '-checks=-*,bugprone-unchecked-optional-access' repro.cpp -- clang -c -std=c++17 -x c++ repro.cpp
clang-tidy: /usr/local/google/home/gbiv/llvm/main/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:100: void clang::dataflow::TerminatorVisitor::VisitForStmt(const clang::ForStmt *): Assertion `Cond != nullptr' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /usr/local/google/home/gbiv/llvm/main/build/release/bin/clang-tidy -checks=-*,bugprone-unchecked-optional-access repro.cpp -- clang -c -std=c++17 -x c++ repro.cpp
1. <eof> parser at end of file
2. ASTMatcher: Processing 'bugprone-unchecked-optional-access' against:
FunctionDecl (anonymous namespace)::base::(anonymous namespace)::ag : <repro.cpp:11:1, line:17:1>
--- Bound Nodes Begin ---
T - { BuiltinType : int }
fun - { FunctionDecl (anonymous namespace)::base::(anonymous namespace)::ag : <repro.cpp:11:1, line:17:1> }
--- Bound Nodes End ---
```
cc @ymand
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/e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