File: DefaultAlloc.cpp

package info (click to toggle)
libloki 0.1.5-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,888 kB
  • ctags: 5,535
  • sloc: cpp: 22,174; ansic: 1,955; makefile: 359; php: 316; perl: 108
file content (765 lines) | stat: -rw-r--r-- 24,943 bytes parent folder | download
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
/** @file DefaultAlloc.cpp  Tests compiler compliance when using the new and
 delete operators.

 @author Rich Sposato (original author)

 @par Purpose of Program
 This program tests how well C++ compilers comply with the ISO C++ Standard in
 implementing new, new [], delete, and delete [] operators.  The program should
 identify each known way in which a C++ compiler can fail to comply.  It
 provides versions of each new, new[], delete, and delete [] operators that
 classes typically overload.  These functions have the same signatures as
 those in the Loki project, and the same as those enumerated in section 18 of
 the ISO C++ Standard.

 @par Running the Program
 If the programs fails to compile, or crashes when executed, the compiler does
 not comply with the ISO C++ Standard.  As the program runs, it should:
 - identify your compiler,
 - execute each version of the new, new[], delete, and delete [] operators,
 - determine if compiler provides correct behavior when exceptions are thrown,
 - determine if correct operators were called for each appropriate situation,
 - and determine if the correct parameters were provided to each function.

 @par License
 This file is released under the MIT License - like the rest of Loki.  You
 may use it and modify it as you wish - except that the entire set of
 documentation commentary at the top of this file shall remain intact.

 @par Connection to Loki
 This file is provided as part of the Loki project - but does not depend upon
 any other files in Loki.  It was made for Loki by Rich Sposato to determine
 which compilers can safely use Loki's Small-Object Allocator.  During his
 work on Loki, Rich noticed that some compilers did not provide the correct
 values to the allocation / deallocation operators, or worse, called the wrong
 operator.  Rather than make several variations of allocator functions to work
 around areas of non-compliance, Rich decided to write a program that exposes
 which compilers do not comply with the ISO C++ Standard.  It is recommended
 that you execute this program before incorporating Loki's Small-Object
 Allocator from your source code.  Hence, this program is a "crash test dummy"
 for how well your compiler can handle Loki.
 */

// $Header: /cvsroot/loki-lib/loki/test/SmallObj/DefaultAlloc.cpp,v 1.1 2005/10/13 00:40:38 rich_sposato Exp $


// ----------------------------------------------------------------------------

#include <iostream>
#include <new>


// ----------------------------------------------------------------------------

using namespace std;


/** @par Array Overhead
 Most compilers require a few extra bytes when allocating arrays via the new []
 operators.  The overhead is needed to keep track of how many objects are in
 the array and how many bytes were allocated.  The overhead often exists as 4
 extra bytes at the start of the array.
 */
static const unsigned int ArrayOverhead = 4;
static const unsigned int ArrayCount = 1000;

static bool s_verbose = false;


// ----------------------------------------------------------------------------

class EmptyThing { };

class BadBee : public std::exception
{
public:
    BadBee( void ) : m_message( "Unknown exception." ) {}
    BadBee( const char * m ) : m_message( m ) {}
    virtual ~BadBee( void ) throw() {}
    virtual const char* what() const throw() { return m_message; }
private:
    const char * m_message;
};

class Bee
{
public:

    /// Enumerates all the new and delete operators.
    enum OperatorName
    {
        Unknown,
        NewScalarThrow,
        NewScalarNoThrow,
        NewScalarPlacement,
        DeleteScalarWithSize,
        DeleteScalarNoThrow,
        DeleteScalarPlacement,
        NewArrayThrow,
        NewArrayNoThrow,
        NewArrayPlacement,
        DeleteArrayWithSize,
        DeleteArrayNoThrow,
        DeleteArrayPlacement,
    };

