Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / expr / expr.unary / expr.sizeof / p1.cpp
blobaa76b3a73462458056b020496a06eb5ece322c7b
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
3 struct A {
4 unsigned bitX : 4;
5 unsigned bitY : 4;
6 unsigned var;
8 void foo();
9 };
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}}
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}}
30 namespace pr16992 {
32 template<typename T> struct ABC {
33 int func () {
34 return sizeof T; // expected-error {{expected parentheses around type name in sizeof expression}}
38 ABC<int> qq;
40 template<typename T> struct ABC2 {
41 int func () {
42 return sizeof T::A;
46 struct QQ { int A; };
47 ABC2<QQ> qq2;