p1.cpp revision eeac7a4bb4bf6b2bf423ec84eabcf179b9d7e4ea
1// RUN: %clang_cc1 -fsyntax-only -verify %s 2 3struct A { 4 unsigned bitX : 4; 5 unsigned bitY : 4; 6 unsigned var; 7 8 void foo(); 9}; 10 11void 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 22void 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 30namespace pr16992 { 31 32template<typename T> struct ABC { 33 int func () { 34 return sizeof T; // expected-error {{expected parentheses around type name in sizeof expression}} 35 } 36}; 37 38ABC<int> qq; 39 40template<typename T> struct ABC2 { 41 int func () { 42 return sizeof T::A; 43 } 44}; 45 46struct QQ { int A; }; 47ABC2<QQ> qq2; 48} 49