    /// Provides textual name for all new and delete operators.
    static const char * Name( OperatorName type )
    {
        switch ( type )
        {
            case NewScalarThrow:
                return "scalar throwing new operator";
            case NewScalarNoThrow:
                return "scalar nothrow new operator";
            case NewScalarPlacement:
                return "scalar placement new operator";
            case DeleteScalarWithSize:
                return "scalar delete operator with size";
            case DeleteScalarNoThrow:
                return "scalar nothrow delete operator";
            case DeleteScalarPlacement:
                return "scalar placement delete operator";
            case NewArrayThrow:
                return "array throwing new operator";
            case NewArrayNoThrow:
                return "array nothrow new operator";
            case NewArrayPlacement:
                return "array placement new operator";
            case DeleteArrayWithSize:
                return "array delete operator with size";
            case DeleteArrayNoThrow:
                return "array nothrow delete operator";
            case DeleteArrayPlacement:
                return "array placement delete operator";
        }
        return "Unknown";
    }

#ifdef _MSC_VER
    /// @note MSVC complains about non-empty exception specification lists.
    static void * operator new ( std::size_t size )
#else
    static void * operator new ( std::size_t size ) throw ( std::bad_alloc )
#endif
    {
        CheckCallType( NewScalarThrow, "new" );
        void * place = ::operator new( size );
        if ( s_verbose )
            cout << "static void * operator new ( std::size_t size ) throw ( std::bad_alloc )" << endl
                 << "\tsize = " << size << endl;
        cout << endl;
        return place;
    }

    static void * operator new ( std::size_t size, const std::nothrow_t & nt ) throw ()
    {
        s_triedNoThrowNew = true;
        CheckCallType( NewScalarNoThrow, "new" );
        void * place = ::operator new( size, nt );
        if ( s_verbose )
            cout << "static void * operator new ( std::size_t size," << endl
                 << "\tconst std::nothrow_t & nt ) throw ()" << endl
                 << "\tsize = " << size << endl;
        cout << endl;
        return place;
    }

    static void * operator new ( std::size_t size, void * place )
    {
        void * place2 = ::operator new( size, place );
        CheckCallType( NewScalarPlacement, "new" );
        if ( s_verbose )
            cout << "static void * operator new ( std::size_t size, void * place )" << endl
                 << "\tsize = " << size << endl
                 << "\tplace = " << place << endl
                 << "\treturn = " << place2 << endl;
        cout << endl;
        return place2;
    }

    /** @note This version of delete [] is commented out since the C++ Standard
     requires compilers to use the version of delete [] with the size parameter
     if that one is available and this one is not.
     */
//    static void operator delete ( void * place ) throw ()
//    {
//        CheckCallType( DeleteScalarNoSize, "delete" );
//        cout << "scalar delete operator" << endl;
//        if ( s_verbose )
//            cout << "static void operator delete ( void * place ) throw ()" << endl
//                 << "\tplace = " << place << endl;
//        cout << endl;
//        ::operator delete( place );
//    }

    static void operator delete ( void * place, std::size_t size ) throw ()
    {
        CheckCallType( DeleteScalarWithSize, "delete" );
        if ( s_verbose )
            cout << "static void operator delete ( void * place, std::size_t size ) throw ()" << endl
                 << "\tplace = " << place << endl
                 << "\tsize = " << size << endl;
        cout << endl;
        ::operator delete( place );
    }

    static void operator delete ( void * place, const std::nothrow_t & nt ) throw()
    {
        CheckCallType( DeleteScalarNoThrow, "delete" );
        if ( s_verbose )
            cout << "static void operator delete ( void * place," << endl
                 << "\tconst std::nothrow_t & nt ) throw()" << endl
                 << "\tplace = " << place << endl;
        cout << endl;
        ::operator delete( place, nt );
    }

    static void operator delete ( void * place1, void * place2 )
    {
        CheckCallType( DeleteScalarPlacement, "delete" );
        if ( s_verbose )
            cout << "static void operator delete ( void * place1, void * place2 )" << endl
                 << "\tplace1 = " << place1 << endl
                 << "\tplace2 = " << place2 << endl;
        cout << endl;
        ::operator delete( place1, place2 );
    }


#ifdef _MSC_VER
    /// @note MSVC complains about non-empty exception specification lists.
    static void * operator new [] ( std::size_t size )
#else
    static void * operator new [] ( std::size_t size ) throw ( std::bad_alloc )
#endif
    {
        s_newArraySize = size;
        CheckCallType( NewArrayThrow, "new []" );
        void * place = ::operator new [] ( size );
        if ( s_verbose )
           cout << "static void * operator new [] ( std::size_t size ) throw ( std::bad_alloc )" << endl
                 << "\tsize = " << size << endl;
        cout << endl;
        return place;
    }

