[constraints] (original) (raw)

16 Library introduction [library]

16.4 Library-wide requirements [requirements]

16.4.5 Constraints on programs [constraints]

16.4.5.1 Overview [constraints.overview]

Subclause [constraints] describes restrictions on C++ programs that use the facilities of the C++ standard library.

The following subclauses specify constraints on the program's use of namespaces, its use of various reserved names, its use of headers, its use of standard library classes as base classes ([derived.classes]), its definitions of replacement functions, and its installation of handler functions during execution.

16.4.5.2 Namespace use [namespace.constraints]

16.4.5.2.1 Namespace std [namespace.std]

Unless otherwise specified, the behavior of a C++ program is undefined if it adds declarations or definitions to namespacestdor to a namespace within namespacestd.

Unless explicitly prohibited, a program may add a template specialization for any standard library class template to namespacestd provided that

The behavior of a C++ program is undefined if it declares an explicit or partial specialization of any standard library variable template, except where explicitly permitted by the specification of that variable template.

[Note 1:

The requirements on an explicit or partial specialization are stated by each variable template that grants such permission.

β€” _end note_]

The behavior of a C++ program is undefined if it declares

A program may explicitly instantiate a class template defined in the standard library only if the declaration

Let F denote a standard library function ([global.functions]), a standard library static member function, or an instantiation of a standard library function template.

Unless F is designated an addressable function, the behavior of a C++ program is unspecified (possibly ill-formed) if it explicitly or implicitly attempts to form a pointer to F.

Moreover, the behavior of a C++ program is unspecified (possibly ill-formed) if it attempts to form a reference to _F_or if it attempts to form a pointer-to-member designating either a standard library non-static member function ([member.functions]) or an instantiation of a standard library member function template.

A translation unit shall not declare namespace std to be an inline namespace ([namespace.def]).

16.4.5.2.2 Namespace posix [namespace.posix]

The behavior of a C++ program is undefined if it adds declarations or definitions to namespaceposixor to a namespace within namespaceposixunless otherwise specified.

The namespace posix is reserved for use by ISO/IEC/IEEE 9945 and other POSIX standards.

16.4.5.2.3 Namespaces for future standardization [namespace.future]

Top-level namespaces whose namespace-name consists of stdfollowed by one or more digits ([lex.name]) are reserved for future standardization.

The behavior of a C++ program is undefined if it adds declarations or definitions to such a namespace.

[Example 1:

The top-level namespace std2 is reserved for use by future revisions of this International Standard.

β€” _end example_]

16.4.5.3 Reserved names [reserved.names]

16.4.5.3.1 General [reserved.names.general]

The C++ standard library reserves the following kinds of names:

If a program declares or defines a name in a context where it is reserved, other than as explicitly allowed by [library], its behavior is undefined.

16.4.5.3.2 Zombie names [zombie.names]

In namespace std, the names shown in Table 38 are reserved for previous standardization:

Table 38 β€” Zombie names in namespace std [tab:zombie.names.std]

πŸ”— auto_ptr generate_header pointer_to_binary_function
πŸ”— auto_ptr_ref get_pointer_safety pointer_to_unary_function
πŸ”— binary_function get_temporary_buffer ptr_fun
πŸ”— binary_negate get_unexpected random_shuffle
πŸ”— bind1st gets raw_storage_iterator
πŸ”— bind2nd is_literal_type result_of
πŸ”— binder1st is_literal_type_v result_of_t
πŸ”— binder2nd istrstream return_temporary_buffer
πŸ”— codecvt_mode little_endian set_unexpected
πŸ”— codecvt_utf16 mem_fun1_ref_t strstream
πŸ”— codecvt_utf8 mem_fun1_t strstreambuf
πŸ”— codecvt_utf8_utf16 mem_fun_ref_t unary_function
πŸ”— const_mem_fun1_ref_t mem_fun_ref unary_negate
πŸ”— const_mem_fun1_t mem_fun_t uncaught_exception
πŸ”— const_mem_fun_ref_t mem_fun undeclare_no_pointers
πŸ”— const_mem_fun_t not1 undeclare_reachable
πŸ”— consume_header not2 unexpected_handler
πŸ”— declare_no_pointers ostrstream wbuffer_convert
πŸ”— declare_reachable pointer_safety wstring_convert

