File tree 3 files changed +58
-0
lines changed
regression/ansi-c/bitfields2
3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <limits.h>
2
+
3
+ #define CONCAT (a , b ) a##b
4
+ #define CONCAT2 (a , b ) CONCAT(a, b)
5
+
6
+ #define STATIC_ASSERT (condition ) \
7
+ int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
8
+
9
+ #if CHAR_BIT == 8
10
+ struct bits
11
+ {
12
+ char a : 4 ;
13
+ char b : 4 ;
14
+ char c : 4 ;
15
+ char d : 4 ;
16
+ char : 0 ; // this is ok: no declarator
17
+ int i ;
18
+ };
19
+
20
+ STATIC_ASSERT (sizeof (struct bits ) == 2 * sizeof (int ));
21
+
22
+ # pragma pack(1)
23
+ struct packed_bits
24
+ {
25
+ char a : 4 ;
26
+ char b : 4 ;
27
+ char c : 4 ;
28
+ char d : 4 ;
29
+ char x : 0 ; // this is not permitted
30
+ int i ;
31
+ };
32
+ # pragma pack()
33
+
34
+ STATIC_ASSERT (sizeof (struct packed_bits ) == sizeof (int ) + 2 );
35
+ #endif
36
+
37
+ int main ()
38
+ {
39
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+
4
+ zero-width bit-field with declarator not permitted$
5
+ CONVERSION ERROR
6
+ ^EXIT=(64|1)$
7
+ ^SIGNAL=0$
8
+ --
9
+ ^warning: ignoring
Original file line number Diff line number Diff line change @@ -964,6 +964,16 @@ void c_typecheck_baset::typecheck_compound_body(
964
964
throw 0 ;
965
965
}
966
966
967
+ if (
968
+ new_component.type ().id () == ID_c_bit_field &&
969
+ to_c_bit_field_type (new_component.type ()).get_width () == 0 &&
970
+ !new_component.get_name ().empty ())
971
+ {
972
+ throw invalid_source_file_exceptiont{
973
+ " zero-width bit-field with declarator not permitted" ,
974
+ source_location};
975
+ }
976
+
967
977
components.push_back (new_component);
968
978
}
969
979
}
You can’t perform that action at this time.
0 commit comments