    static void * operator new [] ( std::size_t size, const std::nothrow_t & nt ) throw ()
    {
        s_triedNoThrowNew = true;
        s_newArraySize = size;
        CheckCallType( NewArrayNoThrow, "new []" );
        void * place = ::operator new [] ( size, nt );
        if ( s_verbose )
            cout << "static void * operator new [] ( std::size_t size," << endl
                 << "\tconst std::nothrow_t & nt ) throw ()" << endl
                 << "\tsize = " << size << endl;
        cout << endl;
        return place;
    }

    static void * operator new [] ( std::size_t size, void * place )
    {
        CheckCallType( NewArrayPlacement, "new []" );
        void * place2 = ::operator new [] ( size, place );
        if ( s_verbose )
            cout << "static void * operator new [] ( std::size_t size, void * place )" << endl
                 << "\tsize = " << size << endl
                 << "\tplace = " << place << endl
                 << "\treturn = " << place2 << endl;
        cout << endl;
        return place2;
    }

    /** @note This version of delete [] is commented out since the C++ Standard
     requires compilers to use the version of delete [] with the size parameter
     if that one is available and this one is not.
     */
//    static void operator delete [] ( void * place ) throw ()
//    {
//        CheckCallType( DeleteArrayNoSize, "delete []" );
//        if ( s_verbose )
//            cout << "static void operator delete [] ( void * place ) throw ()" << endl
//                 << "\tplace = " << place << endl;
//        cout << endl;
//        ::operator delete [] ( place );
//    }

    static void operator delete [] ( void * place, std::size_t size ) throw ()
    {
        s_deleteArraySize = size;
        CheckCallType( DeleteArrayWithSize, "delete []" );
        if ( s_verbose )
            cout << "static void operator delete [] ( void * place, std::size_t size ) throw ()" << endl
                 << "\tplace = " << place << endl
                 << "\tsize = " << size << endl;
        if ( s_newArraySize != size )
        {
            cout << "\tERROR: The size parameter should be: " << s_newArraySize << '!' << endl;
            s_errorCount++;
        }
        cout << endl;
        ::operator delete [] ( place );
    }

    static void operator delete [] ( void * place, const std::nothrow_t & nt ) throw()
    {
        CheckCallType( DeleteArrayNoThrow, "delete []" );
        if ( s_verbose )
            cout << "static void operator delete [] ( void * place," << endl
                 << "\tconst std::nothrow_t & nt ) throw()" << endl
                 << "\tplace = " << place << endl;
        cout << endl;
        ::operator delete [] ( place, nt );
    }

    static void operator delete [] ( void * place1, void * place2 )
    {
        CheckCallType( DeleteArrayPlacement, "delete []" );
        if ( s_verbose )
            cout << "static void operator delete [] ( void * place1, void * place2 )" << endl
                 << "\tplace1 = " << place1 << endl
                 << "\tplace2 = " << place2 << endl;
        cout << endl;
        ::operator delete [] ( place1, place2 );
    }

    static void OutputArraySizeInfo( void );

    inline static void Clear( void )
    {
        s_newArraySize = 0;
        s_deleteArraySize = 0;
    }

    inline static void SetConstructorToThrow( bool b ) { s_throw = b; }

    inline static bool WillConstructorThrow( void ) { return s_throw; }

    Bee( void ) : m_legs( 6 )
    {
        if ( s_throw )
        {
            s_expectedCall = ( NewArrayNoThrow == s_expectedCall ) ?
                DeleteArrayNoThrow : DeleteScalarNoThrow;
            throw BadBee( "Bee died before it hatched." );
        }
    }

    ~Bee( void ) {}

