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