18 - Language support library [lib.language.support]

-1- This clause describes the function signatures that are called implicitly, and the types of objects generated implicitly, during the execution of some C++ programs. It also describes the headers that declare these function signatures and define any related types.

-2- The following subclauses describe common type definitions used throughout the library, characteristics of the predefined types, functions supporting start and termination of a C++ program, support for dynamic memory management, support for dynamic type identification, support for exception processing, and other runtime support, as summarized in Table ??:

Language support library summary
SubclauseHeader(s)
lib.support.types Types<cstddef>
lib.support.limits Implementation properties<limits>
 <climits>
 <cfloat>
lib.support.start.term Start and termination<cstdlib>
lib.support.dynamic Dynamic memory management<new>
lib.support.rtti Type identification<typeinfo>
lib.support.exception Exception handling<exception>
lib.support.runtime Other runtime support<cstdarg>
 <csetjmp>
 <ctime>
 <csignal>
 <cstdlib>

18.1 - Types [lib.support.types]

-1- Common definitions.

-2- Header <cstddef> (Table ??):

Header <cstddef> synopsis
KindName(s)
Macros:NULLoffsetof
Types:ptrdiff_tsize_t

-3- The contents are the same as the Standard C library header <stddef.h>, with the following changes:

-4- The macro NULL is an implementation-defined C++ null pointer constant in this International Standard (conv.ptr).*

[Footnote: Possible definitions include 0 and 0L, but not (void*)0. --- end foonote]

-5- The macro offsetof accepts a restricted set of type arguments in this International Standard. type shall be a POD structure or a POD union (clause class). The result of applying the offsetof macro to a field that is a static data member or a function member is undefined.

See also subclause expr.sizeof, Sizeof, subclause expr.add, Additive operators, subclause class.free, Free store, and ISO C subclause 7.1.6.

18.2 - Implementation properties [lib.support.limits]

-1- The headers <limits>, <climits>, and <cfloat> supply characteristics of implementation-dependent fundamental types (basic.fundamental).

18.2.1 - Numeric limits [lib.limits]

-1- The numeric_limits component provides a C++ program with information about various properties of the implementation's representation of the fundamental types.

-2- Specializations shall be provided for each fundamental type, both floating point and integer, including bool. The member is_specialized shall be true for all such specializations of numeric_limits.

-3- For all members declared static const in the numeric_limits template, specializations shall define these values in such a way that they are usable as integral constant expressions.

-4- Non-fundamental standard types, such as complex<T> (lib.complex), shall not have specializations.

Header <limits> synopsis

namespace std {
  template<class T> class numeric_limits;
  enum float_round_style;
  enum float_denorm_style;

  template<> class numeric_limits<bool>;

  template<> class numeric_limits<char>;
  template<> class numeric_limits<signed char>;
  template<> class numeric_limits<unsigned char>;
  template<> class numeric_limits<wchar_t>;

  template<> class numeric_limits<short>;
  template<> class numeric_limits<int>;
  template<> class numeric_limits<long>;
  template<> class numeric_limits<unsigned short>;
  template<> class numeric_limits<unsigned int>;
  template<> class numeric_limits<unsigned long>;

  template<> class numeric_limits<float>;
  template<> class numeric_limits<double>;
  template<> class numeric_limits<long double>;
}

18.2.1.1 - Template class numeric_limits [lib.numeric.limits]

namespace std {
  template<class T> class numeric_limits {
  public:
    static const bool is_specialized = false;
    static T min() throw();
    static T max() throw();
    static const int  digits = 0;
    static const int  digits10 = 0;
    static const bool is_signed = false;
    static const bool is_integer = false;
    static const bool is_exact = false;
    static const int  radix = 0;
    static T epsilon() throw();
    static T round_error() throw();
    static const int  min_exponent = 0;
    static const int  min_exponent10 = 0;
    static const int  max_exponent = 0;
    static const int  max_exponent10 = 0;

    static const bool has_infinity = false;
    static const bool has_quiet_NaN = false;
    static const bool has_signaling_NaN = false;
    static const float_denorm_style has_denorm = denorm_absent;
    static const bool has_denorm_loss = false;
    static T infinity() throw();
    static T quiet_NaN() throw();
    static T signaling_NaN() throw();
    static T denorm_min() throw();

    static const bool is_iec559 = false;
    static const bool is_bounded = false;
    static const bool is_modulo = false;

    static const bool traps = false;
    static const bool tinyness_before = false;
    static const float_round_style round_style = round_toward_zero;
  };
}

-1- The member is_specialized makes it possible to distinguish between fundamental types, which have specializations, and non-scalar types, which do not.

-2- The default numeric_limits<T> template shall have all members, but with 0 or false values.

18.2.1.2 - numeric_limits members [lib.numeric.limits.members]

static T min() throw();

-1- Minimum finite value.*

[Footnote: Equivalent to CHAR_MIN, SHRT_MIN, FLT_MIN, DBL_MIN, etc. --- end foonote]

-2- For floating types with denormalization, returns the minimum positive normalized value.

-3- Meaningful for all specializations in which is_bounded != false, or is_bounded == false && is_signed == false.

