Home | History | Annotate | Download | only in Sema
      1 // RUN: %clang_cc1 -fborland-extensions -fsyntax-only -verify %s
      2 
      3 #define JOIN2(x,y) x ## y
      4 #define JOIN(x,y) JOIN2(x,y)
      5 #define TEST2(name) JOIN(name,__LINE__)
      6 #define TEST TEST2(test)
      7 typedef int DWORD;
      8 
      9 #pragma sysheader begin
     10 
     11 struct EXCEPTION_INFO{};
     12 
     13 int __exception_code();
     14 struct EXCEPTION_INFO* __exception_info();
     15 void __abnormal_termination();
     16 
     17 #define GetExceptionCode __exception_code
     18 #define GetExceptionInformation __exception_info
     19 #define AbnormalTermination __abnormal_termination
     20 
     21 #pragma sysheader end
     22 
     23 DWORD FilterExpression(int);
     24 DWORD FilterExceptionInformation(struct EXCEPTION_INFO*);
     25 
     26 const char * NotFilterExpression();
     27 
     28 void TEST() {
     29   __try {
     30     __try {
     31       __try {
     32       }
     33       __finally{
     34       }
     35     }
     36     __finally{
     37     }
     38   }
     39   __finally{
     40   }
     41 }
     42 
     43 void TEST() {
     44   __try {
     45 
     46   }
     47 }  // expected-error{{expected '__except' or '__finally' block}}
     48 
     49 void TEST() {
     50   __except ( FilterExpression() ) { // expected-error{{}}
     51 
     52   }
     53 }
     54 
     55 void TEST() {
     56   __finally { } // expected-error{{}}
     57 }
     58 
     59 void TEST() {
     60   __try{
     61     int try_scope = 0;
     62   } // TODO: expected expression is an extra error
     63   __except( try_scope ? 1 : -1 ) // expected-error{{undeclared identifier 'try_scope'}} expected-error{{expected expression}}
     64   {}
     65 }
     66 
     67 void TEST() {
     68   __try {
     69 
     70   }
     71   // TODO: Why are there two errors?
     72   __except( ) { // expected-error{{expected expression}} expected-error{{expected expression}}
     73   }
     74 }
     75 
     76 void TEST() {
     77   __try {
     78 
     79   }
     80   __except ( FilterExpression(GetExceptionCode()) ) {
     81 
     82   }
     83 
     84   __try {
     85 
     86   }
     87   __except( FilterExpression(__exception_code()) ) {
     88 
     89   }
     90 
     91   __try {
     92 
     93   }
     94   __except( FilterExceptionInformation(__exception_info()) ) {
     95 
     96   }
     97 
     98   __try {
     99 
    100   }
    101   __except(FilterExceptionInformation( GetExceptionInformation() ) ) {
    102 
    103   }
    104 }
    105 
    106 void TEST() {
    107   __try {
    108 
    109   }
    110   __except ( NotFilterExpression() ) { // expected-error{{filter expression type should be an integral value not 'const char *'}}
    111 
    112   }
    113 }
    114 
    115 void TEST() {
    116   int function_scope = 0;
    117   __try {
    118     int try_scope = 0;
    119   }
    120   __except ( FilterExpression(GetExceptionCode()) ) {
    121     (void)function_scope;
    122     (void)try_scope; // expected-error{{undeclared identifier}}
    123   }
    124 }
    125 
    126 void TEST() {
    127   int function_scope = 0;
    128   __try {
    129     int try_scope = 0;
    130   }
    131   __finally {
    132     (void)function_scope;
    133     (void)try_scope; // expected-error{{undeclared identifier}}
    134   }
    135 }
    136 
    137 void TEST() {
    138   int function_scope = 0;
    139   __try {
    140 
    141   }
    142   __except( function_scope ? 1 : -1 ) {}
    143 }
    144 
    145 void TEST() {
    146   __try {
    147     (void)AbnormalTermination;  // expected-error{{only allowed in __finally block}}
    148     (void)__abnormal_termination; // expected-error{{only allowed in __finally block}}
    149   }
    150   __except( 1 ) {
    151     (void)AbnormalTermination;  // expected-error{{only allowed in __finally block}}
    152     (void)__abnormal_termination; // expected-error{{only allowed in __finally block}}
    153   }
    154 
    155   __try {
    156   }
    157   __finally {
    158     AbnormalTermination();
    159     __abnormal_termination();
    160   }
    161 }
    162 
    163 void TEST() {
    164   (void)__exception_code;       // expected-error{{only allowed in __except block}}
    165   (void)__exception_info;       // expected-error{{only allowed in __except filter expression}}
    166   (void)__abnormal_termination; // expected-error{{only allowed in __finally block}}
    167 
    168   (void)GetExceptionCode();     // expected-error{{only allowed in __except block}}
    169   (void)GetExceptionInformation(); // expected-error{{only allowed in __except filter expression}}
    170   (void)AbnormalTermination();  // expected-error{{only allowed in __finally block}}
    171 }
    172