Fix all tests that fail with -sanitize=return.
[official-gcc.git] / gcc / testsuite / g++.dg / torture / pr34850.C
blobc2538288964d5867bedb3c6cb41d8c40b93ec91b
1 /* { dg-do compile } */
2 /* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
3 /* { dg-options "-ffat-lto-objects" } */
5 typedef unsigned char uint8_t;
6 typedef unsigned int uint32_t;
7 typedef uint8_t byte;
8 typedef uint32_t u32bit;
9 __extension__ typedef __SIZE_TYPE__ size_t;
10 extern "C" {
11     extern void __warn_memset_zero_len (void) __attribute__((__warning__ ("")));
12     extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__, __artificial__))
13     void * memset (void *__dest, int __ch, size_t __len) throw () {
14         if (__builtin_constant_p (__len) && __len == 0)
15             __warn_memset_zero_len (); /* { dg-warning "declared with attribute warning" } */
17         return __dest;
18     }
20 inline void clear_mem(void* ptr, u32bit n)    {
21     memset(ptr, 0, n);
23 template<typename T> class MemoryRegion    {
24 public:
25     u32bit size() const {
26     }
27     const T* begin() const {
28     }
29     void set(const T in[], u32bit n) {
30         create(n);
31     }
32     void set(const MemoryRegion<T>& in) {
33         set(in.begin(), in.size());
34     }
35     void clear() {
36         clear_mem(buf, allocated);
37     }
38     void create(u32bit);
39     MemoryRegion() {
40         used = allocated = 0;
41     }
42     mutable T* buf;
43     mutable u32bit used;
44     mutable u32bit allocated;
46 template<typename T> void MemoryRegion<T>::create(u32bit n)    {
47     if(n <= allocated) {
48         clear();
49     }
51 template<typename T> class SecureVector : public MemoryRegion<T>    {
52 public:
53     SecureVector<T>& operator=(const MemoryRegion<T>& in)          {
54         if(this != &in) this->set(in);
55         return *this;
56     }
58 class OctetString    {
59 public:
60     SecureVector<byte> bits_of() const {
61         return SecureVector<byte> ();
62     }
63     OctetString& operator^=(const OctetString&);
64     void change(const MemoryRegion<byte>& in) {
65         bits = in;
66     }
67     OctetString(const MemoryRegion<byte>& in) {
68         change(in);
69     }
70     SecureVector<byte> bits;
72 OctetString& OctetString::operator^=(const OctetString& k)    {
73     if(&k == this) {
74         bits.clear();
75     }
77     return *this;
79 bool __attribute__((flatten))
80 operator==(const OctetString& s1, const OctetString& s2)    {
81     return (s1.bits_of() == s2.bits_of());