fork download
  1. #include <iostream>
  2.  
  3. constexpr bool t()
  4. {
  5. struct A {};
  6. struct B {};
  7. union U { A a; B b; } u{};
  8. u.a = A{};
  9. u.b = B{};
  10. return true;
  11. }
  12. static_assert(t(), "oops");
  13.  
  14. constexpr bool f()
  15. {
  16. struct A { char c; };
  17. struct B { char c; };
  18. union U { A a; B b; } u{};
  19. u.a = A{};
  20. u.b = B{}; // error originating from here
  21. return true;
  22. }
  23. static_assert(f(), "whoa dude");
  24.  
  25. int main () { std::cout << "It worked"; }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
It worked