summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/exceptions-seh.cpp
blob: dd00c11590ae79615c8a7bdcaef9c07929b0bc64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -fsyntax-only -fexceptions -fcxx-exceptions -verify %s

// Basic usage should work.
int safe_div(int n, int d) {
  int r;
  __try {
    r = n / d;
  } __except(_exception_code() == 0xC0000094) {
    r = 0;
  }
  return r;
}

void might_crash();

// Diagnose obvious builtin mis-usage.
void bad_builtin_scope() {
  __try {
    might_crash();
  } __except(1) {
  }
  _exception_code(); // expected-error {{'_exception_code' only allowed in __except block or filter expression}}
  _exception_info(); // expected-error {{'_exception_info' only allowed in __except filter expression}}
}

// Diagnose obvious builtin misusage in a template.
template <void FN()>
void bad_builtin_scope_template() {
  __try {
    FN();
  } __except(1) {
  }
  _exception_code(); // expected-error {{'_exception_code' only allowed in __except block or filter expression}}
  _exception_info(); // expected-error {{'_exception_info' only allowed in __except filter expression}}
}
void instantiate_bad_scope_tmpl() {
  bad_builtin_scope_template<might_crash>();
}

// FIXME: Diagnose this case. For now we produce undef in codegen.
template <typename T, T FN()>
T func_template() {
  return FN();
}
void inject_builtins() {
  func_template<void *, __exception_info>();
  func_template<unsigned long, __exception_code>();
}

void use_seh_after_cxx() {
  try { // expected-note {{conflicting 'try' here}}
    might_crash();
  } catch (int) {
  }
  __try { // expected-error {{cannot use C++ 'try' in the same function as SEH '__try'}}
    might_crash();
  } __except(1) {
  }
}

void use_cxx_after_seh() {
  __try { // expected-note {{conflicting '__try' here}}
    might_crash();
  } __except(1) {
  }
  try { // expected-error {{cannot use C++ 'try' in the same function as SEH '__try'}}
    might_crash();
  } catch (int) {
  }
}
OpenPOWER on IntegriCloud