<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/81419>81419</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-tidy check bugprone-unused-local-non-trivial-variable should honor [[maybe_unused]]
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
pkl97
</td>
</tr>
</table>
<pre>
In clang 18.1.0-rc2 clang-tidy check bugprone-unused-local-non-trivial-variable emits a warning even if the variable in question is marked [[maybe_unused]].
A simple example:
```c++
#include <string>
int main()
{
const std::string s1; // warning is ok
[[maybe_unused]] const std::string s2; // no warning expected
return 0;
}
```
Both lines trigger an "unused local variable" warning.
Honestly I think this defeats the purpose of this attribute and makes it unnecessarily hard to write platform independent code.
Flagging with NOLINT() is always a possibility however a non-clang compiler will still require the [[maybe_unused]] attribute to suppress the warning. And the presence of the attribute indicates that the developer has thought about the variable being unused in the first place.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVE2P4zYM_TXKhUhgy7GTHHyYaRp0gGJ76b2QJcZmI0teiUo2_76QnZnMFpjTAoIEi-bHe0-kipF6h9iK-lXUx5VKPPjQThd72K06b-7tmwNtleuh3G_KTbEOWi4XayZzBz2gvkCX-il4h-vkUkSztl4ru3berTnQlZRdX1Ug1VkEHIkjKLip4Mj1gFd0QGfgAeHjJ3LwPWFk8g4owqjCBQ3MNb6O6t7hP0siUR9FfdyI4iiKl2V_gUjjlBP9UPkU1cMgmmJZWsjXvJZbWZHTNhkEUf0WOZDrRfX754jkGEZFTsi9kIeHZffwBwDQ3kWGyCbnql6WIBBLUb2CkCchTx9oKYK_PD2_QvRVSPkppPNPDn9MqBnNI3BATsFBIap3kLvj_zhYPl89D2DJYQQO1PcYQDkQUi61wCzjhypCyveMPzH-h3cY2d7hDXggd8l7BINnVBxnXacUJh8R_HmxKeZAXWIE5QyM6oIRiCE5hxpjVIHsHQYVDLCHWyBGmKzisw8jkDM4oTPoGLQ3-CjlZFXfZy5uxAN8--vPt29_L4JlzpW9qXt-dZOPkTqyxHcY_A2vGTLkh7o8cu3HiSwGuJG1EDnvAb8nCjgj-VKwJyT2ENM0BYwL-HfK4MWZhY2AEZ1-0IGfXMkZ0oqzHIPi2WjwitZPGGBQ-dqnfmBQnU_8c8t0mNE_hCM3G88UImfqNG5Wpq3MoTqoFbblrtg1TbPbl6uhRSlrvW0OZaO2XXdoynMjJXb7Tp_roj6oFbWykNtClmVZ11VRbrZNV-6boq63cl815V5sCxwV2Y2113HjQ7-iGBO2-3JbHlZWdWjjPGCkfE4OIWUeOKHNTusu9VFsC0uR4zMME1tsf2XaxMEna2DwzocvxVulYNuBeYq52-bu6omH1G20H4U85Xoex3oK_l_ULORpxhiFPM0w_wsAAP__u4K8qQ">