Advertisement
Guest User

CppCoreCheck with union

a guest
Jul 28th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #pragma pack(push, 1)
  2. class Handle
  3. {
  4.     union
  5.     {
  6.         struct
  7.         {
  8.             unsigned short index;           //the index in global handle list
  9.             unsigned short handleNumber;    //the identifier number
  10.         } handleDetail;
  11.         unsigned int handle;
  12.     };
  13.  
  14. public:
  15.  
  16.     /// warning C26495: Variable 'Handle::<unnamed-tag>::handleDetail' is uninitialized. Always initialize a member variable.
  17.     Handle()
  18.         : handle(0)
  19.         //, handleDetail() /// Uncommenting line fixes C26495 but doesn't make sense
  20.     {}
  21. };
  22. #pragma pack(pop)
  23.  
  24. int main()
  25. {
  26.     Handle h;
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement