p1.cpp 1.5 KB

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