brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.1 KiB · 02bb786 Raw
129 lines · cpp
1// RUN: %clang_cc1 -std=c++03 -fblocks -triple x86_64-windows-msvc -fms-extensions -fsyntax-only -fexceptions -fcxx-exceptions -verify %s2// RUN: %clang_cc1 -std=c++11 -fblocks -triple x86_64-windows-msvc -fms-extensions -fsyntax-only -fexceptions -fcxx-exceptions -verify %s3 4// Basic usage should work.5int safe_div(int n, int d) {6  int r;7  __try {8    r = n / d;9  } __except(_exception_code() == 0xC0000094) {10    r = 0;11  }12  return r;13}14 15void might_crash();16 17// Diagnose obvious builtin mis-usage.18void bad_builtin_scope() {19  __try {20    might_crash();21  } __except(1) {22  }23  _exception_code(); // expected-error {{'_exception_code' only allowed in __except block or filter expression}}24  _exception_info(); // expected-error {{'_exception_info' only allowed in __except filter expression}}25}26 27// Diagnose obvious builtin misusage in a template.28template <void FN()>29void bad_builtin_scope_template() {30  __try {31    FN();32  } __except(1) {33  }34  _exception_code(); // expected-error {{'_exception_code' only allowed in __except block or filter expression}}35  _exception_info(); // expected-error {{'_exception_info' only allowed in __except filter expression}}36}37void instantiate_bad_scope_tmpl() {38  bad_builtin_scope_template<might_crash>();39}40 41#if __cplusplus < 201103L42template <typename T, T FN()>43T func_template() {44  return FN(); // expected-error 2{{builtin functions must be directly called}}45}46void inject_builtins() {47  func_template<void *, __exception_info>(); // expected-note {{instantiation of}}48  func_template<unsigned long, __exception_code>(); // expected-note {{instantiation of}}49}50#endif51 52void use_seh_after_cxx() {53  try { // expected-note {{conflicting 'try' here}}54    might_crash();55  } catch (int) {56  }57  __try { // expected-error {{cannot use C++ 'try' in the same function as SEH '__try'}}58    might_crash();59  } __except(1) {60  }61}62 63void use_cxx_after_seh() {64  __try { // expected-note {{conflicting '__try' here}}65    might_crash();66  } __except(1) {67  }68  try { // expected-error {{cannot use C++ 'try' in the same function as SEH '__try'}}69    might_crash();70  } catch (int) {71  }72}73 74#if __cplusplus >= 201103L75void use_seh_in_lambda() {76  ([]() {77    __try {78      might_crash();79    } __except(1) {80    }81  })();82  try {83    might_crash();84  } catch (int) {85  }86}87#endif88 89void use_seh_in_block() {90  void (^b)() = ^{91    __try { // expected-error {{cannot use SEH '__try' in blocks, captured regions, or Obj-C method decls}}92      might_crash();93    } __except(1) {94    }95  };96  try {97    b();98  } catch (int) {99  }100}101 102void (^use_seh_in_global_block)() = ^{103  __try { // expected-error {{cannot use SEH '__try' in blocks, captured regions, or Obj-C method decls}}104    might_crash();105  } __except(1) {106  }107};108 109void (^use_cxx_in_global_block)() = ^{110  try {111    might_crash();112  } catch(int) {113  }114};115 116template <class T> void dependent_filter() {117  __try {118    might_crash();119  } __except (T()) { // expected-error {{filter expression has non-integral type 'NotInteger'}}120  }121}122 123struct NotInteger { int x; };124 125void instantiate_dependent_filter() {126  dependent_filter<int>();127  dependent_filter<NotInteger>(); // expected-note {{requested here}}128}129