    inline static unsigned int GetErrorCount( void ) { return s_errorCount; }
    inline static void IncrementErrorCount( void ) { ++s_errorCount; }

    static OperatorName s_expectedCall;

private:
    static std::size_t s_newArraySize;
    static std::size_t s_deleteArraySize;
    static unsigned int s_errorCount;
    static bool s_triedNoThrowNew;
    static bool s_throw;

    static void CheckCallType( OperatorName actual, const char * name )
    {
        cout << Name( actual ) << endl;
        if ( s_expectedCall != actual )
        {
            s_errorCount++;
            cout << "\tERROR!  The wrong " << name << " operator was called!" << endl
                 << "\tExpected " << Name( s_expectedCall ) << " instead!" << endl;
        }
    }

    unsigned int m_legs;
};

// ----------------------------------------------------------------------------

Bee::OperatorName Bee::s_expectedCall = Bee::Unknown;
std::size_t Bee::s_newArraySize = 0;
std::size_t Bee::s_deleteArraySize = 0;
unsigned int Bee::s_errorCount = 0;
bool Bee::s_triedNoThrowNew = false;
bool Bee::s_throw = false;

// ----------------------------------------------------------------------------

void Bee::OutputArraySizeInfo( void )
{
    cout << endl;
    if ( ( 0 == s_newArraySize ) || ( 0 == s_deleteArraySize ) )
        cout << "I do not have sufficient information to know if your compiler complies" << endl
             << "with Section 12.5/5 of the C++ Standard.  You should not use Loki to" << endl
             << "allocate arrays.  Please do not #define LOKI_SMALL_OBJECT_USE_NEW_ARRAY." << endl;
    else if ( s_newArraySize == s_deleteArraySize )
        cout << "Your compiler provides correct value for delete [] operator.  You may use" << endl
             << "Loki to allocate arrays via #define LOKI_SMALL_OBJECT_USE_NEW_ARRAY.  If" << endl
             << "you do, please run the SmallObjBench tests to see if Loki is faster or" << endl
             << "slower at allocating arrays than the default allocator." << endl
             << endl;
    else
        cout << "Your compiler does NOT provide correct size value for delete [] operator." << endl
             << "It should provide the same size value to delete [] as it did to new []." << endl
             << "Please ask your compiler vendor to comply with Section 12.5/5 of the C++" << endl
             << "Standard.  You should NOT use Loki to allocate arrays.  Please do *not*" << endl
             << "#define LOKI_SMALL_OBJECT_USE_NEW_ARRAY." << endl
             << endl;
    cout << endl;
}

// ----------------------------------------------------------------------------

