<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57252>57252</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
bugprone-unchecked-optional-access false-positive with structured bindings
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
gburgessiv
</td>
</tr>
</table>
<pre>
On clang-tidy at bdb859c9a75f0e574ac877c4ca277edcc6db4e46, 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:61:14: warning: unchecked access to optional value [bugprone-unchecked-optional-access]
content ? *content : "";
^
```
Creduce'd repro:
```
namespace {
namespace {
template <class a, a b> struct c { static const a value = b; };
} // namespace
} // namespace
typedef int d;
namespace std {
namespace {
template <class a> struct al : c<bool, __is_final(a)> {};
} // namespace
inline namespace am {
template <class> struct tuple_size;
template <d, class> struct tuple_element;
template <class...> class ao;
template <class... a> struct tuple_size<ao<a...>> : c<d, sizeof...(a)> {};
template <class...> struct ap;
template <d aq, class... ar> struct tuple_element<aq, ap<ar...>> {
typedef __type_pack_element<aq, ar...> type;
};
template <d aq, class... a> struct tuple_element<aq, ao<a...>> {
typedef typename tuple_element<aq, ap<a...>>::type type;
};
template <class, class, class> class at;
typedef at<char, char, char> au;
template <class...> class ao {};
template <d aq, class... a>
typename tuple_element<aq, ao<a...>>::type get(ao<a...>) {}
struct av {};
template <class a, bool = al<a>::value> struct aw { aw(av); };
template <class ax, class ay> class az : aw<ax>, aw<ay, 1> {
public:
using ba = aw<ax>;
using bb = aw<ay, 1>;
template <class bc, class bd> az(bc be, bd bf) : ba(be), bb(bf) {}
};
template <class bi, class, class bj> class at {
public:
typedef bj bk;
struct bl {};
az<bl, bk> bm;
at(bi *) : bm(av(), av()) {}
};
} // namespace am
namespace bv {
enum bw { bx };
template <bw> class by {};
template <bw> class bz {};
template <typename> struct ca { static constexpr bw cb = bx; };
template <typename> struct cc { static constexpr bw cb = bx; };
} // namespace bv
template <typename bp>
class optional {
public:
bp operator*();
operator bool();
};
namespace {
ao<optional<const char *>, int> get_opt();
void ch() {
auto [content, ck] = get_opt();
content ? *content : "";
}
} // namespace
} // namespace std
```
Note that changing the last function to:
```
void ch() {
auto [content, ck] = get_opt();
auto c2 = content;
c2 ? *c2 : "";
}
```
Results in clang-tidy not emitting a warning.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytV19zujoQ_TT4sqOjICIPPLTaztyXe2fuF3CSEDQtApcEq_30dxP-RUVqZ34dq0A2m7NnTzYLzeNL9E8GLCXZfqpEfAGigMZ07YcsJIGfzLkfLAlbBwFbMuIGAY8ZW8V0yZcrx93AX0B5KviJA632RZlnfFpl7MDZJ4-neaFEnpF0ShjjUsKBSCCQkFTyaZFLocSJz5z51pm_NN-refOpb90l4L9BtzPoHDeYGu_S8bZTx0WTzc8L4yxIRMp3GTnyGSsKmE7rmB33FT8wPQNrL6WK0Xdzu7iZWOO6fuS9rBb4tVjiF3yRMhPoFy87ONCEr3JogcGJpBUHx399Ar2_rZcFYHmmeKbA8d6Ripf-9gVvXf3xXltb68_x34b5Nd-bkscV40hSDCVHMOhuJCk6blkQhuiD14ePFD8WKVH4xNsg0xg90XIhQB3vDaQqK6aAaXu8IUowHZtUaNAw42216StabLug8BrjfMcPdEv-NKIuBY95AgJ5ijtPPWJM968D6SPATGryGQ7SPE91iLudkLtEYP4cd41Bh9pcu3sqEJGlIuP9UyDHESwWElUVKEopvnm3im0ea2jDc3jKj6iiwWlmxmw205Oa6PNRwyt2bEwbPXFDal-GkoY3g0zb5IkefMjZI1htJorhuIH814Vu8JWPCdjUttrVhpQW1KDbVa2cdjt9tcMUfd7Pb6YaYzvnTyL8GeAtlff49K8W0WiInQe94z2zVZ7DXAupU5QtrUYllpwaRPrRh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