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

--- Comment #7 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
This may be related. Assigning to another member doesn't end the lifetime of
the active one: https://godbolt.org/z/eMGY5ehnb.

```C++
#include <memory>

struct symbol { };

constexpr symbol one{};

struct unit {
  const struct symbol* symbol = &one;

  struct not_one_t { };

  union to_the {
    not_one_t not_one = {}; // Omits ¹ from NTTP.
    int i;

    to_the() = default;
    constexpr to_the(int i) : i{i} {
      if (i == 1) {
        // std::destroy_at(&this->i); // On GCC, doesn't help.
        not_one = {};
        // std::construct_at(&not_one); // On GCC, initializes `not_one`,
doesn't end the lifetime of `i`.
      }
    }
  } exponent = {};

  constexpr unit(const struct symbol& s)
    : symbol{&s} { }
  constexpr unit(const struct symbol& s, auto e)
    : symbol{&s}, exponent{e} { }
};

template<auto> void print() { }

int main() {
  constexpr auto U = unit{one, 1};
  print<U>();
  print<unit{one}>();
  static_assert(&U.exponent.not_one);
  // static_assert(U.exponent.i == 1); // Works on GCC (and MSVC).
}
```

Reply via email to