<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/98836>98836</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Confusing warning message trying to use `counted_by` in C++
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang,
clang:diagnostics
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Kmeakin
</td>
</tr>
</table>
<pre>
This code generates a warning when compiled in C++ mode, but not in C mode:
```c++
#include <stddef.h>
#include <stdint.h>
struct slice {
size_t len;
uint32_t* data __attribute__((counted_by(len)));
};
```
```
<source>:6:35: warning: 'counted_by' attribute ignored [-Wignored-attributes]
6 | uint32_t* data __attribute__((counted_by(len)));
| ^
```
This warning could be improved by telling the user that `counted_by` is only allowed in C mode, and will be ignored in C++ mode. The [documentation]( https://clang.llvm.org/docs/AttributeReference.html#counted-by) could also be improved to state this explicitly.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVE-P6jYQ_zSTywgUxiEhhxxY9nHprXpSj8ixZxO3jo3iyW7pp6-SDSzvqe2pKAJ7Rvw8vz-xTsl1gbmB_QvsXzM9SR_H5peB9R8uZG20t-Z77xKaaBk7Djxq4YQaP_QYXOjwo-eAJg5X59miC3gCegF6wSFaBjphOwmGKEvrs6iOkL9CfoQy_3zM51_WKikXjJ8sI6hTEmv5bduD-vYvbRfkub18JxknI5i8M4xQrciIiMn9xRdBzwHUU3lyQRRdBOiIVovGy0WLjK6dhC8XoAPQwcQpCNtLewM6zABUr88dCarXr_Wd3PNcPxfVKcVpNDyPr44lqKPagzrexZ2XQNXzwRU-5kLXhTiyRdi_bH5bN5tHO8H-9YtgiVCd_ieauHxmPNh_-w-2S3DuOTFx8hZbRjdcx_jOFtsbCns_N6VnnBKPKL0WnBPxNUSZo0sYg7-h9j5-rCl75EsHix_O-wV7VeSnGG7xe8-zTDaaaeAgWlwMsz50wF7kmuZM0hnobLwO3db792Ebxw7obKNJQOfjXaZf-Y1HDoa3vQweSK2jbma96pWm9in-wFUiJtHCKLMm_OfVO-PE37aY2UbZWtU642ZXUV4f6koVWd-Yqt0Vem_asi6ptOWOy7auCnMolaXSlJlrKKcir3YF5QXtaMuKS7NrTVHsqFDVHoqcB-38g07mUpq4qQ8HVWZet-zT8uITLbSBCOj02KmjdboLMYmbJaD5fhibGWvTTl2CIvcuSfpCFyeem1MMb1NarobV-oFT0h2jjLfF7Dh7_Q8uP0zLptE3P_rSOemndmviAHSeT1x_Ntcx_s5GgM4LudmrT37vDf0dAAD__zn7f-s">