summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.other/delete4.C
blob: 0971eb98260738759b3dbaee3abc376832eaef7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// { dg-do assemble  }

// Copyright (C) 1999 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 15 Apr 1999 <nathan@acm.org>

// delete (void *)e and delete[] (void *)e result in undefined behavior
// [expr.delete/3]. Check we warn about them
// operator new functions can only return NULL, if their exceptions
// specification is `throw()'. All other cases must return a non-null pointer
// [expr.new/13].

typedef __SIZE_TYPE__ size_t;

void *operator new(size_t)
{
  return 0; // { dg-warning "NULL" } cannot return NULL
}
void *operator new[](size_t)
{
  return 0; // { dg-warning "NULL" } cannot return NULL
}

struct X
{
  void *operator new(size_t)
  {
    return 0; // { dg-warning "NULL" } cannot return NULL
  }
  void *operator new[](size_t)
  {
    return 0; // { dg-warning "NULL" } cannot return NULL
  }
};

struct Y
{
  void *operator new(size_t) throw()
  {
    return 0; // ok
  }
  void *operator new[](size_t) throw()
  {
    return 0; // ok
  }
};

void fn(double *d, void *v)
{
  delete d;   // ok
  delete v;   // { dg-warning "" } deleting void
  delete[] d; // ok
  delete[] v; // { dg-warning "" } deleting void
}