https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122360

            Bug ID: 122360
           Summary: Initialized variable is reported as uninitialized when
                    reading through a reinterpret_cast-ed pointer
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: csaba_22 at yahoo dot co.uk
  Target Milestone: ---

When compiled with -O2 -Wall -Wno-strict-aliasing,  the following code

#include <stdint.h>

uint8_t sum()
{
    uint64_t dw = 42ul;
    uint32_t wo = reinterpret_cast<uint32_t*>(&dw)[0] +
reinterpret_cast<uint32_t*>(&dw)[1];
    uint16_t hw = reinterpret_cast<uint16_t*>(&wo)[0] +
reinterpret_cast<uint16_t*>(&wo)[1];
    uint16_t bb = reinterpret_cast<uint8_t *>(&hw)[0] +
reinterpret_cast<uint8_t *>(&hw)[1];
    return bb;
}

reports 'dw' is used uninitialized, even though dw is declared with an
initializer.

https://godbolt.org/z/GKK9xsrP8

Originally detected with RedHat's GCC 12.2.1; same behavior with GCC 12.5 on
godbolt.

Reply via email to