static T max() throw();

-4- Maximum finite value.*

[Footnote: Equivalent to CHAR_MAX, SHRT_MAX, FLT_MAX, DBL_MAX, etc. --- end foonote]

-5- Meaningful for all specializations in which is_bounded != false.

static const int  digits;

-6- Number of radix digits that can be represented without change.

-7- For built-in integer types, the number of non-sign bits in the representation.

-8- For floating point types, the number of radix digits in the mantissa.*

[Footnote: Equivalent to FLT_MANT_DIG, DBL_MANT_DIG, LDBL_MANT_DIG. --- end foonote]
static const int  digits10;

-9- Number of base 10 digits that can be represented without change.*

[Footnote: Equivalent to FLT_DIG, DBL_DIG, LDBL_DIG. --- end foonote]

-10- Meaningful for all specializations in which is_bounded != false.

static const bool is_signed;

-11- True if the type is signed.

-12- Meaningful for all specializations.

static const bool is_integer;

-13- True if the type is integer.

-14- Meaningful for all specializations.

static const bool is_exact;

-15- True if the type uses an exact representation. All integer types are exact, but not all exact types are integer. For example, rational and fixed-exponent representations are exact but not integer.

-16- Meaningful for all specializations.

static const int  radix;

-17- For floating types, specifies the base or radix of the exponent representation (often 2).*

[Footnote: Equivalent to FLT_RADIX. --- end foonote]

-18- For integer types, specifies the base of the representation.*

[Footnote: Distinguishes types with bases other than 2 (e.g. BCD). --- end foonote]

-19- Meaningful for all specializations.

static T epsilon() throw();
Machine epsilon: the difference between 1 and the least value greater than 1 that is representable.*
[Footnote: Equivalent to FLT_EPSILON, DBL_EPSILON, LDBL_EPSILON. --- end foonote]
Meaningful for all floating point types.
static T round_error() throw();
Measure of the maximum rounding error.*
[Footnote: Rounding error is described in ISO/IEC 10967-1 Language independent arithmetic - Part 1 Section 5.2.8 and Annex A Rationale Section A.5.2.8 - Rounding constants. --- end foonote]
static const int  min_exponent;
Minimum negative integer such that radix raised to the power of one less than that integer is a normalized floating point number.*
[Footnote: Equivalent to FLT_MIN_EXP, DBL_MIN_EXP, LDBL_MIN_EXP. --- end foonote]
Meaningful for all floating point types.
static const int  min_exponent10;
Minimum negative integer such that 10 raised to that power is in the range of normalized floating point numbers.*
[Footnote: Equivalent to FLT_MIN_10_EXP, DBL_MIN_10_EXP, LDBL_MIN_10_EXP. --- end foonote]
Meaningful for all floating point types.
static const int  max_exponent;
Maximum positive integer such that radix raised to the power one less than that integer is a representable finite floating point number.*
[Footnote: Equivalent to FLT_MAX_EXP, DBL_MAX_EXP, LDBL_MAX_EXP. --- end foonote]
Meaningful for all floating point types.
static const int  max_exponent10;
Maximum positive integer such that 10 raised to that power is in the range of representable finite floating point numbers.*
[Footnote: Equivalent to FLT_MAX_10_EXP, DBL_MAX_10_EXP, LDBL_MAX_10_EXP. --- end foonote]
Meaningful for all floating point types.
static const bool has_infinity;
True if the type has a representation for positive infinity. Meaningful for all floating point types. Shall be true for all specializations in which is_iec559 != false.
static const bool has_quiet_NaN;
True if the type has a representation for a quiet (non-signaling) ``Not a Number.''*
[Footnote: Required by LIA-1. --- end foonote]
Meaningful for all floating point types. Shall be true for all specializations in which is_iec559 != false.
static const bool has_signaling_NaN;
True if the type has a representation for a signaling ``Not a Number.''*
[Footnote: Required by LIA-1. --- end foonote]
Meaningful for all floating point types. Shall be true for all specializations in which is_iec559 != false.
static const float_denorm_style has_denorm;
denorm_present if the type allows denormalized values (variable number of exponent bits)*,
[Footnote: Required by LIA-1. --- end foonote]
denorm_absent if the type does not allow denormalized values, and denorm_indeterminate if it is indeterminate at compile time whether the type allows denormalized values. Meaningful for all floating point types.
static const bool has_denorm_loss;
True if loss of accuracy is detected as a denormalization loss, rather than as an inexact result.*
[Footnote: See IEC 559. --- end foonote]
static T infinity() throw();
Representation of positive infinity, if available.*
[Footnote: Required by LIA-1. --- end foonote]
Meaningful for all specializations for which has_infinity != false. Required in specializations for which is_iec559 != false.
static T quiet_NaN() throw();
Representation of a quiet ``Not a Number,'' if available.*
[Footnote: Required by LIA-1. --- end foonote]
Meaningful for all specializations for which has_quiet_NaN != false. Required in specializations for which is_iec559 != false.
static T signaling_NaN() throw();
Representation of a signaling ``Not a Number,'' if available.*
[Footnote: Required by LIA-1. --- end foonote]
Meaningful for all specializations for which has_signaling_NaN != false. Required in specializations for which is_iec559 != false.
static T denorm_min() throw();
Minimum positive denormalized value.*
[Footnote: Required by LIA-1. --- end foonote]
Meaningful for all floating point types. In specializations for which has_denorm == false, returns the minimum positive normalized value.
static const bool is_iec559;
True if and only if the type adheres to IEC 559 standard.*
[Footnote: International Electrotechnical Commission standard 559 is the same as IEEE 754. --- end foonote]
Meaningful for all floating point types.
static const bool is_bounded;
True if the set of values representable by the type is finite.*
[Footnote: Required by LIA-1. --- end foonote]
All built-in types are bounded, this member would be false for arbitrary precision types. Meaningful for all specializations.
static const bool is_modulo;
True if the type is modulo.*
[Footnote: Required by LIA-1. --- end foonote]
A type is modulo if it is possible to add two positive numbers and have a result that wraps around to a third number that is less. Generally, this is false for floating types, true for unsigned integers, and true for signed integers on most machines. Meaningful for all specializations.
static const bool traps;
true if trapping is implemented for the type.*
[Footnote: Required by LIA-1. --- end foonote]
Meaningful for all specializations.
static const bool tinyness_before;
true if tinyness is detected before rounding.*
[Footnote: Refer to IEC 559. Required by LIA-1. --- end foonote]
Meaningful for all floating point types.
static const float_round_style round_style;
The rounding style for the type.*
[Footnote: Equivalent to FLT_ROUNDS. Required by LIA-1. --- end foonote]
Meaningful for all floating point types. Specializations for integer types shall return round_toward_zero.

