[clang] [clang] Add clang::preferred_type attribute for bitfields (PR #69104)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 23 09:06:48 PDT 2023
AaronBallman wrote:
> The changes should also come with a release note, but I'm generally happy with the code. I did have some suggestions for changes to documentation though.
Suggestion for the release note would be something along these lines:
```
- Clang now supports ``[[clang::preferred_type(type-name)]]`` as an attribute
which can be applied to a bit-field. This attribute helps to map a bit-field
back to a particular type that may be better-suited to representing the bit-
field but cannot be used for other reasons and will impact the debug
information generated for the bit-field. This is most useful when mapping a
bit-field of basic integer type back to a ``bool`` or an enumeration type.
e.g.,
.. code-block:: c++
enum E { Apple, Orange, Pear };
struct S {
[[clang::preferred_type(E)]] unsigned FruitKind : 2;
};
When viewing ``S::FruitKind`` in a debugger, it will behave as if the member
was declared as type ``E`` rather than ``unsigned``.
```
https://github.com/llvm/llvm-project/pull/69104
More information about the cfe-commits
mailing list