exprs3.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Integer literals
  2. const char Ch1 = 'a';
  3. const signed char Ch2 = 'b';
  4. const unsigned char Ch3 = 'c';
  5. const wchar_t Ch4 = L'd';
  6. const signed wchar_t Ch5 = L'e';
  7. const unsigned wchar_t Ch6 = L'f';
  8. const short C1 = 12;
  9. const unsigned short C2 = 13;
  10. const int C3 = 12;
  11. const unsigned int C4 = 13;
  12. const long C5 = 22;
  13. const unsigned long C6 = 23;
  14. const long long C7 = 66;
  15. const unsigned long long C8 = 67;
  16. // String literals
  17. const char str1[] = "ABCD";
  18. const char str2[] = "ABCD" "0123";
  19. const wchar_t wstr1[] = L"DEF";
  20. const wchar_t wstr2[] = L"DEF" L"123";
  21. // Boolean literals
  22. const bool bval1 = true;
  23. const bool bval2 = false;
  24. // Floating Literals
  25. const float F1 = 12.2F;
  26. const double F2 = 1E4;
  27. const long double F3 = 1.2E-3L;
  28. // nullptr literal
  29. const void *vptr = nullptr;
  30. int glb_1[4] = { 10, 20, 30, 40 };
  31. struct S1 {
  32. int a;
  33. int b[3];
  34. };
  35. struct S2 {
  36. int c;
  37. S1 d;
  38. };
  39. S2 glb_2 = { 22, .d.a = 44, .d.b[0] = 55, .d.b[1] = 66 };
  40. void testNewThrowDelete() {
  41. throw;
  42. char *p = new char[10];
  43. delete[] p;
  44. }
  45. int testArrayElement(int *x, int n) {
  46. return x[n];
  47. }
  48. int testTernaryOp(int c, int x, int y) {
  49. return c ? x : y;
  50. }
  51. S1 &testConstCast(const S1 &x) {
  52. return const_cast<S1&>(x);
  53. }
  54. S1 &testStaticCast(S1 &x) {
  55. return static_cast<S1&>(x);
  56. }
  57. S1 &testReinterpretCast(S1 &x) {
  58. return reinterpret_cast<S1&>(x);
  59. }
  60. S1 &testDynamicCast(S1 &x) {
  61. return dynamic_cast<S1&>(x);
  62. }
  63. int testScalarInit(int x) {
  64. return int(x);
  65. }
  66. struct S {
  67. float f;
  68. double d;
  69. };
  70. struct T {
  71. int i;
  72. struct S s[10];
  73. };
  74. void testOffsetOf() {
  75. __builtin_offsetof(struct T, s[2].d);
  76. }
  77. int testDefaultArg(int a = 2*2) {
  78. return a;
  79. }
  80. template <typename T> // T has TemplateTypeParmType
  81. void testTemplateTypeParmType(int i);
  82. void useTemplateType() {
  83. testTemplateTypeParmType<char>(4);
  84. }
  85. const bool ExpressionTrait = __is_lvalue_expr(1);
  86. const unsigned ArrayRank = __array_rank(int[10][20]);
  87. const unsigned ArrayExtent = __array_extent(int[10][20], 1);