LINUX.ORG.RU

История изменений

Исправление rumgot, (текущая версия) :

Хм. На Microsoft Visual C++ Compiler 16.8.30711.63 (amd64) не падает.

#include <iostream>
#include <string>

int main() {
  union MyUnion {
    MyUnion() {}
    ~MyUnion() {}
    std::string a;
    std::string b;
  } u;

  // segmentation fault не наблюдаю
  u.a = std::string{"Hello, World!"};
  // new (&u.a) std::string{"Hello, World!\n"};
  std::cout << u.a;
}

Исправление rumgot, :

Хм. На Microsoft Visual C++ Compiler 16.8.30711.63 (amd64) не падает.

#include <iostream>
#include <string>

int main() {
  union MyUnion {
    MyUnion() {}
    ~MyUnion() {}
    std::string a;
    std::string b;
  } u;

  // 	segmentation fault не наблюдаю
  u.a = std::string{"Hello, World!"};
  //  new (&u.a) std::string{"Hello, World!\n"};
  std::cout << u.a;
}

Исправление rumgot, :

Хм. На Microsoft Visual C++ Compiler 16.8.30711.63 (amd64) не падает.

#include <iostream>
#include <string>

int main() {
  union MyUnion {
    MyUnion() {}
    ~MyUnion() {}
    std::string a;
    std::string b;
  } u;

  // 	segmentation fault
  u.a = std::string{"Hello, World!"};
  //  new (&u.a) std::string{"Hello, World!\n"};
  std::cout << u.a;
}

Исходная версия rumgot, :

Хм. На Microsoft Visual C++ Compiler 16.8.30711.63 (amd64) не падает.