<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/67662>67662</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-tidy bugprone-branch-clone false-positive with missing include
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zmodem
</td>
</tr>
</table>
<pre>
Consider:
```
$ cat /tmp/a.cc
template <typename T>
struct S {
std::unique_ptr<T[]> contents_;
void f(int capacity) {
if (capacity) {
contents_.reset(new T[capacity]);
} else {
contents_.reset(nullptr);
}
}
};
$ build/bin/clang-tidy /tmp/a.cc -checks=bugprone-branch-clone --
1 warning and 1 error generated.
Error while processing /tmp/a.cc.
/tmp/a.cc:3:3: error: use of undeclared identifier 'std' [clang-diagnostic-error]
3 | std::unique_ptr<T[]> contents_;
| ^
/tmp/a.cc:6:4: warning: if with identical then and else branches [bugprone-branch-clone]
6 | if (capacity) {
| ^
/tmp/a.cc:8:7: note: else branch starts here
8 | } else {
| ^
Found compiler error(s).
```
The "if with identical then and else branches [bugprone-branch-clone]" is obviously not correct.
This seems to be an effect of `std::unique_ptr` not being declared. If I add `include <memory>` the warning goes away.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVF2PqzYQ_TXOywhEbMLHAw_ZzSLd5-77lbEHcGtsapuN0l9fGZJNouaqUlUpIQPOnDlzZjjcezUYxIYc3sjhtONLGK1r_pqsxGnXWXlp3q3xSqIj7EiyE8lu1yK7frZbmoPgAQhtwzQT2vJUiO0o4DRrHhAIew-XGQ2fED4J-9iOfXCLCPAbkPJtewI-yFiNHRej_lzw5xwcYe-fG0fCPkBYE9AE_5Owt0dSAF9WSegJrZQJIPjMhQoXQusHdADVA6HVr04B7vipQ4-B0MrgGSKB76TDidD6u3xMIuUJUHt8AHuBs2gd2_ln7u3mO4zBc3tR5G5RWhLadsoQ2gr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