18.2.1.3 - Type float_round_style [lib.round.style]

namespace std {
  enum float_round_style {
    round_indeterminate       = -1,
    round_toward_zero         =  0,
    round_to_nearest          =  1,
    round_toward_infinity     =  2,
    round_toward_neg_infinity =  3
  };
}

-1- The rounding mode for floating point arithmetic is characterized by the values:

  • round_indeterminate if the rounding style is indeterminable
  • round_toward_zero if the rounding style is toward zero
  • round_to_nearest if the rounding style is to the nearest representable value
  • round_toward_infinity if the rounding style is toward infinity
  • round_toward_neg_infinity if the rounding style is toward negative infinity

18.2.1.4 - Type float_denorm_style [lib.denorm.style]

namespace std {
  enum float_denorm_style {
    denorm_indeterminate = -1;
    denorm_absent = 0;
    denorm_present = 1;
  };
}

-1- The presence or absence of denormalization (variable number of exponent bits) is characterized by the values:

  • denorm_indeterminate if it cannot be determined whether or not the type allows denormalized values
  • denorm_absent if the type does not allow denormalized values
  • denorm_present if the type does allow denormalized values

18.2.1.5 - numeric_limits specializations [lib.numeric.special]

-1- All members shall be provided for all specializations. However, many values are only required to be meaningful under certain conditions (for example, epsilon() is only meaningful if is_integer is false). Any value that is not ``meaningful'' shall be set to 0 or false.

-2- [Example:

namespace std {
  template<> class numeric_limits<float> {
  public:
    static const bool is_specialized = true;
    inline static float min() throw() { return 1.17549435E-38F; }
    inline static float max() throw() { return 3.40282347E+38F; }
    static const int digits   = 24;
    static const int digits10 =  6;
    static const bool is_signed  = true;
    static const bool is_integer = false;
    static const bool is_exact   = false;
    static const int radix = 2;
    inline static float epsilon() throw()     { return 1.19209290E-07F; }
    inline static float round_error() throw() { return 0.5F; }
    static const int min_exponent   = -125;
    static const int min_exponent10 = - 37;
    static const int max_exponent   = +128;
    static const int max_exponent10 = + 38;
    static const bool has_infinity             = true;
    static const bool has_quiet_NaN            = true;
    static const bool has_signaling_NaN        = true;
    static const float_denorm_style has_denorm = denorm_absent;
    static const bool has_denorm_loss          = false;
    inline static float infinity()      throw() { return ...; }
    inline static float quiet_NaN()     throw() { return ...; }
    inline static float signaling_NaN() throw() { return ...; }
    inline static float denorm_min()    throw() { return min(); }
    static const bool is_iec559  = true;
    static const bool is_bounded = true;
    static const bool is_modulo  = false;
    static const bool traps      = true;
    static const bool tinyness_before = true;
    static const float_round_style round_style = round_to_nearest;
  };
}

--- end example]

18.2.2 - C Library [lib.c.limits]

-1- Header <climits> (Table ??):

Header <climits> synopsis
TypeName(s)
Values:
CHAR_BITINT_MAXLONG_MINSCHAR_MINUCHAR_MAXUSHRT_MAX
CHAR_MAXINT_MINMB_LEN_MAXSHRT_MAXUINT_MAX
CHAR_MINLONG_MAXSCHAR_MAXSHRT_MINULONG_MAX

-2- The contents are the same as the Standard C library header <limits.h>.

-3- Header <cfloat> (Table ??):

