[PATCH] D23035: [Support] Add LLVM_BITFIELD_WIDTH and LLVM_CHECKED_BITFIELD_ASSIGN macros.

Chandler Carruth via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 1 17:19:45 PDT 2016


chandlerc added a comment.

In https://reviews.llvm.org/D23035#502855, @rnk wrote:

> Do we really need this macro? I think we should just encourage this pattern:
>
>   class Foo {
>   private:
>     unsigned Data : 12;
>     ...
>   public:
>     MyEnum getData() { return MyEnum(Data); }
>     void setData(MyEnum V) { Data = V; assert(Data == V && "bitfield too small"); }
>     ...
>   };
>
>
> Sure, it's not compile time checked, but I hope we have tests exercising the use of all enums in our data structures.


I don't feel strongly about whether we should package this up in a macro and use the macro to implement such setData methods or not.

If folks want the macro, I'm much happier with the simpler incarnation.


https://reviews.llvm.org/D23035





More information about the llvm-commits mailing list