<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62693>62693</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
bugprone-branch-clone false positive on template instantiations
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
njames93
</td>
</tr>
</table>
<pre>
The bugprone-branch-clone check currently emits warnings when template instantiations can result in a branch clone
Take this example here
```cpp
class Object {
public:
template <typename T>
bool ConvertableTo() const;
template <typename T>
void Handle();
};
template <typename T>
void update(Object &a) {
if (a.ConvertableTo<char *>()) {
a.Handle<char *>();
} else {
a.Handle<T>();
}
}
template <typename T>
void update2(Object &a) {
if (a.ConvertableTo<char *>()) {
a.Handle<char *>();
} else {
a.Handle<T>();
}
}
void foo(Object &a) {
update<int>(a);
update2<char *>(a);
}
```
In this code, there is no warning emitted from `update`, which has exactly the same code as `update2`. However due to the instantiation of `update2` with type `char *`, A warning is emitted on the line containing the `if` statement in `update2`.
https://godbolt.org/z/Pefv9E6Mv
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VMGOozgQ_RpzKXVkTCDhwKE7PdHsYbV7yA8UpgieMTbCRbK9X78yJJ1O1LszGmmjCETJ7_m9suthCOboiCqRv4j8NcGJOz9W7hv2FMosqX3zVh06gno6DqN39FSP6HT3pK13BLoj_R30NI7k2L4B9YYDnHF0xh0DnDtywNQPFpnAuMDo2CAb7wJodDBSmCyDcYCwEMNMLOSrkM_L84DfCbgzAegv7AdL0NF4XVHI5a-HYaloiyHAH_U30gxi87JUAWCYamu0yJ7fKzdlItvx20AOe4KDyL7cltTeW9h5d6KRsbZ08EJthSpBexdYZC8flf4M58mbBr6iaywtTDeOzesD3w-4ZqppaJAj1dWyKjDq-2gdTAtCbXF1byTb6Q5HEOo5Ui5iHpHxh6uL3s8AV8UgNq9ANtB_4g-fAAEi9taDX2qA-n868HPWFwe_5v7frM_eWu9_4Oty_NnOOF7Y8Y7-2p1H_fh48-7Hafn8zS1zp31DQu2A4-CBCeD8dcbniWdqoB19D6KQF0GFjIBzZ3QHHc6jq2NAcEcQ4ilGTsBwgyhRyBV89Wc60QjNRMB-Xn4XG-DbewicDXcQL0esv5tc9n9-lxnT46LUu5nWmphf3jGaeUWsiUKaNpIGRqae3BxN9xI_HlLHPIQYKWov1P7om9pbXvnxKNT-b6H2f1J7Kr8Uv5-SpsqaMisxoSottllZbPM0T7qqTHXdkGzadVZnqdzKptBym-ftNm3bct0kplJSZTJPM1nKNM9XJPOsTMvNRqeo1uVarCX1aOzK2lMf905MCBNVhSrKLLFYkw1zuiulLbrjE5vmTSgV036sIuipno5BrKU1gcONhg1bqj7P_RbjXR98MGxONLf085RPptFWD20y3E31SvteqH3c7fJ6GkYfL7pQ-9lBEGo_m_gnAAD__xv09oY">