expressions.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. void test1() {
  3. if (sizeof (int){ 1}) {} // sizeof compound literal
  4. if (sizeof (int)) {} // sizeof type
  5. (void)(int)4; // cast.
  6. (void)(int){4}; // compound literal.
  7. int A = (struct{ int a;}){ 1}.a;
  8. }
  9. int test2(int a, int b) {
  10. return a ? (void)a,b : a;
  11. }
  12. int test3(int a, int b, int c) {
  13. return a = b = c;
  14. }
  15. int test4() {
  16. test4();
  17. return 0;
  18. }
  19. struct X0 { struct { struct { int c[10][9]; } b; } a; };
  20. int test_offsetof() {
  21. (void)__builtin_offsetof(struct X0, a.b.c[4][5]);
  22. return 0;
  23. }
  24. void test_sizeof(){
  25. int arr[10];
  26. (void)sizeof arr[0];
  27. (void)sizeof(arr[0]);
  28. (void)sizeof(arr)[0];
  29. }
  30. // PR3418
  31. int test_leading_extension() {
  32. __extension__ (*(char*)0) = 1; // expected-warning {{indirection of non-volatile null pointer}} \
  33. // expected-note {{consider using __builtin_trap}}
  34. return 0;
  35. }
  36. // PR3972
  37. int test5(int);
  38. int test6(void) {
  39. return test5( // expected-note {{to match}}
  40. test5(1)
  41. ; // expected-error {{expected ')'}}
  42. }
  43. // PR8394
  44. void test7() {
  45. ({} // expected-note {{to match}}
  46. ; // expected-error {{expected ')'}}
  47. }
  48. // PR16992
  49. struct pr16992 { int x; };
  50. void func_16992 () {
  51. int x1 = sizeof int; // expected-error {{expected parentheses around type name in sizeof expression}}
  52. int x2 = sizeof struct pr16992; // expected-error {{expected parentheses around type name in sizeof expression}}
  53. int x3 = __alignof int; // expected-error {{expected parentheses around type name in __alignof expression}}
  54. int x4 = _Alignof int; // expected-error {{expected parentheses around type name in _Alignof expression}}
  55. }
  56. void callee(double, double);
  57. void test8() {
  58. callee(foobar, // expected-error {{use of undeclared identifier 'foobar'}}
  59. fizbin); // expected-error {{use of undeclared identifier 'fizbin'}}
  60. }