John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -fborland-extensions -fcxx-exceptions %s |
Andy Gibbs | 8e8fb3b | 2012-10-19 12:44:48 +0000 | [diff] [blame] | 2 | // expected-no-diagnostics |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 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 | } |