The names shown in Table 39 are reserved as members for previous standardization, and may not be used as a name for object-like macros in portable code:

The names shown in Table 40 are reserved as member functions for previous standardization, and may not be used as a name for function-like macros in portable code:

The header names shown in Table 41 are reserved for previous standardization:

16.4.5.3.3 Macro names [macro.names]

A translation unit that includes a standard library header shall not#define or #undef names declared in any standard library header.

A translation unit shall not #define or #undefnames lexically identical to keywords, to the identifiers listed in Table 4, or to the attribute-tokens described in [dcl.attr], except that the names likely and unlikely may be defined as function-like macros ([cpp.replace]).

16.4.5.3.4 External linkage [extern.names]

Each name declared as an object with external linkagein a header is reserved to the implementation to designate that library object with external linkage,152both in namespace std and in the global namespace.

Eachglobal function signature declared withexternal linkage in a header is reserved to the implementation to designate that function signature withexternal linkage.153

Each name from the C standard library declared with external linkageis reserved to the implementation for use as a name withextern "C"linkage, both in namespace std and in the global namespace.

Each function signature from the C standard library declared withexternal linkage is reserved to the implementation for use as a function signature with bothextern "C"andextern "C++"linkage,154or as a name of namespace scope in the global namespace.

16.4.5.3.5 Types [extern.types]

For each type T from the C standard library, the types​::​Tandstd​::​Tare reserved to the implementation and, when defined,​::​Tshall be identical tostd​::​T.

16.4.5.3.6 User-defined literal suffixes [usrlit.suffix]

Literal suffix identifiers ([over.literal]) that do not start with an underscore are reserved for future standardization.

Literal suffix identifiers that contain a double underscore__ are reserved for use by C++ implementations.

16.4.5.5 Derived classes [derived.classes]

Virtual member function signatures definedfor a base class in the C++ standardlibrary may be overridden in a derived class defined in the program ([class.virtual]).

16.4.5.7 Handler functions [handler.functions]

The C++ standard library provides a default version of the following handler function ([support]):

A C++ program may install different handler functions during execution, by supplying a pointer to a function defined in the program or the library as an argument to (respectively):

See also subclauses [alloc.errors], Storage allocation errors, and [support.exception], Exception handling.

A C++ program can get a pointer to the current handler function by calling the following functions:

Calling the set_* and get_* functions shall not incur a data race ([intro.races]).

A call to any of the set_* functions shall synchronize with subsequent calls to the sameset_* function and to the corresponding get_* function.

16.4.5.8 Other functions [res.on.functions]

In certain cases (replacement functions, handler functions, operations on types used to instantiate standard library template components), the C++ standard library depends on components supplied by a C++ program.

If these components do not meet their requirements, this document places no requirements on the implementation.

In particular, the behavior is undefined in the following cases:

16.4.5.9 Function arguments [res.on.arguments]

Each of the following applies to all argumentsto functions defined in the C++ standard library,unless explicitly stated otherwise.

16.4.5.10 Library object access [res.on.objects]

The behavior of a program is undefined if calls to standard library functions from different threads may introduce a data race.

The conditions under which this may occur are specified in [res.on.data.races].

[Note 1:

Modifying an object of a standard library type that is shared between threads risks undefined behavior unless objects of that type are explicitly specified as being shareable without data races or the user supplies a locking mechanism.

β€” _end note_]

If an object of a standard library type is accessed, and the beginning of the object's lifetimedoes not happen before the access, or the access does not happen before the end of the object's lifetime, the behavior is undefined unless otherwise specified.

[Note 2:

This applies even to objects such as mutexes intended for thread synchronization.

β€” _end note_]

16.4.5.11 Semantic requirements [res.on.requirements]

A sequence Args of template arguments is said tomodel a concept Cif Argssatisfies C ([temp.constr.decl]) and meets all semantic requirements (if any) given in the specification of C.

If the validity or meaning of a program depends on whether a sequence of template arguments models a concept, and the concept is satisfied but not modeled, the program is ill-formed, no diagnostic required.

If the semantic requirements of a declaration's constraints ([structure.requirements]) are not modeled at the point of use, the program is ill-formed, no diagnostic required.