const char * GetCompilerName( void )
{
    /** @note This list of predefined compiler version macros comes from
      http://predef.sourceforge.net/precomp.html  Feel free to update this
      function to add specific version numbers or add other compilers.
     */
#if (__INTEL_COMPILER)
    return "Intel";

#elif (__ICC)
    return "Intel";

#elif (__KCC)
    return "Intel's KAI C++";

#elif (__MINGW32__)
    return "MinGW";

#elif (__COMO__)
    return "Comeau C++";

#elif (__DECC)
    return "Compaq C/C++";

#elif (VAXC)
    return "Compaq C/C++";

#elif (__VAXC)
    return "Compaq C/C++";

#elif (_CRAYC)
    return "Cray C/C++";

#elif (__CYGWIN__)
    return "Cygwin";

#elif (__DCC__)
    return "Diab C/C++";

#elif (__DMC__)
    return "Digital Mars";

#elif (__SC__)
    return "Digital Mars";

#elif (__ZTC__)
    return "Digital Mars";

#elif (__EDG__)
    return "EDG C++ Front End";

#elif (__GNUC__)
    return "Gnu C/C++";

#elif (__HP_cc)
    return "HP ANSI C/aC++";

#elif (__HP_aCC)
    return "HP ANSI C/aC++";

#elif (__xlC__)
    return "IBM XL C/C++";

#elif (__IBMC__)
    return "IBM XL C/C++";

#elif (__IBMCPP__)
    return "IBM XL C/C++";

#elif (LCC)
    return "LCC";

#elif (__HIGHC__)
    return "MetaWare High C/C++";

#elif (sgi)
    return "MIPSpro";

#elif (__sgi)
    return "MIPSpro";

#elif (__MRC__)
    return "MPW C++";

#elif (MPW_C)
    return "MPW C++";

#elif (MPW_CPLUS)
    return "MPW C++";

#elif (__CC_NORCROFT)
    return "Norcroft C";

#elif (__POCC__)
    return "Pelles C";

#elif (SASC)
    return "SAS/C";

#elif (__SASC)
    return "SAS/C";

#elif (__SASC__)
    return "SAS/C";

#elif (_SCO_DS)
    return "SCO";

#elif (__SUNPRO_C)
    return "Sun Workshop C/C++";

#elif (__SUNPRO_CC)
    return "Sun Workshop C/C++";

#elif (__TenDRA__)
    return "TenDRA C/C++";

#elif (__TINYC__)
    return "Tiny C";

#elif (__USLC__)
    return "USL C";

#elif (__WATCOMC__)
    return "Watcom C++";

#elif (__MWERKS__)
    return "MetroWerks CodeWarrior";

#elif (__TURBOC__)
    return "Borland Turbo C";

#elif (__BORLANDC__)
    return "Borland C++";

#elif (_MSC_VER >= 1400)
    return "Microsoft 8.0 or higher";

#elif (_MSC_VER >= 1300)
    return "Microsoft 7";

#elif (_MSC_VER >= 1200)
    return "Microsoft 6";

#elif (_MSC_VER)
    return "Microsoft, but a version lower than 6";

#else
    return "an Unknown type";
#endif
}

// ----------------------------------------------------------------------------

void OutputCompilerType( void )
{
    cout << "Your compiler is " << GetCompilerName() << '.' << endl << endl;

    const bool zeroSize = ( 0 == sizeof(EmptyThing) );
    if ( zeroSize )
    {
        cout << "Your compiler allows datatypes to be zero bytes, which is contrary to" << endl;
        cout << "the ISO C++ Standard." << endl;
    }
    else
    {
        cout << "Your compiler correctly sets the sizeof empty data types to "
             << sizeof(EmptyThing) << " byte(s) instead of zero bytes." << endl;
    }
    cout << "( sizeof(EmptyThing) == " << sizeof(EmptyThing) << " )" << endl << endl;
}

// ----------------------------------------------------------------------------