Header <cfloat> synopsis
TypeName(s)
Values:
DBL_DIGDBL_MIN_EXPFLT_MIN_10_EXPLDBL_MAX_10_EXP
DBL_EPSILONFLT_DIGFLT_MIN_EXPLDBL_MAX_EXP
DBL_MANT_DIGFLT_EPSILONFLT_RADIXLDBL_MIN
DBL_MAXFLT_MANT_DIGFLT_ROUNDSLDBL_MIN_10_EXP
DBL_MAX_10_EXPFLT_MAXLDBL_DIGLDBL_MIN_EXP
DBL_MAX_EXPFLT_MAX_10_EXPLDBL_EPSILON
DBL_MINFLT_MAX_EXPLDBL_MANT_DIG
DBL_MIN_10_EXPFLT_MINLDBL_MAX

-4- The contents are the same as the Standard C library header <float.h>.

See also ISO C subclause 7.1.5, 5.2.4.2.2, 5.2.4.2.1.

18.3 - Start and termination [lib.support.start.term]

-1- Header <cstdlib> (partial), Table ??:

Header <cstdlib> synopsis
TypeName(s)
Macros:EXIT_FAILUREEXIT_SUCCESS
Functions:abortatexitexit

-2- The contents are the same as the Standard C library header <stdlib.h>, with the following changes:

abort(void)

-3- The function abort() has additional behavior in this International Standard:

  • The program is terminated without executing destructors for objects of automatic or static storage duration and without calling the functions passed to atexit() (basic.start.term).
extern "C" int atexit(void (* f )(void))
extern "C++" int atexit(void (* f )(void))

-4- Effects: The atexit() functions register the function pointed to by f, to be called without arguments at normal program termination.

-5- For the execution of a function registered with atexit(), if control leaves the function because it provides no handler for a thrown exception, terminate() is called (lib.terminate).

-6- Implementation Limits: The implementation shall support the registration of at least 32 functions.

-7- Returns: The atexit() function returns zero if the registration succeeds, nozero if it fails.

exit(int  status )

-8- The function exit() has additional behavior in this International Standard:

  • First, objects with static storage duration are destroyed and functions registered by calling atexit are called. Objects with static storage duration are destroyed in the reverse order of the completion of their constructor. (Automatic objects are not destroyed as a result of calling exit().)*
    [Footnote: Objects with automatic storage duration are all destroyed in a program whose function main() contains no automatic objects and executes the call to exit(). Control can be transferred directly to such a main() by throwing an exception that is caught in main(). --- end foonote]
    Functions registered with atexit are called in the reverse order of their registration.*
    [Footnote: A function is called for every time it is registered. --- end foonote]
    A function registered with atexit before an object obj1 of static storage duration is initialized will not be called until obj1's destruction has completed. A function registered with atexit after an object obj2 of static storage duration is initialized will be called before obj2's destruction starts.
  • Next, all open C streams (as mediated by the function signatures declared in <cstdio>) with unwritten buffered data are flushed, all open C streams are closed, and all files created by calling tmpfile() are removed.*
    [Footnote: Any C streams associated with cin, cout, etc (lib.iostream.objects) are flushed and closed when static objects are destroyed in the previous phase. The function tmpfile() is declared in <cstdio>. --- end foonote]
  • Finally, control is returned to the host environment. If status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned. If status is EXIT_FAILURE, an implementation-defined form of the status unsuccessful termination is returned. Otherwise the status returned is implementation-defined.*
    [Footnote: The macros EXIT_FAILURE and EXIT_SUCCESS are defined in <cstdlib>. --- end foonote]

-9- The function exit() never returns to its caller.

See also subclauses basic.start, basic.start.term, ISO C subclause 7.10.4.

18.4 - Dynamic memory management [lib.support.dynamic]

-1- The header <new> defines several functions that manage the allocation of dynamic storage in a program. It also defines components for reporting storage management errors.

Header <new> synopsis

namespace std {
  class bad_alloc;
  struct nothrow_t {};
  extern const nothrow_t nothrow;
  typedef void (*new_handler)();
  new_handler set_new_handler(new_handler new_p) throw();
}
  void* operator new(std::size_t size) throw(std::bad_alloc);
  void* operator new(std::size_t size, const std::nothrow_t&) throw();
  void  operator delete(void* ptr) throw();
  void  operator delete(void* ptr, const std::nothrow_t&) throw();
  void* operator new[](std::size_t size) throw(std::bad_alloc);
  void* operator new[](std::size_t size, const std::nothrow_t&) throw();
  void  operator delete[](void* ptr) throw();
  void  operator delete[](void* ptr, const std::nothrow_t&) throw();
  void* operator new  (std::size_t size, void* ptr) throw();
  void* operator new[](std::size_t size, void* ptr) throw();
  void  operator delete  (void* ptr, void*) throw();
  void  operator delete[](void* ptr, void*) throw();

See also intro.memory, basic.stc.dynamic, expr.new, expr.delete, class.free, lib.memory.

18.4.1 - Storage allocation and deallocation [lib.new.delete]

18.4.1.1 - Single-object forms [lib.new.delete.single]

void* operator new(std::size_t size) throw(std::bad_alloc);

