[lld][WebAssembly] Reinstate mistakenly disabled test. NFC
[llvm-project.git] / clang / test / SemaCXX / exceptions-seh.cpp
blob02bb786160dcfe37129f0e62b4042debdc7f3a12
1 // RUN: %clang_cc1 -std=c++03 -fblocks -triple x86_64-windows-msvc -fms-extensions -fsyntax-only -fexceptions -fcxx-exceptions -verify %s
2 // RUN: %clang_cc1 -std=c++11 -fblocks -triple x86_64-windows-msvc -fms-extensions -fsyntax-only -fexceptions -fcxx-exceptions -verify %s
4 // Basic usage should work.
5 int safe_div(int n, int d) {
6 int r;
7 __try {
8 r = n / d;
9 } __except(_exception_code() == 0xC0000094) {
10 r = 0;
12 return r;
15 void might_crash();
17 // Diagnose obvious builtin mis-usage.
18 void bad_builtin_scope() {
19 __try {
20 might_crash();
21 } __except(1) {
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}}
27 // Diagnose obvious builtin misusage in a template.
28 template <void FN()>
29 void bad_builtin_scope_template() {
30 __try {
31 FN();
32 } __except(1) {
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}}
37 void instantiate_bad_scope_tmpl() {
38 bad_builtin_scope_template<might_crash>();
41 #if __cplusplus < 201103L
42 template <typename T, T FN()>
43 T func_template() {
44 return FN(); // expected-error 2{{builtin functions must be directly called}}
46 void inject_builtins() {
47 func_template<void *, __exception_info>(); // expected-note {{instantiation of}}
48 func_template<unsigned long, __exception_code>(); // expected-note {{instantiation of}}
50 #endif
52 void use_seh_after_cxx() {
53 try { // expected-note {{conflicting 'try' here}}
54 might_crash();
55 } catch (int) {
57 __try { // expected-error {{cannot use C++ 'try' in the same function as SEH '__try'}}
58 might_crash();
59 } __except(1) {
63 void use_cxx_after_seh() {
64 __try { // expected-note {{conflicting '__try' here}}
65 might_crash();
66 } __except(1) {
68 try { // expected-error {{cannot use C++ 'try' in the same function as SEH '__try'}}
69 might_crash();
70 } catch (int) {
74 #if __cplusplus >= 201103L
75 void use_seh_in_lambda() {
76 ([]() {
77 __try {
78 might_crash();
79 } __except(1) {
81 })();
82 try {
83 might_crash();
84 } catch (int) {
87 #endif
89 void 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) {
96 try {
97 b();
98 } catch (int) {
102 void (^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) {
109 void (^use_cxx_in_global_block)() = ^{
110 try {
111 might_crash();
112 } catch(int) {
116 template <class T> void dependent_filter() {
117 __try {
118 might_crash();
119 } __except (T()) { // expected-error {{filter expression has non-integral type 'NotInteger'}}
123 struct NotInteger { int x; };
125 void instantiate_dependent_filter() {
126 dependent_filter<int>();
127 dependent_filter<NotInteger>(); // expected-note {{requested here}}