ms-if-exists.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -Wmicrosoft -verify -fms-extensions
  2. class MayExist {
  3. private:
  4. typedef int Type;
  5. };
  6. void test_if_exists_stmts() {
  7. int b = 0;
  8. __if_exists(MayExist::Type) {
  9. b++;
  10. b++;
  11. }
  12. __if_exists(MayExist::Type_not) {
  13. this will not compile.
  14. }
  15. __if_not_exists(MayExist::Type) {
  16. this will not compile.
  17. }
  18. __if_not_exists(MayExist::Type_not) {
  19. b++;
  20. b++;
  21. }
  22. }
  23. int if_exists_creates_no_scope() {
  24. __if_exists(MayExist::Type) {
  25. int x; // 'x' is declared in the parent scope.
  26. }
  27. __if_not_exists(MayExist::Type_not) {
  28. x++;
  29. }
  30. return x;
  31. }
  32. __if_exists(MayExist::Type) {
  33. int var23;
  34. }
  35. __if_exists(MayExist::Type_not) {
  36. this will not compile.
  37. }
  38. __if_not_exists(MayExist::Type) {
  39. this will not compile.
  40. }
  41. __if_not_exists(MayExist::Type_not) {
  42. int var244;
  43. }
  44. void test_if_exists_init_list() {
  45. int array1[] = {
  46. 0,
  47. __if_exists(MayExist::Type) {2, }
  48. 3
  49. };
  50. int array2[] = {
  51. 0,
  52. __if_exists(MayExist::Type_not) { this will not compile }
  53. 3
  54. };
  55. int array3[] = {
  56. 0,
  57. __if_not_exists(MayExist::Type_not) {2, }
  58. 3
  59. };
  60. int array4[] = {
  61. 0,
  62. __if_not_exists(MayExist::Type) { this will not compile }
  63. 3
  64. };
  65. }
  66. class IfExistsClassScope {
  67. __if_exists(MayExist::Type) {
  68. // __if_exists, __if_not_exists can nest
  69. __if_not_exists(MayExist::Type_not) {
  70. int var123;
  71. }
  72. int var23;
  73. }
  74. __if_exists(MayExist::Type_not) {
  75. this will not compile.
  76. }
  77. __if_not_exists(MayExist::Type) {
  78. this will not compile.
  79. }
  80. __if_not_exists(MayExist::Type_not) {
  81. int var244;
  82. }
  83. };
  84. void test_nested_if_exists() {
  85. __if_exists(MayExist::Type) {
  86. int x = 42;
  87. __if_not_exists(MayExist::Type_not) {
  88. x++;
  89. }
  90. }
  91. }
  92. void test_attribute_on_if_exists() {
  93. [[clang::fallthrough]] // expected-error {{an attribute list cannot appear here}}
  94. __if_exists(MayExist::Type) {
  95. int x;
  96. }
  97. }