-1- Effects: The allocation function (basic.stc.dynamic.allocation) called by a new-expression (expr.new) to allocate size bytes of storage suitably aligned to represent any object of that size.

-2- Replaceable: a C++ program may define a function with this function signature that displaces the default version defined by the C++ Standard library.

-3- Required behavior: Return a non-null pointer to suitably aligned storage (basic.stc.dynamic), or else throw a bad_alloc exception. This requirement is binding on a replacement version of this function.

-4- Default behavior:

  • Executes a loop: Within the loop, the function first attempts to allocate the requested storage. Whether the attempt involves a call to the Standard C library function malloc is unspecified.
  • Returns a pointer to the allocated storage if the attempt is successful. Otherwise, if the last argument to set_new_handler() was a null pointer, throw bad_alloc.
  • Otherwise, the function calls the current new_handler (lib.new.handler). If the called function returns, the loop repeats.
  • The loop terminates when an attempt to allocate the requested storage is successful or when a called new_handler function does not return.
void* operator new(std::size_t size, const std::nothrow_t&) throw();

-5- Effects: Same as above, except that it is called by a placement version of a new-expression when a C++ program prefers a null pointer result as an error indication, instead of a bad_alloc exception.

-6- Replaceable: a C++ program may define a function with this function signature that displaces the default version defined by the C++ Standard library.

-7- Required behavior: Return a non-null pointer to suitably aligned storage (basic.stc.dynamic), or else return a null pointer. This nothrow version of operator new returns a pointer obtained as if acquired from the ordinary version. This requirement is binding on a replacement version of this function.

-8- Default behavior:

  • Executes a loop: Within the loop, the function first attempts to allocate the requested storage. Whether the attempt involves a call to the Standard C library function malloc is unspecified.
  • Returns a pointer to the allocated storage if the attempt is successful. Otherwise, if the last argument to set_new_handler() was a null pointer, return a null pointer.
  • Otherwise, the function calls the current new_handler (lib.new.handler). If the called function returns, the loop repeats.
  • The loop terminates when an attempt to allocate the requested storage is successful or when a called new_handler function does not return. If the called new_handler function terminates by throwing a bad_alloc exception, the function returns a null pointer.

-9- [Example:

T* p1 = new T;                  //  throws  bad_alloc  if it fails
T* p2 = new(nothrow) T;         //  returns  0  if it fails

--- end example]
void operator delete(void* ptr) throw();
void operator delete(void* ptr, const std::nothrow_t&) throw();

-10- Effects: The deallocation function (basic.stc.dynamic.deallocation) called by a delete-expression to render the value of ptr invalid.

-11- Replaceable: a C++ program may define a function with this function signature that displaces the default version defined by the C++ Standard library.

-12- Required behavior: accept a value of ptr that is null or that was returned by an earlier call to the default operator new(std::size_t) or operator new(std::size_t,const std::nothrow_t&).

-13- Default behavior:

  • For a null value of ptr , do nothing.
  • Any other value of ptr shall be a value returned earlier by a call to the default operator new, which was not invalidated by an intervening call to operator delete(void*) (lib.res.on.arguments). For such a non-null value of ptr , reclaims storage allocated by the earlier call to the default operator new.

-14- Notes: It is unspecified under what conditions part or all of such reclaimed storage is allocated by a subsequent call to operator new or any of calloc, malloc, or realloc, declared in <cstdlib>.

18.4.1.2 - Array forms [lib.new.delete.array]

void* operator new[](std::size_t size) throw(std::bad_alloc);

-1- Effects: The allocation function (basic.stc.dynamic.allocation) called by the array form of a new-expression (expr.new) to allocate size bytes of storage suitably aligned to represent any array object of that size or smaller.*

[Footnote: It is not the direct responsibility of operator new[](std::size_t) or operator delete[](void*) to note the repetition count or element size of the array. Those operations are performed elsewhere in the array new and delete expressions. The array new expression, may, however, increase the size argument to operator new[](std::size_t) to obtain space to store supplemental information. --- end foonote]

-2- Replaceable: a C++ program can define a function with this function signature that displaces the default version defined by the C++ Standard library.

-3- Required behavior: Same as for operator new(std::size_t). This requirement is binding on a replacement version of this function.

-4- Default behavior: Returns operator new( size ).

void* operator new[](std::size_t size, const std::nothrow_t&) throw();

-5- Effects: Same as above, except that it is called by a placement version of a new-expression when a C++ program prefers a null pointer result as an error indication, instead of a bad_alloc exception.

-6- Replaceable: a C++ program can define a function with this function signature that displaces the default version defined by the C++ Standard library.

-7- Required behavior: Same as for operator new(std::size_t,const std::nothrow_t&). This nothrow version of operator new[] returns a pointer obtained as if acquired from the ordinary version.

-8- Default behavior: Returns operator new( size ,nothrow).

void operator delete[](void* ptr) throw();
void operator delete[](void* ptr, const std::nothrow_t&) throw();

-9- Effects: The deallocation function (basic.stc.dynamic.deallocation) called by the array form of a delete-expression to render the value of ptr invalid.

