1 // RUN: %clang_cc1 -fsyntax-only -verify -fborland-extensions -fcxx-exceptions %s
2 // expected-no-diagnostics
3 
4 // This test is from http://docwiki.embarcadero.com/RADStudio/en/Try
5 
6 int puts(const char *);
7 
8 template<typename T>
9 int printf(const char *, T);
10 
11 const char * strdup(const char *);
12 
13 void free(const void *);
14 
15 #define EXCEPTION_EXECUTE_HANDLER 1
16 
17 class Exception
18 {
19 public:
20   Exception(const char* s = "Unknown"){what = strdup(s);      }
21   Exception(const Exception& e ){what = strdup(e.what); }
22   ~Exception()                   {free(what);         }
23   const char* msg() const             {return what;           }
24 private:
25   const char* what;
26 };
27 
28 int main()
29 {
30   float e, f, g;
31   try
32   {
33     try
34     {
35       f = 1.0;
36       g = 0.0;
37       try
38       {
39         puts("Another exception:");
40 
41         e = f / g;
42       }
43       __except(EXCEPTION_EXECUTE_HANDLER)
44       {
45         puts("Caught a C-based exception.");
46         throw(Exception("Hardware error: Divide by 0"));
47       }
48     }
49     catch(const Exception& e)
50     {
51       printf("Caught C++ Exception: %s :\n", e.msg());
52     }
53   }
54   __finally
55   {
56     puts("C++ allows __finally too!");
57   }
58   return e;
59 }
60 
61 namespace PR17584 {
62 template <typename>
63 void Except() {
64   __try {
65   } __except(true) {
66   }
67 }
68 
69 template <typename>
70 void Finally() {
71   __try {
72   } __finally {
73   }
74 }
75 
76 template void Except<void>();
77 template void Finally<void>();
78 
79 }
80