On Mon, Aug 05, 2024 at 04:46:09PM +0000, Qing Zhao wrote: > So, you want me to add counted_by test-suite for C23? (Which should be > supported) > Okay, but I will do it in another separate patch since this patch is for C++. > > The C++11/C23 standard attributes are more strict on where they can appear > > depending on what it appertains to, as it applies to declarations, I think > > it needs to go before the [] or at the start of the declaration, so > > [[gnu::counted_by (count)]] int field[]; > > or > > int field [[gnu::counted_by (count)]] []; > > but I could be wrong, better test it… > For C++11, as I just checked: > > int field[] [[gnu::counted_by (count)]]; > > Is fine.
What do you mean by fine, that it emits the sorry? Yes, but the question is if it will be ok when the support is added. struct S { int s; int f[] [[gnu::counted_by (s)]]; }; with -std=c23 certainly emits test.c:3:3: warning: ‘counted_by’ attribute does not apply to types [-Wattributes] 3 | int f[] [[gnu::counted_by (s)]]; | ^~~ while it is fine for int f [[gnu::counted_by (s)]] []; and [[gnu::counted_by (s)]] int f[]; So, I'd use that in the C++ testcase too... Jakub