-10- Replaceable: a C++ program can define a function with this function signature that displaces the default version defined by the C++ Standard library.

-11- Required behavior: accept a value of ptr that is null or that was returned by an earlier call to operator new[](std::size_t) or operator new[](std::size_t,const std::nothrow_t&).

-12- Default behavior:

  • For a null value of ptr , does nothing.
  • Any other value of ptr shall be a value returned earlier by a call to the default operator new[](std::size_t).*
    [Footnote: The value must not have been invalidated by an intervening call to operator delete[](void*) (lib.res.on.arguments). --- end foonote]
    For such a non-null value of ptr , reclaims storage allocated by the earlier call to the default operator new[].

-13- It is unspecified under what conditions part or all of such reclaimed storage is allocated by a subsequent call to operator new or any of calloc, malloc, or realloc, declared in <cstdlib>.

18.4.1.3 - Placement forms [lib.new.delete.placement]

-1- These functions are reserved, a C++ program may not define functions that displace the versions in the Standard C++ library (lib.constraints).

void* operator new(std::size_t size, void* ptr) throw();

-2- Returns: ptr .

-3- Notes: Intentionally performs no other action.

-4- [Example: This can be useful for constructing an object at a known address:

char place[sizeof(Something)];
Something* p = new (place) Something();

--- end example]
void* operator new[](std::size_t size, void* ptr) throw();

-5- Returns: ptr .

-6- Notes: Intentionally performs no other action.

void operator delete(void* ptr, void*) throw();

-7- Effects: Intentionally performs no action.

-8- Notes: Default function called when any part of the initialization in a placement new expression that invokes the library's non-array placement operator new terminates by throwing an exception (expr.new).

void operator delete[](void* ptr, void*) throw();

-9- Effects: Intentionally performs no action.

-10- Notes: Default function called when any part of the initialization in a placement new expression that invokes the library's array placement operator new terminates by throwing an exception (expr.new).

18.4.2 - Storage allocation errors [lib.alloc.errors]

18.4.2.1 - Class bad_alloc [lib.bad.alloc]

namespace std {
  class bad_alloc : public exception {
  public:
    bad_alloc() throw();
    bad_alloc(const bad_alloc&) throw();
    bad_alloc& operator=(const bad_alloc&) throw();
    virtual ~bad_alloc() throw();
    virtual const char* what() const throw();
  };
}

-1- The class bad_alloc defines the type of objects thrown as exceptions by the implementation to report a failure to allocate storage.

bad_alloc() throw();

-2- Effects: Constructs an object of class bad_alloc.

-3- Notes: The result of calling what() on the newly constructed object is implementation-defined.

    bad_alloc(const bad_alloc&) throw();
    bad_alloc& operator=(const bad_alloc&) throw();

-4- Effects: Copies an object of class bad_alloc.

virtual const char* what() const throw();

-5- Returns: An implementation-defined NTBS.

18.4.2.2 - Type new_handler [lib.new.handler]

typedef void (*new_handler)();

-1- The type of a handler function to be called by operator new() or operator new[]() (lib.new.delete) when they cannot satisfy a request for additional storage.

-2- Required behavior: A new_handler shall perform one of the following:

  • make more storage available for allocation and then return;
  • throw an exception of type bad_alloc or a class derived from bad_alloc;
  • call either abort() or exit();

18.4.2.3 - set_new_handler [lib.set.new.handler]

new_handler set_new_handler(new_handler  new_p ) throw();

-1- Effects: Establishes the function designated by new_p as the current new_handler .

-2- Returns: 0 on the first call, the previous new_handler on subsequent calls.

18.5 - Type identification [lib.support.rtti]

-1- The header <typeinfo> defines a type associated with type information generated by the implementation. It also defines two types for reporting dynamic type identification errors.

Header <typeinfo> synopsis

namespace std {
  class type_info;
  class bad_cast;
  class bad_typeid;
}

See also expr.dynamic.cast, expr.typeid.

18.5.1 - Class type_info [lib.type.info]

namespace std {
  class type_info {
  public:
    virtual ~type_info();
    bool operator==(const type_info&  rhs ) const;
    bool operator!=(const type_info&  rhs ) const;
    bool before(const type_info&  rhs ) const;
    const char* name() const;
  private:
    type_info(const type_info&  rhs );
    type_info& operator=(const type_info&  rhs );
  };
}

-1- The class type_info describes type information generated by the implementation. Objects of this class effectively store a pointer to a name for the type, and an encoded value suitable for comparing two types for equality or collating order. The names, encoding rule, and collating sequence for types are all unspecified and may differ between programs.

bool operator==(const type_info&  rhs ) const;

-2- Effects: Compares the current object with rhs .

-3- Returns: true if the two values describe the same type.

bool operator!=(const type_info&  rhs ) const;

-4- Returns: !(*this == rhs ).

bool before(const type_info&  rhs ) const;

-5- Effects: Compares the current object with rhs .

-6- Returns: true if *this precedes rhs in the implementation's collation order.

const char* name() const;

-7- Returns: an implementation-defined NTBS.

-8- Notes: The message may be a null-terminated multibyte string (lib.multibyte.strings), suitable for conversion and display as a wstring (lib.string.classes, lib.locale.codecvt)

