Clang Project

clang_source_code/test/CXX/conv/conv.prom/p5.cpp
1// RUN: %clang_cc1 -verify %s
2// expected-no-diagnostics
3
4// A prvalue for an integral bit-field can be converted to a prvalue of type
5// int if int can represent all the values of the bit-field
6struct X { long long e : 1; };
7static_assert(sizeof(+X().e) == sizeof(int), "");
8static_assert(sizeof(X().e + 1) == sizeof(int), "");
9static_assert(sizeof(true ? X().e : 0) == sizeof(int), "");
10
11enum E : long long { a = __LONG_LONG_MAX__ };
12static_assert(sizeof(E{}) == sizeof(long long), "");
13
14// If the bit-field has an enumerated type, it is treated as any other value of
15// that [enumerated] type for promotion purposes.
16struct Y { E e : 1; };
17static_assert(sizeof(+Y().e) == sizeof(long long), "");
18static_assert(sizeof(Y().e + 1) == sizeof(long long), "");
19static_assert(sizeof(true ? Y().e : 0) == sizeof(long long), "");
20