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