<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/107249>107249</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Inconsistent behavior with counted/sizedby attributes in type positions
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:frontend
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          AaronBallman
      </td>
    </tr>
</table>

<pre>
    While working on https://github.com/llvm/llvm-project/pull/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
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVctu47gS_Rp6U4ghUZIVL7RwHsbt1V1MgKBXBkWWRPZQLIGk7HYv5tsHlJw4SWcwD8xmBEE2H8VTp6pYR4RgeofYsOqOVQ8rMUVNvtkJT-5OWDsIt2pJnZtnbSzCifyvxvVADnSMY2DFjvE94_veRD21a0kD43trjy8_N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