128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley// RUN: %clang_cc1 -fsyntax-only -verify -fborland-extensions -fcxx-exceptions %s
228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley// This test is from http://docwiki.embarcadero.com/RADStudio/en/Try
428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyint puts(const char *);
628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename T>
828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyint printf(const char *, T);
928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyconst char * strdup(const char *);
1128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyvoid free(const void *);
1328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley#define EXCEPTION_EXECUTE_HANDLER 1
1528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
1628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyclass Exception
1728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley{
1828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleypublic:
1928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Exception(const char* s = "Unknown"){what = strdup(s);      }
2028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  Exception(const Exception& e ){what = strdup(e.what); }
2128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  ~Exception()                   {free(what);         }
2228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  const char* msg() const             {return what;           }
2328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyprivate:
2428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  const char* what;
2528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley};
2628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
2728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleyint main()
2828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley{
2928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  float e, f, g;
3028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  try
3128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  {
3228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    try
3328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    {
3428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley      f = 1.0;
3528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley      g = 0.0;
3628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley      try
3728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley      {
3828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley        puts("Another exception:");
3928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley
4028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley        e = f / g;
4128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley      }
4228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley      __except(EXCEPTION_EXECUTE_HANDLER)
4328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley      {
4428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley        puts("Caught a C-based exception.");
4528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley        throw(Exception("Hardware error: Divide by 0"));
4628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley      }
4728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    }
4828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    catch(const Exception& e)
4928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    {
5028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley      printf("Caught C++ Exception: %s :\n", e.msg());
5128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    }
5228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
5328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  __finally
5428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  {
5528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley    puts("C++ allows __finally too!");
5628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  }
5728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley  return e;
5828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley}
59