Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 2.56 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Unreachable code at constructor's closing brace
  2. __declspec(noreturn) void foo() {
  3.   // Do something, then terminate the program
  4. }
  5. struct A {
  6.   A() {
  7.     foo();
  8.   } // d:foo.cpp(7) : warning C4702: unreachable code
  9. };
  10. int main() {
  11.   A a;
  12. }
  13.        
  14. d:>cl /c /W4 foo.cpp
  15. Microsoft (R) C/C++ Optimizing Compiler Version 15.00.21022.08 for x64
  16. Copyright (C) Microsoft Corporation.  All rights reserved.
  17.  
  18. foo.cpp
  19. d:foo.cpp(7) : warning C4702: unreachable code
  20.        
  21. struct A {
  22. private:
  23.   A(); // No, you can't construct this!
  24. };
  25. int main() {
  26.   A a;
  27. }
  28.        
  29. __declspec(noreturn) void foo() {
  30.   // Do something, then terminate the program
  31. }
  32. struct A {
  33.   A() {
  34.   }
  35.   ~A() {
  36.     foo();
  37.   }
  38. };
  39. int main() {
  40.   A a;
  41. }
  42.        
  43. d:>cl /c /W4 foo3.cpp
  44. Microsoft (R) C/C++ Optimizing Compiler Version 15.00.21022.08 for x64
  45. Copyright (C) Microsoft Corporation.  All rights reserved.
  46.  
  47. foo3.cpp
  48.        
  49. __declspec(noreturn) void foo() {
  50.   // Do something, then terminate the program
  51. }
  52. struct A {
  53.   A() {
  54.     foo();
  55.   }
  56.   ~A() {
  57.   }
  58. };
  59. int main() {
  60.   A a;
  61. }
  62.        
  63. __declspec(noreturn) void foo() {
  64.   // Do something, then terminate the program
  65. }
  66. struct A {
  67.   A() {
  68.   }
  69.   ~A() {
  70.     foo();
  71.   }
  72. };
  73. int main() {
  74.   A a;
  75. }
  76.        
  77. --- noreturn_constructor.disasm 2012-05-30 11:15:02.000000000 -0400
  78. +++ noreturn_destructor.disasm  2012-05-30 11:15:08.000000000 -0400
  79. @@ -2,7 +2,7 @@
  80.  Copyright (C) Microsoft Corporation.  All rights reserved.
  81.  
  82.  
  83. -Dump of file noreturn_constructor.obj
  84. +Dump of file noreturn_destructor.obj
  85.  
  86.  File Type: COFF OBJECT
  87.  
  88. @@ -35,15 +35,15 @@
  89.  
  90.  ??0A@@QEAA@XZ (public: __cdecl A::A(void)):
  91.    0000000000000000: 48 89 4C 24 08     mov         qword ptr [rsp+8],rcx
  92. -  0000000000000005: 48 83 EC 28        sub         rsp,28h
  93. -  0000000000000009: E8 00 00 00 00     call        ?foo@@YAXXZ
  94. -  000000000000000E: 48 8B 44 24 30     mov         rax,qword ptr [rsp+30h]
  95. -  0000000000000013: 48 83 C4 28        add         rsp,28h
  96. -  0000000000000017: C3                 ret
  97. +  0000000000000005: 48 8B 44 24 08     mov         rax,qword ptr [rsp+8]
  98. +  000000000000000A: C3                 ret
  99.  
  100.  ??1A@@QEAA@XZ (public: __cdecl A::~A(void)):
  101.    0000000000000000: 48 89 4C 24 08     mov         qword ptr [rsp+8],rcx
  102. -  0000000000000005: C3                 ret
  103. +  0000000000000005: 48 83 EC 28        sub         rsp,28h
  104. +  0000000000000009: E8 00 00 00 00     call        ?foo@@YAXXZ
  105. +  000000000000000E: 48 83 C4 28        add         rsp,28h
  106. +  0000000000000012: C3                 ret
  107.  
  108.    Summary
  109.        
  110. -  000000000000000E: 48 8B 44 24 30     mov         rax,qword ptr [rsp+30h]
  111. +  0000000000000005: 48 8B 44 24 08     mov         rax,qword ptr [rsp+8]