void RunTests( void )
{

    char localQueen[ sizeof(Bee) ];
    char localHive[ sizeof(Bee) * ArrayCount + ArrayOverhead ];
    void * here = localQueen;

    // test throwing new
    if ( s_verbose )
        cout << "Bee * queen = new Bee;" << endl;
    Bee::s_expectedCall = Bee::NewScalarThrow;
    Bee * queen = new Bee;
    if ( s_verbose )
        cout << "delete queen;" << endl;
    // test normal delete
    Bee::s_expectedCall = Bee::DeleteScalarWithSize;
    delete queen;

    // test throwing new []
    if ( s_verbose )
        cout << "Bee * hive = new Bee [ ArrayCount ];" << endl;
    Bee::s_expectedCall = Bee::NewArrayThrow;
    Bee * hive = new Bee [ ArrayCount ];
    if ( s_verbose )
        cout << "delete [] hive;" << endl;
    // test normal delete []
    Bee::s_expectedCall = Bee::DeleteArrayWithSize;
    delete [] hive;
    Bee::OutputArraySizeInfo();

    // test nothrow new
    if ( s_verbose )
        cout << "Bee * queen = new nothrow Bee;" << endl;
    Bee::s_expectedCall = Bee::NewScalarNoThrow;
    queen = new (nothrow) Bee;
    if ( s_verbose )
        cout << "delete queen;" << endl;
    // test normal delete
    Bee::s_expectedCall = Bee::DeleteScalarWithSize;
    delete queen;

    // test nothrow new []
    if ( s_verbose )
        cout << "Bee * hive = new (nothrow) Bee [ 1000 ];" << endl;
    Bee::s_expectedCall = Bee::NewArrayNoThrow;
    hive = new (nothrow) Bee [ ArrayCount ];
    if ( s_verbose )
        cout << "delete [] hive;" << endl;
    // test normal delete []
    Bee::s_expectedCall = Bee::DeleteArrayWithSize;
    delete [] hive;

    Bee::Clear();
    Bee::SetConstructorToThrow( true );
    std::nothrow_t nothrow;

    try
    {
        // test nothrow new when constructor throws.
        if ( s_verbose )
            cout << "Bee * queen = new nothrow Bee;" << endl;
        Bee::s_expectedCall = Bee::NewScalarNoThrow;
        queen = new (nothrow) Bee;
        if ( s_verbose )
            cout << "delete queen;" << endl;
        // test normal delete
        delete queen;
    }
    catch ( const std::exception & ex0 )
    {
        // nothrow delete should be called before catch block starts
        if ( s_verbose )
            cout << "catch ( const std::exception & ex0 )" << endl
                 << "\t" << ex0.what() << endl;
    }

    try
    {
        // test nothrow new [] when constructor throws.
        if ( s_verbose )
            cout << "Bee * hive = new (nothrow) Bee [ 1000 ];" << endl;
        Bee::s_expectedCall = Bee::NewArrayNoThrow;
        hive = new (nothrow) Bee [ ArrayCount ];
        if ( s_verbose )
            cout << "delete queen;" << endl;
        // test normal delete
        delete [] hive;
    }
    catch ( const std::exception & ex1 )
    {
        // nothrow delete should be called before catch block starts
        if ( s_verbose )
            cout << "catch ( const std::exception & ex0 )" << endl
                 << "\t" << ex1.what() << endl;
    }
    Bee::SetConstructorToThrow( false );

    // test placement new
    if ( s_verbose )
        cout << "Bee * queen = new (here) Bee;" << endl;
    Bee::s_expectedCall = Bee::NewScalarPlacement;
    queen = new (here) Bee;
    if ( s_verbose )
        cout << "delete (here, queen);" << endl;
    // test placement delete;
    Bee::s_expectedCall = Bee::DeleteScalarPlacement;
    delete (here, queen);

    // test placement new []
    here = localHive;
    if ( s_verbose )
        cout << "Bee * hive = new (here) Bee [ ArrayCount ];" << endl;
    Bee::s_expectedCall = Bee::NewArrayPlacement;
    hive = new (here) Bee [ ArrayCount ];
    if ( s_verbose )
        cout << "delete [] (here, hive);" << endl;
    // test placement delete [];
    Bee::s_expectedCall = Bee::DeleteArrayPlacement;
    delete [] (here, hive);

}

// ----------------------------------------------------------------------------

int main( unsigned int argc, const char * const argv[] )
{

    bool caught = false;
    for ( unsigned int aa = 1; aa < argc; ++aa )
    {
        if ( ::strcmp( argv[aa], "-v" ) == 0 )
            s_verbose = true;
    }

    OutputCompilerType();
    try
    {
        RunTests();
    }
    catch ( const std::bad_alloc & ex1 )
    {
        caught = true;
        if ( s_verbose )
            cout << "catch ( const std::bad_alloc & ex1 )" << endl
                 << "\t" << ex1.what() << endl;
    }
    catch ( const std::exception & ex2 )
    {
        caught = true;
        if ( s_verbose )
            cout << "catch ( const std::exception & ex2 )" << endl
                 << "\t" << ex2.what() << endl;
    }
    catch ( ... )
    {
        caught = true;
        if ( s_verbose )
            cout << "catch ( ... )" << endl;
    }

    if ( caught )
    {
        Bee::IncrementErrorCount();
        cout << "Tests of default new and delete operators aborted because of exception!"
             << endl;
    }

    cout << "Done running tests of default allocators." << endl;
    cout << "Total errors detected: " << Bee::GetErrorCount() << endl;

    return 0;
}

// ----------------------------------------------------------------------------

// $Log: DefaultAlloc.cpp,v $
// Revision 1.1  2005/10/13 00:40:38  rich_sposato
// Added program to test how compiler uses default new and delete operators.
//