brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 79cc571 Raw
118 lines · cpp
1// RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -Wmicrosoft -verify -fms-extensions2 3class MayExist {4private:5  typedef int Type;6};7 8void test_if_exists_stmts() {9  int b = 0;10  __if_exists(MayExist::Type) {11    b++;12    b++;13  }14  __if_exists(MayExist::Type_not) {15    this will not compile.16  }17  __if_not_exists(MayExist::Type) {18    this will not compile.19  }20  __if_not_exists(MayExist::Type_not) {21    b++;22    b++;23  }24}25 26int if_exists_creates_no_scope() {27  __if_exists(MayExist::Type) {28    int x;  // 'x' is declared in the parent scope.29  }30  __if_not_exists(MayExist::Type_not) {31    x++;32  }33  return x;34}35 36__if_exists(MayExist::Type) {37  int var23;38}39 40__if_exists(MayExist::Type_not) {41  this will not compile.42}43 44__if_not_exists(MayExist::Type) {45  this will not compile.46}47 48__if_not_exists(MayExist::Type_not) {49  int var244;50}51 52void test_if_exists_init_list() {53 54  int array1[] = {55    0,56    __if_exists(MayExist::Type) {2, }57    358  };59 60  int array2[] = {61    0,62    __if_exists(MayExist::Type_not) { this will not compile }63    364  };65 66  int array3[] = {67    0,68    __if_not_exists(MayExist::Type_not) {2, }69    370  };71 72  int array4[] = {73    0,74    __if_not_exists(MayExist::Type) { this will not compile }75    376  };77 78}79 80 81class IfExistsClassScope {82  __if_exists(MayExist::Type) {83    // __if_exists, __if_not_exists can nest84    __if_not_exists(MayExist::Type_not) {85      int var123;86    }87    int var23;88  }89 90  __if_exists(MayExist::Type_not) {91   this will not compile.92  }93 94  __if_not_exists(MayExist::Type) {95   this will not compile.96  }97 98  __if_not_exists(MayExist::Type_not) {99    int var244;100  }101};102 103void test_nested_if_exists() {104  __if_exists(MayExist::Type) {105    int x = 42;106    __if_not_exists(MayExist::Type_not) {107      x++;108    }109  }110}111 112void test_attribute_on_if_exists() {113  [[clang::fallthrough]] // expected-error {{an attribute list cannot appear here}}114  __if_exists(MayExist::Type) {115    int x;116  }117}118