xref: /aosp_15_r20/external/clang/test/SemaCXX/bitfield.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 %s -verify
2*67e74705SXin Li 
3*67e74705SXin Li // expected-no-diagnostics
4*67e74705SXin Li 
5*67e74705SXin Li namespace PromotionVersusMutation {
6*67e74705SXin Li   typedef unsigned Unsigned;
7*67e74705SXin Li   typedef signed Signed;
8*67e74705SXin Li 
9*67e74705SXin Li   struct T { unsigned n : 2; } t;
10*67e74705SXin Li 
11*67e74705SXin Li   typedef __typeof__(t.n) Unsigned; // Bitfield is unsigned
12*67e74705SXin Li   typedef __typeof__(+t.n) Signed;  // ... but promotes to signed.
13*67e74705SXin Li 
14*67e74705SXin Li   typedef __typeof__(t.n + 0) Signed; // Arithmetic promotes.
15*67e74705SXin Li 
16*67e74705SXin Li   typedef __typeof__(t.n = 0) Unsigned;  // Assignment produces an lvalue...
17*67e74705SXin Li   typedef __typeof__(t.n += 0) Unsigned;
18*67e74705SXin Li   typedef __typeof__(t.n *= 0) Unsigned;
19*67e74705SXin Li   typedef __typeof__(+(t.n = 0)) Signed;  // ... which is a bit-field.
20*67e74705SXin Li   typedef __typeof__(+(t.n += 0)) Signed;
21*67e74705SXin Li   typedef __typeof__(+(t.n *= 0)) Signed;
22*67e74705SXin Li 
23*67e74705SXin Li   typedef __typeof__(++t.n) Unsigned; // Increment is equivalent to compound-assignment.
24*67e74705SXin Li   typedef __typeof__(--t.n) Unsigned;
25*67e74705SXin Li   typedef __typeof__(+(++t.n)) Signed;
26*67e74705SXin Li   typedef __typeof__(+(--t.n)) Signed;
27*67e74705SXin Li 
28*67e74705SXin Li   typedef __typeof__(t.n++) Unsigned; // Post-increment's result has the type
29*67e74705SXin Li   typedef __typeof__(t.n--) Unsigned; // of the operand...
30*67e74705SXin Li   typedef __typeof__(+(t.n++)) Unsigned; // ... and is not a bit-field (because
31*67e74705SXin Li   typedef __typeof__(+(t.n--)) Unsigned; // it's not a glvalue).
32*67e74705SXin Li }
33