Open
Description
While working on #107238, I noticed that these attributes (and their "or null" counterparts) are DeclOrTypeAttr
attributes which are intended to be C-only. However, there's no code in processTypeAttrs()
in SemaType.cpp
to handle these attributes, and so it wasn't clear that we had the right restrictions for checking the language mode.
This led me to discover some odd inconsistencies with how we handle the type form of the attribute: https://godbolt.org/z/WhjYE1xTY
#define __counted_by(f) __attribute__((counted_by(f)))
int foo;
int y = (int __counted_by(foo))12;
int * __counted_by(foo) ptr;
gives:
<source>:4:14: warning: 'counted_by' attribute ignored when parsing type [-Wignored-attributes]
4 | int y = (int __counted_by(foo))12;
| ^~~~~~~~~~~~~~~~~
<source>:1:40: note: expanded from macro '__counted_by'
1 | #define __counted_by(f) __attribute__((counted_by(f)))
| ^~~~~~~~~~~~~
<source>:6:7: error: 'counted_by' attribute only applies to non-static data members
6 | int * __counted_by(foo) ptr;
| ^
<source>:1:40: note: expanded from macro '__counted_by'
1 | #define __counted_by(f) __attribute__((counted_by(f)))
| ^
1 warning and 1 error generated.
Compiler returned: 1