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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Pedro Alves from comment #4)
> Looks like I over reduced in the minimal reproducer.  std::optional has a
> boolean field to track whether the contained object had been fully
> initialized, which is checked in the desctructor, but I removed it because
> its presence doesn't affect whether the warning is emitted.  Of course,
> std::optional has that field, but still, it warns.

I think the problem is that GCC isn't smart enough to infer the invariant that
the truthiness of the bool corresponds to the initialization of the member. So
the value of the bool is treated as unrelated to the (un)initialized state. By
inspecting all the accesses to the bool we can tell that's true, but the
compiler apparently can't. I don't know how we could state the invariant in
code.

Reply via email to