1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
2 | |
3 | struct A { |
4 | unsigned bitX : 4; |
5 | unsigned bitY : 4; |
6 | unsigned var; |
7 | |
8 | void foo(); |
9 | }; |
10 | |
11 | void test(A *a) { |
12 | int x; |
13 | x = sizeof(a->bitX); // expected-error {{invalid application of 'sizeof' to bit-field}} |
14 | x = sizeof((unsigned) a->bitX); |
15 | x = sizeof(a->foo(), a->bitX); // expected-error {{invalid application of 'sizeof' to bit-field}} |
16 | x = sizeof(a->var ? a->bitX : a->bitY); // expected-error {{invalid application of 'sizeof' to bit-field}} |
17 | x = sizeof(a->var ? a->bitX : a->bitX); // expected-error {{invalid application of 'sizeof' to bit-field}} |
18 | x = sizeof(a->bitX = 3); // expected-error {{invalid application of 'sizeof' to bit-field}} |
19 | x = sizeof(a->bitY += 3); // expected-error {{invalid application of 'sizeof' to bit-field}} |
20 | } |
21 | |
22 | void test2() { |
23 | int x; |
24 | x = sizeof(void); // expected-error {{invalid application of 'sizeof' to an incomplete type 'void'}} |
25 | x = sizeof(int()); // expected-error {{invalid application of 'sizeof' to a function type}} |
26 | x = sizeof(test2()); // expected-error {{invalid application of 'sizeof' to an incomplete type 'void'}} |
27 | x = sizeof(test2); // expected-error {{invalid application of 'sizeof' to a function type}} |
28 | } |
29 | |
30 | namespace pr16992 { |
31 | |
32 | template<typename T> struct ABC { |
33 | int func () { |
34 | return sizeof T; // expected-error {{expected parentheses around type name in sizeof expression}} |
35 | } |
36 | }; |
37 | |
38 | ABC<int> qq; |
39 | |
40 | template<typename T> struct ABC2 { |
41 | int func () { |
42 | return sizeof T::A; |
43 | } |
44 | }; |
45 | |
46 | struct QQ { int A; }; |
47 | ABC2<QQ> qq2; |
48 | } |
49 | |