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