type_info(const type_info&  rhs );
type_info& operator=(const type_info&  rhs );

-9- Effects: Copies a type_info object.

-10- Notes: Since the copy constructor and assignment operator for type_info are private to the class, objects of this type cannot be copied.

18.5.2 - Class bad_cast [lib.bad.cast]

namespace std {
  class bad_cast : public exception {
  public:
    bad_cast() throw();
    bad_cast(const bad_cast&) throw();
    bad_cast& operator=(const bad_cast&) throw();
    virtual ~bad_cast() throw();
    virtual const char* what() const throw();
  };
}

-1- The class bad_cast defines the type of objects thrown as exceptions by the implementation to report the execution of an invalid dynamic-cast expression (expr.dynamic.cast).

bad_cast() throw();

-2- Effects: Constructs an object of class bad_cast.

-3- Notes: The result of calling what() on the newly constructed object is implementation-defined.

    bad_cast(const bad_cast&) throw();
    bad_cast& operator=(const bad_cast&) throw();

-4- Effects: Copies an object of class bad_cast.

virtual const char* what() const throw();

-5- Returns: An implementation-defined NTBS.

-6- Notes: The message may be a null-terminated multibyte string (lib.multibyte.strings), suitable for conversion and display as a wstring (lib.string.classes, lib.locale.codecvt)

18.5.3 - Class bad_typeid [lib.bad.typeid]

namespace std {
  class bad_typeid : public exception {
  public:
    bad_typeid() throw();
    bad_typeid(const bad_typeid&) throw();
    bad_typeid& operator=(const bad_typeid&) throw();
    virtual ~bad_typeid() throw();
    virtual const char* what() const throw();
  };
}

-1- The class bad_typeid defines the type of objects thrown as exceptions by the implementation to report a null pointer in a typeid expression (expr.typeid).

bad_typeid() throw();

-2- Effects: Constructs an object of class bad_typeid.

-3- Notes: The result of calling what() on the newly constructed object is implementation-defined.

    bad_typeid(const bad_typeid&) throw();
    bad_typeid& operator=(const bad_typeid&) throw();

-4- Effects: Copies an object of class bad_typeid.

virtual const char* what() const throw();

-5- Returns: An implementation-defined NTBS.

-6- Notes: The message may be a null-terminated multibyte string (lib.multibyte.strings), suitable for conversion and display as a wstring (lib.string.classes, lib.locale.codecvt)

18.6 - Exception handling [lib.support.exception]

-1- The header <exception> defines several types and functions related to the handling of exceptions in a C++ program.

Header <exception> synopsis

namespace std {
  class exception;
  class bad_exception;
  typedef void (*unexpected_handler)();
  unexpected_handler set_unexpected(unexpected_handler  f ) throw();
  void unexpected();
  typedef void (*terminate_handler)();
  terminate_handler set_terminate(terminate_handler  f ) throw();
  void terminate();
  bool uncaught_exception();
}

See also except.special.

18.6.1 - Class exception [lib.exception]

namespace std {
  class exception {
  public:
    exception() throw();
    exception(const exception&) throw();
    exception& operator=(const exception&) throw();
    virtual ~exception() throw();
    virtual const char* what() const throw();
  };
}

-1- The class exception defines the base class for the types of objects thrown as exceptions by C++ Standard library components, and certain expressions, to report errors detected during program execution.

exception() throw();

-2- Effects: Constructs an object of class exception.

-3- Notes: Does not throw any exceptions.

exception(const exception&) throw();
exception& operator=(const exception&) throw();

-4- Effects: Copies an exception object.

-5- Notes: The effects of calling what() after assignment are implementation-defined.

virtual ~exception() throw();

-6- Effects: Destroys an object of class exception.

-7- Notes: Does not throw any exceptions.

virtual const char* what() const throw();

-8- Returns: An implementation-defined NTBS.

-9- Notes: The message may be a null-terminated multibyte string (lib.multibyte.strings), suitable for conversion and display as a wstring (lib.string.classes, lib.locale.codecvt)

18.6.2 - Violating exception-specifications [lib.exception.unexpected]

18.6.2.1 - Class bad_exception [lib.bad.exception]

namespace std {
  class bad_exception : public exception {
  public:
    bad_exception() throw();
    bad_exception(const bad_exception&) throw();
    bad_exception& operator=(const bad_exception&) throw();
    virtual ~bad_exception() throw();
    virtual const char* what() const throw();
  };
}

-1- The class bad_exception defines the type of objects thrown as described in (except.unexpected).

bad_exception() throw();

-2- Effects: Constructs an object of class bad_exception.

-3- Notes: The result of calling what() on the newly constructed object is implementation-defined.

    bad_exception(const bad_exception&) throw();
    bad_exception& operator=(const bad_exception&) throw();

-4- Effects: Copies an object of class bad_exception.

virtual const char* what() const throw();

-5- Returns: An implementation-defined NTBS.

-6- Notes: The message may be a null-terminated multibyte string (lib.multibyte.strings), suitable for conversion and display as a wstring (lib.string.classes, lib.locale.codecvt)

