Uploaded image for project: 'SonarCFamily'
  1. SonarCFamily
  2. CPP-3000

Rule S6232: "std::bit_cast" should be used instead of union type-punning

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.26
    • Component/s: C++, Rules

      Description

      This is extracted part of the CPP-2928

      Detect uses of the union that are equivalent to bit-cast:

      float x = 1.0f;
      
      union fi_union
      {
      	float f;
      	uint32_t i;
      };
      
      fi_union u;
      u.f = x;
      const uint32_t y = u.i;	
      

      See:

      Consider overlap with other union-replacement rules: RSPEC-6025 and RSPEC-6147.

      Once implemented add link to the RSPEC in See section of RSPEC-6181.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              arseniy.zaostrovnykh Arseniy Zaostrovnykh
              Reporter:
              tomasz.kaminski Tomasz KamiƄski
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: