• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//  (C) Copyright Edward Diener 2019
2
3//  Use, modification and distribution are subject to the
4//  Boost Software License, Version 1.0. (See accompanying file
5//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7//  See http://www.boost.org/libs/config for more information.
8
9//  MACRO:         BOOST_NO_CXX11_UNRESTRICTED_UNION
10//  TITLE:         C++11 unrestricted union
11//  DESCRIPTION:   The compiler does not support the C++11 unrestricted union
12
13#include <new>
14
15namespace boost_no_cxx11_unrestricted_union {
16
17struct HoldsShort
18    {
19    short i;
20    HoldsShort();
21    };
22
23HoldsShort::HoldsShort() : i(1)
24    {
25    }
26
27union with_static_data
28    {
29    int a;
30    long b;
31    HoldsShort o;
32    with_static_data();
33    static int sd;
34    };
35
36with_static_data::with_static_data() :
37    a(0)
38    {
39    }
40
41int with_static_data::sd = 0;
42
43int test()
44{
45  with_static_data wsd;
46  wsd.a = 24;
47  wsd.b = 48L;
48  new(&wsd.o) HoldsShort;
49  wsd.o.i = 2;
50  with_static_data::sd = 1;
51  bool b = (wsd.o.i == 2 && with_static_data::sd == 1);
52  return b ? 0 : 1;
53}
54
55}
56