Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
1.5 KiB

  1. /*
  2. COMMAND LINE: -Ox -GX
  3. DESCRIPTION: test some weird EH flow.
  4. */
  5. #include <stdio.h>
  6. int i;
  7. class C
  8. {
  9. public:
  10. C(char *s) { printf("Constructing %s0\n", s); str = s; inst = 0; }
  11. C(const C &c) {
  12. str = c.str;
  13. inst = c.inst + 1;
  14. printf("Copying %s%d from %s%d\n", c.str, c.inst, str, inst);
  15. }
  16. ~C() { printf("Destructing %s%d\n", str, inst); str = NULL; }
  17. char * str;
  18. int inst;
  19. };
  20. void foo()
  21. {
  22. C f("InFoo");
  23. i++;
  24. if(i&1)
  25. throw(f);
  26. }
  27. void bar()
  28. {
  29. C b("InBar");
  30. i++;
  31. if(i&3)
  32. throw(b);
  33. }
  34. void nothing()
  35. {
  36. }
  37. /* CRT implementation gives a different destruction order if bar is being
  38. inlined.. */
  39. #pragma inline_depth(0)
  40. C test()
  41. {
  42. C c1("c1");
  43. try{
  44. C c2("c2");
  45. if(i){
  46. try{
  47. C c3("c3");
  48. foo();
  49. return c3;
  50. }catch(C c4){
  51. printf("Caught %s%d\n", c4.str, c4.inst);
  52. C c5("c5");
  53. bar();
  54. return c5;
  55. }
  56. }
  57. foo();
  58. }catch(C &c6){
  59. printf("Caught %s%d\n", c6.str, c6.inst);
  60. nothing();
  61. }
  62. nothing();
  63. return c1;
  64. }
  65. #pragma inline_depth()
  66. int main()
  67. {
  68. printf("i = %d\n", i);
  69. test();
  70. printf("i = %d\n", i);
  71. test();
  72. printf("i = %d\n", i);
  73. test();
  74. printf("i = %d\n", i);
  75. test();
  76. return 0;
  77. }