diff options
author | dim <dim@FreeBSD.org> | 2011-05-02 19:39:53 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2011-05-02 19:39:53 +0000 |
commit | 110eaaceddcec790f7e6a5e3bf1261c9aa1e73ab (patch) | |
tree | 64a10f4c4154739d4a8191d7e1b52ce497f4ebd6 /test/SemaCXX/__try.cpp | |
parent | a0fb00f9837bd0d2e5948f16f6a6b82a7a628f51 (diff) | |
download | FreeBSD-src-110eaaceddcec790f7e6a5e3bf1261c9aa1e73ab.zip FreeBSD-src-110eaaceddcec790f7e6a5e3bf1261c9aa1e73ab.tar.gz |
Vendor import of clang trunk r130700:
http://llvm.org/svn/llvm-project/cfe/trunk@130700
Diffstat (limited to 'test/SemaCXX/__try.cpp')
-rw-r--r-- | test/SemaCXX/__try.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/SemaCXX/__try.cpp b/test/SemaCXX/__try.cpp new file mode 100644 index 0000000..cb5d38a --- /dev/null +++ b/test/SemaCXX/__try.cpp @@ -0,0 +1,58 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -fborland-extensions -fcxx-exceptions %s + +// This test is from http://docwiki.embarcadero.com/RADStudio/en/Try + +int puts(const char *); + +template<typename T> +int printf(const char *, T); + +const char * strdup(const char *); + +void free(const void *); + +#define EXCEPTION_EXECUTE_HANDLER 1 + +class Exception +{ +public: + Exception(const char* s = "Unknown"){what = strdup(s); } + Exception(const Exception& e ){what = strdup(e.what); } + ~Exception() {free(what); } + const char* msg() const {return what; } +private: + const char* what; +}; + +int main() +{ + float e, f, g; + try + { + try + { + f = 1.0; + g = 0.0; + try + { + puts("Another exception:"); + + e = f / g; + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + puts("Caught a C-based exception."); + throw(Exception("Hardware error: Divide by 0")); + } + } + catch(const Exception& e) + { + printf("Caught C++ Exception: %s :\n", e.msg()); + } + } + __finally + { + puts("C++ allows __finally too!"); + } + return e; +} |