2018-11-07 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / ubsan / pr65583.C
blob02acb361a22787953b0c9da482f65379583ca966
1 // PR sanitizer/65583
2 // { dg-do compile }
3 // { dg-options "-std=c++11 -fsanitize=undefined" }
4 // { dg-additional-options "-Wno-return-type" }
6 namespace std
8   inline namespace __cxx11
9   {
10   }
11   template < typename > class allocator;
12     template < class _CharT > struct char_traits;
13   namespace __cxx11
14   {
15     template < typename _CharT, typename _Traits =
16       char_traits < _CharT >, typename _Alloc =
17       allocator < _CharT > >class basic_string;
18     typedef basic_string < char >string;
19   }
21 namespace std
23   template < typename _Tp, _Tp __v > struct integral_constant
24   {
25     static constexpr _Tp value = __v;
26   };
27   typedef integral_constant < bool, true > true_type;
29 namespace __gnu_cxx
31   template < typename _Tp > class new_allocator
32   {
33   public:
34     typedef long unsigned size_type;
35     typedef _Tp value_type;
36       template < typename _Tp1 > struct rebind
37     {
38       typedef new_allocator < _Tp1 > other;
39     };
40   };
42 namespace std
44   template < typename _Tp > using __allocator_base =
45     __gnu_cxx::new_allocator < _Tp >;
46   template < typename _Tp > class allocator:public __allocator_base < _Tp >
47   {
48   };
49   template < typename _Alloc, typename _Tp > class __alloctr_rebind_helper
50   {
51     template < typename _Alloc2, typename _Tp2 >
52       static constexpr true_type _S_chk (typename _Alloc2::template rebind <
53                                          _Tp2 >::other *);
54   public:
55     using __type = decltype (_S_chk < _Alloc, _Tp > (nullptr));
56   };
57   template < typename _Alloc, typename _Tp, bool =
58     __alloctr_rebind_helper < _Alloc,
59     _Tp >::__type::value > struct __alloctr_rebind;
60   template < typename _Alloc, typename _Tp > struct __alloctr_rebind <_Alloc,
61     _Tp, true >
62   {
63     typedef typename _Alloc::template rebind < _Tp >::other __type;
64   };
65   template < typename _Alloc > struct allocator_traits
66   {
67     typedef typename _Alloc::value_type value_type;
68     static value_type *_S_pointer_helper (...);
69     typedef decltype (_S_pointer_helper ((_Alloc *) 0)) __pointer;
70     typedef __pointer pointer;
71       template < typename _Tp >
72       static typename _Tp::size_type _S_size_type_helper (_Tp *);
73     typedef decltype (_S_size_type_helper ((_Alloc *) 0)) __size_type;
74     typedef __size_type size_type;
75       template < typename _Tp > using rebind_alloc =
76       typename __alloctr_rebind < _Alloc, _Tp >::__type;
77   };
79 namespace __gnu_cxx
81   template < typename _Alloc > struct __alloc_traits:std::allocator_traits <
82     _Alloc >
83   {
84     typedef std::allocator_traits < _Alloc > _Base_type;
85       template < typename _Tp > struct rebind
86     {
87       typedef typename _Base_type::template rebind_alloc < _Tp > other;
88     };
89   };
91 namespace std
93   namespace __cxx11
94   {
95     template < typename _CharT, typename _Traits,
96       typename _Alloc > class basic_string
97     {
98       typedef typename __gnu_cxx::__alloc_traits < _Alloc >::template rebind <
99         _CharT >::other _Char_alloc_type;
100       typedef __gnu_cxx::__alloc_traits < _Char_alloc_type > _Alloc_traits;
101       typedef _Char_alloc_type allocator_type;
102       typedef typename _Alloc_traits::size_type size_type;
103       typedef typename _Alloc_traits::pointer pointer;
104       struct _Alloc_hider:allocator_type
105       {
106         _Alloc_hider (pointer __dat, const _Alloc & __a)
107         {
108         }
109       };
110       _Alloc_hider _M_dataplus;
111       union
112       {
113         size_type _M_allocated_capacity;
114       };
115       pointer _M_local_data ()
116       {
117       }
118       void _M_dispose ()
119       {
120         _M_destroy (_M_allocated_capacity);
121       }
122       void _M_destroy (size_type __size) throw ()
123       {
124       }
125     public:
126     basic_string (const _CharT * __s, const _Alloc & __a = _Alloc ()):_M_dataplus (_M_local_data (),
127                    __a)
128       {
129         _M_dispose ();
130       }
131     };
132   }
133   class FileHandle
134   {
135     std::string fname;
136     FileHandle (const char *fname);
137   };
138   FileHandle::FileHandle (const char *fname):fname (fname)
139   {
140   }