18.6.2.2 - Type unexpected_handler [lib.unexpected.handler]

typedef void (*unexpected_handler)();

-1- The type of a handler function to be called by unexpected() when a function attempts to throw an exception not listed in its exception-specification.

-2- Required behavior: An unexpected_handler shall not return. See also except.unexpected.

-3- Default behavior: The implementation's default unexpected_handler calls terminate().

18.6.2.3 - set_unexpected [lib.set.unexpected]

unexpected_handler set_unexpected(unexpected_handler  f ) throw();

-1- Effects: Establishes the function designated by f as the current unexpected_handler .

-2- Requires: f shall not be a null pointer.

-3- Returns: The previous unexpected_handler .

18.6.2.4 - unexpected [lib.unexpected]

void unexpected();

-1- Called by the implementation when a function exits via an exception not allowed by its exception-specification (except.unexpected). May also be called directly by the program.

-2- Effects: Calls the unexpected_handler function in effect immediately after evaluating the throw-expression (lib.unexpected.handler), if called by the implementation, or calls the current unexpected_handler, if called by the program.

18.6.3 - Abnormal termination [lib.exception.terminate]

18.6.3.1 - Type terminate_handler [lib.terminate.handler]

typedef void (*terminate_handler)();

-1- The type of a handler function to be called by terminate() when terminating exception processing.

-2- Required behavior: A terminate_handler shall terminate execution of the program without returning to the caller.

-3- Default behavior: The implementation's default terminate_handler calls abort().

18.6.3.2 - set_terminate [lib.set.terminate]

terminate_handler set_terminate(terminate_handler  f ) throw();

-1- Effects: Establishes the function designated by f as the current handler function for terminating exception processing.

-2- Requires: f shall not be a null pointer.

-3- Returns: The previous terminate_handler .

18.6.3.3 - terminate [lib.terminate]

void terminate();

-1- Called by the implementation when exception handling must be abandoned for any of several reasons (except.terminate). May also be called directly by the program.

-2- Effects: Calls the terminate_handler function in effect immediately after evaluating the throw-expression (lib.terminate.handler), if called by the implementation, or calls the current terminate_handler function, if called by the program.

18.6.4 - uncaught_exception [lib.uncaught]

bool uncaught_exception();

-1- Returns: true after completing evaluation of a throw-expression until either completing initialization of the exception-declaration in the matching handler or entering unexpected() due to the throw; or after entering terminate() for any reason other than an explicit call to terminate(). [Note: This includes stack unwinding (except.ctor).
--- end note]

-2- Notes: When uncaught_exception() is true, throwing an exception can result in a call of terminate() (except.terminate).

18.7 - Other runtime support [lib.support.runtime]

-1- Headers <cstdarg> (variable arguments), <csetjmp> (nonlocal jumps), <ctime> (system clock clock(), time()), <csignal> (signal handling), and <cstdlib> (runtime environment getenv(), system()).

Header <cstdarg> synopsis
TypeName(s)
Macros:va_argva_endva_start
Type:va_list

Header <csetjmp> synopsis
TypeName(s)
Macro:setjmp
Type:jmp_buf
Function:longjmp

Header <ctime> synopsis
TypeName(s)
Macros:CLOCKS_PER_SEC
Types:clock_t
Functions:clock

Header <csignal> synopsis
TypeName(s)
Macros:SIGABRTSIGILLSIGSEGVSIG_DFL
SIG_IGNSIGFPESIGINTSIGTERMSIG_ERR
Type:sig_atomic_t
Functions:raisesignal

Header <cstdlib> synopsis
TypeName(s)
Functions:getenvsystem

-2- The contents of these headers are the same as the Standard C library headers <stdarg.h>, <setjmp.h>, <time.h>, <signal.h>, and <stdlib.h> respectively, with the following changes:

-3- The restrictions that ISO C places on the second parameter to the va_start() macro in header <stdarg.h> are different in this International Standard. The parameter parmN is the identifier of the rightmost parameter in the variable parameter list of the function definition (the one just before the ...). If the parameter parmN is declared with a function, array, or reference type, or with a type that is not compatible with the type that results when passing an argument for which there is no parameter, the behavior is undefined.

See also ISO C subclause 4.8.1.1.

-4- The function signature longjmp(jmp_buf jbuf , int val ) has more restricted behavior in this International Standard. If any automatic objects would be destroyed by a thrown exception transferring control to another (destination) point in the program, then a call to longjmp( jbuf , val ) at the throw point that transfers control to the same (destination) point has undefined behavior.

See also ISO C subclause 7.10.4, 7.8, 7.6, 7.12.

-5- The common subset of the C and C++ languages consists of all declarations, definitions, and expressions that may appear in a well formed C++ program and also in a conforming C program. A POF (``plain old function'') is a function that uses only features from this common subset, and that does not directly or indirectly use any function that is not a POF. All signal handlers shall have C linkage. A POF that could be used as a signal handler in a conforming C program does not produce undefined behavior when used as a signal handler in a C++ program. The behavior of any other function used as a signal handler in a C++ program is implementation defined.*

[Footnote: In particular, a signal handler using exception handling is very likely to have problems --- end foonote]