blob: a0f503abe6c8fb2cff73ef07be1620b93e72cb9f [file] [log] [blame]
John Wiegley28bbe4b2011-04-28 01:08:34 +00001// RUN: %clang_cc1 -fsyntax-only -verify -fborland-extensions -fcxx-exceptions %s
Andy Gibbs8e8fb3b2012-10-19 12:44:48 +00002// expected-no-diagnostics
John Wiegley28bbe4b2011-04-28 01:08:34 +00003
4// This test is from http://docwiki.embarcadero.com/RADStudio/en/Try
5
6int puts(const char *);
7
8template<typename T>
9int printf(const char *, T);
10
11const char * strdup(const char *);
12
13void free(const void *);
14
15#define EXCEPTION_EXECUTE_HANDLER 1
16
17class Exception
18{
19public:
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; }
24private:
25 const char* what;
26};
27
28int 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}