Skip to content

Commit ee8d32d

Browse files
committed
More bitfield tests
1 parent c5f20a8 commit ee8d32d

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

clang/test/AST/Interp/builtin-bit-cast.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,5 +761,41 @@ namespace Bitfields {
761761
constexpr CharStruct CS = __builtin_bit_cast(CharStruct, B); // ref-error {{must be initialized by a constant expression}} \
762762
// ref-note {{bit_cast involving bit-field is not yet supported}} \
763763
// ref-note {{declared here}}
764-
static_assert(CS.v == 155);} // ref-error {{not an integral constant expression}} \
765-
// ref-note {{initializer of 'CS' is not a constant expression}}
764+
static_assert(CS.v == 155); // ref-error {{not an integral constant expression}} \
765+
// ref-note {{initializer of 'CS' is not a constant expression}}
766+
767+
768+
struct I3 {
769+
int a;
770+
int b : 10;
771+
int c;
772+
};
773+
774+
struct I32 {
775+
int a;
776+
int b;
777+
int c;
778+
};
779+
780+
constexpr I3 i3 {5, 10, 15};
781+
constexpr I32 i32 = __builtin_bit_cast(I32, i3); // ref-error {{must be initialized by a constant expression}} \
782+
// ref-note {{bit_cast involving bit-field is not yet supported}} \
783+
// expected-error {{must be initialized by a constant expression}} \
784+
// expected-note {{indeterminate value can only initialize an object of type 'unsigned char'}}
785+
786+
struct I33 {
787+
int a;
788+
unsigned char b;
789+
int c;
790+
};
791+
792+
constexpr I33 i33 = __builtin_bit_cast(I33, i3); // ref-error {{must be initialized by a constant expression}} \
793+
// ref-note {{bit_cast involving bit-field is not yet supported}} \
794+
// ref-note 3{{declared here}}
795+
static_assert(i33.a == 5, ""); // ref-error {{not an integral constant expression}} \
796+
// ref-note {{initializer of 'i33' is not a constant expression}}
797+
static_assert(i33.b == 10, ""); // ref-error {{not an integral constant expression}} \
798+
// ref-note {{initializer of 'i33' is not a constant expression}}
799+
static_assert(i33.c == 15, ""); // ref-error {{not an integral constant expression}} \
800+
// ref-note {{initializer of 'i33' is not a constant expression}}
801+
}

0 commit comments

Comments
 (0)