c++ international standard · 2007. 10. 22. · doc no: n2461=07-0331 date: 2007-10-22 reply to:...

1219
Doc No: N2461=07-0331 Date: 2007-10-22 Reply to: Pete Becker Roundhouse Consulting, Ltd. [email protected] Working Draft, Standard for Programming Language C++ Note: this is an early draft. It’s known to be incomplet and incorrekt, and it has lots of bad formatting.

Upload: others

Post on 11-Oct-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

  • Doc No: N2461=07-0331Date: 2007-10-22Reply to: Pete Becker

    Roundhouse Consulting, [email protected]

    Working Draft, Standard for ProgrammingLanguage C++

    Note: this is an early draft. It’s known to be incomplet and incorrekt, and it has lots of bad formatting.

  • ii

    Draft

  • Contents

    1 General 11.1 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Normative references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.4 Implementation compliance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.5 Structure of this International Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.6 Syntax notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.7 The C++ memory model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.8 The C++ object model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.9 Program execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.10 Multi-threaded executions and data races . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111.11 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    2 Lexical conventions 152.1 Phases of translation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152.2 Character sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162.3 Trigraph sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172.4 Preprocessing tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182.5 Alternative tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182.6 Tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192.7 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192.8 Header names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192.9 Preprocessing numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202.10 Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202.11 Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212.12 Operators and punctuators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212.13 Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

    3 Basic concepts 313.1 Declarations and definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313.2 One definition rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333.3 Declarative regions and scopes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353.4 Name lookup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413.5 Program and linkage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

  • CONTENTS CONTENTS iv

    3.6 Start and termination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583.7 Storage duration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603.8 Object Lifetime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633.9 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673.10 Lvalues and rvalues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723.11 Alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

    4 Standard conversions 754.1 Lvalue-to-rvalue conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764.2 Array-to-pointer conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764.3 Function-to-pointer conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764.4 Qualification conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764.5 Integral promotions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784.6 Floating point promotion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784.7 Integral conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784.8 Floating point conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784.9 Floating-integral conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 794.10 Pointer conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 794.11 Pointer to member conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 794.12 Boolean conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 804.13 Integer conversion rank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

    5 Expressions 815.1 Primary expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 835.2 Postfix expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 855.3 Unary expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 965.4 Explicit type conversion (cast notation) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1045.5 Pointer-to-member operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1055.6 Multiplicative operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1065.7 Additive operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1065.8 Shift operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1075.9 Relational operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1085.10 Equality operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1095.11 Bitwise AND operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1105.12 Bitwise exclusive OR operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1105.13 Bitwise inclusive OR operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1105.14 Logical AND operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1105.15 Logical OR operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1115.16 Conditional operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1115.17 Assignment and compound assignment operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1125.18 Comma operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1135.19 Constant expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

    6 Statements 1176.1 Labeled statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1176.2 Expression statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

    Draft

  • v CONTENTS CONTENTS

    6.3 Compound statement or block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1176.4 Selection statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1186.5 Iteration statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1206.6 Jump statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1226.7 Declaration statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1236.8 Ambiguity resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124

    7 Declarations 1277.1 Specifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1287.2 Enumeration declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1437.3 Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1467.4 The asm declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1607.5 Linkage specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160

    8 Declarators 1658.1 Type names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1668.2 Ambiguity resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1678.3 Meaning of declarators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1688.4 Function definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1818.5 Initializers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

    9 Classes 1959.1 Class names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1979.2 Class members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1999.3 Member functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2019.4 Static members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2059.5 Unions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2079.6 Bit-fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2089.7 Nested class declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2099.8 Local class declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2109.9 Nested type names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211

    10 Derived classes 21310.1 Multiple base classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21410.2 Member name lookup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21610.3 Virtual functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22010.4 Abstract classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224

    11 Member access control 22711.1 Access specifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22911.2 Accessibility of base classes and base class members . . . . . . . . . . . . . . . . . . . . . . . . . . . 23011.3 Access declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23211.4 Friends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23411.5 Protected member access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23711.6 Access to virtual functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23811.7 Multiple access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239

    Draft

  • CONTENTS CONTENTS vi

    11.8 Nested classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239

    12 Special member functions 24112.1 Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24112.2 Temporary objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24312.3 Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24512.4 Destructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24912.5 Free store . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25112.6 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25312.7 Construction and destruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25912.8 Copying class objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262

    13 Overloading 26913.1 Overloadable declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26913.2 Declaration matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27213.3 Overload resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27313.4 Address of overloaded function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29013.5 Overloaded operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29213.6 Built-in operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295

    14 Templates 30114.1 Template parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30214.2 Names of template specializations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30614.3 Template arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30714.4 Type equivalence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31414.5 Template declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31514.6 Name resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33114.7 Template instantiation and specialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34514.8 Function template specializations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358

    15 Exception handling 37915.1 Throwing an exception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38015.2 Constructors and destructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38215.3 Handling an exception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38315.4 Exception specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38515.5 Special functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38715.6 Exceptions and access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389

    16 Preprocessing directives 39116.1 Conditional inclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39316.2 Source file inclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39416.3 Macro replacement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39516.4 Line control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40116.5 Error directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40116.6 Pragma directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40116.7 Null directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402

    Draft

  • vii CONTENTS CONTENTS

    16.8 Predefined macro names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40216.9 Pragma operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403

    17 Library introduction 40517.1 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40517.2 Additional definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40817.3 Method of description (Informative) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40817.4 Library-wide requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415

    18 Language support library 42518.1 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42518.2 Implementation properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42618.3 Integer types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43618.4 Start and termination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43818.5 Dynamic memory management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43918.6 Type identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44418.7 Exception handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44718.8 Other runtime support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451

    19 Diagnostics library 45519.1 Exception classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45519.2 Assertions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46019.3 Error numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46019.4 System error support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461

    20 General utilities library 47720.1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47720.2 Utility components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48220.3 Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48820.4 Metaprogramming and type traits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49520.5 Function objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50720.6 Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52920.7 Date and time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561

    21 Strings library 56321.1 Character traits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56321.2 String classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56921.3 Class template basic_string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57321.4 Numeric Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60121.5 Null-terminated sequence utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603

    22 Localization library 60722.1 Locales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60722.2 Standard locale categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62222.3 Standard code conversion facets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66622.4 C Library Locales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 667

    Draft

  • CONTENTS CONTENTS viii

    23 Containers library 66923.1 Container requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66923.2 Sequence containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68623.3 Associative containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71923.4 Unordered associative containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 746

    24 Iterators library 76124.1 Iterator requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76124.2 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76624.3 Iterator primitives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76924.4 Predefined iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77324.5 Stream iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 789

    25 Algorithms library 79925.1 Non-modifying sequence operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80925.2 Mutating sequence operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81325.3 Sorting and related operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82225.4 C library algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 836

    26 Numerics library 83726.1 Numeric type requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83726.2 The floating-point environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83826.3 Complex numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83926.4 Random number generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84926.5 Numeric arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89626.6 Generalized numeric operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91726.7 C Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 921

    27 Input/output library 92727.1 Iostreams requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92727.2 Forward declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92827.3 Standard iostream objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93027.4 Iostreams base classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93227.5 Stream buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95127.6 Formatting and manipulators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96227.7 String-based streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99327.8 File-based streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1006

    28 Regular expressions library 102328.1 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102328.2 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102428.3 Regular expressions summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102628.4 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102628.5 Namespace std::regex_constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103228.6 Class regex_error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103628.7 Class template regex_traits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1037

    Draft

  • ix CONTENTS CONTENTS

    28.8 Class template basic_regex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103928.9 Class template sub_match . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104428.10Class template match_results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105028.11Regular expression algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105528.12Regular expression Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105928.13Modified ECMAScript regular expression grammar . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1065

    29 Atomic operations library 106929.1 Order and Consistency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107129.2 Lock-free Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107329.3 Flag Type and Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107329.4 Other Types and Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1075

    30 Thread support library 1085

    A Grammar summary 1087A.1 Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1087A.2 Lexical conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1087A.3 Basic concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1092A.4 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1092A.5 Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1095A.6 Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1096A.7 Declarators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1099A.8 Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1101A.9 Derived classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1102A.10 Special member functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1102A.11 Overloading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1103A.12 Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1103A.13 Exception handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1104A.14 Preprocessing directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1104

    B Implementation quantities 1107

    C Compatibility 1109C.1 C++ and ISO C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1109C.2 Standard C library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1119

    D Compatibility features 1125D.1 Increment operator with bool operand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1125D.2 static keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1125D.3 Access declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1125D.4 Implicit conversion from const strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1125D.5 Standard C library headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1125D.6 Old iostreams members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1126D.7 char* streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1128D.8 Binders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1138D.9 auto_ptr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1139

    Draft

  • CONTENTS CONTENTS x

    E Universal-character-names 1143

    F Cross references 1145

    Draft

  • List of Tables

    1 trigraph sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 alternative tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 alternative representations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 Types of Integer Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 escape sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 string literal concatenations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

    8 relations on const and volatile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

    9 simple-type-specifier s and the types they specify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

    10 relationship between operator and function call notation . . . . . . . . . . . . . . . . . . . . . . . . . . 27811 conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286

    12 Library Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40913 C++ Library Headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41614 C++ Headers for C Library Facilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41615 C++ Headers for Freestanding Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417

    16 Language support library summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42517 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42618 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43619 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43620 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43821 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45222 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45223 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45224 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45225 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45226 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452

    27 Diagnostics library summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45528 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460

  • LIST OF TABLES LIST OF TABLES xii

    29 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461

    30 General utilities library summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47731 EqualityComparable requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47832 LessThanComparable requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47833 MoveConstructible requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47834 CopyConstructible requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47835 MoveAssignable requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47836 CopyAssignable requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47937 Swappable requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47938 Destructible requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47939 Descriptive variable definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47940 Allocator requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48141 Primary Type Category Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49842 Composite Type Category Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49943 Type Property Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50044 Type Property Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50245 Type Relationship Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50346 Const-volatile modifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50447 Reference modifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50448 Sign modifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50549 Array modifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50550 Pointer modifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50651 Other transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50652 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56053 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56154 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561

    55 Strings library summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56356 Traits requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56457 basic_string(const Allocator&) effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57958 basic_string(const basic_string&) effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57959 basic_string(const basic_string&, size_type, size_type, const Allocator&) effects . 57960 basic_string(const charT*, size_type, const Allocator&) effects . . . . . . . . . . . . . 58061 basic_string(const charT*, const Allocator&) effects . . . . . . . . . . . . . . . . . . . . . 58062 basic_string(size_t, charT, const Allocator&) effects . . . . . . . . . . . . . . . . . . . . 58063 operator=(const basic_string&) effects . . . . . . . . . . . . 58164 operator=(const basic_string&&) effects . . . . . . . . . . . . 58165 compare() results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59466 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60467 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60568 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60569 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60570 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60671 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606

    Draft

  • xiii LIST OF TABLES LIST OF TABLES

    72 Localization library summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60773 Locale Category Facets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61174 Required Specializations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61275 do_in/do_out result values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63276 do_unshift result values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63377 Integer Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63778 Length Modifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63779 Integer Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64180 Floating-point Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64281 Length Modifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64282 Numeric conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64283 Fill padding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64384 do_get_date effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65185 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 668

    86 Containers library summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66987 Container requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67088 Reversible container requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67289 Sequence container requirements (in addition to container) . . . . . . . . . . . . . . . . . . . . . . . . 67490 Optional sequence container operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67691 Associative container requirements (in addition to container) . . . . . . . . . . . . . . . . . . . . . . . 67792 Container requirements that are not required for unordered associative containers . . . . . . . . . . . . 68093 Unordered associative container requirements (in addition to container) . . . . . . . . . . . . . . . . . 681

    94 Iterators library summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76195 Relations among iterator categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76196 Input iterator requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76397 Output iterator requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76398 Forward iterator requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76499 Bidirectional iterator requirements (in addition to forward iterator) . . . . . . . . . . . . . . . . . . . . 765100 Random access iterator requirements (in addition to bidirectional iterator) . . . . . . . . . . . . . . . . 766

    101 Algorithms library summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 799102 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 836

    103 Numerics library summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 837104 Uniform random number generator requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 850105 Random number engine requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 851106 Random number engine adaptor requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 853107 Random number distribution requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 855108 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 921109 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 922

    110 Input/output library summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 927111 fmtflags effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 937112 fmtflags constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 937

    Draft

  • LIST OF TABLES LIST OF TABLES xiv

    113 iostate effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 938114 openmode effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 938115 seekdir effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 938116 Position type requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 943117 basic_ios::init() effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 945118 seekoff positioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 998119 newoff values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 998120 File open modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1010121 seekoff effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1013122 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1022123 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1022

    124 regular expression traits class requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1024126 regex_constants::match_flag_type effects when obtaining a match against a character container

    sequence [first,last). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1033125 syntax_option_type effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1035127 error_type values in the C locale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1036128 match_results assignment operator effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1052129 Effects of regex_match algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1055130 Effects of regex_search algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1057

    131 Atomics library summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1069132 memory_order effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1071133 Atomics for builtin types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1077134 Atomics for standard typedef types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1078135 Atomic arithmetic computations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1083

    136 Standard Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1119137 Standard Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1120138 Standard Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1120139 Standard Structs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1120140 Standard Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1121

    141 C Headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1125142 strstreambuf(streamsize) effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1129143 strstreambuf(void* (*)(size_t), void (*)(void*)) effects . . . . . . . . . . . . . . . . . . 1130144 strstreambuf(charT*, streamsize, charT*) effects . . . . . . . . . . . . . . . . . . . . . . . . 1130145 seekoff positioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1133146 newoff values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1133

    Draft

  • Chapter 1 General [intro]

    1.1 Scope [intro.scope]

    1 This International Standard specifies requirements for implementations of the C++ programming language. The firstsuch requirement is that they implement the language, and so this International Standard also defines C++. Otherrequirements and relaxations of the first requirement appear at various places within this International Standard.

    2 C++ is a general purpose programming language based on the C programming language as described in ISO/IEC9899:1990 Programming languages — C (1.2). In addition to the facilities provided by C, C++ provides additionaldata types, classes, templates, exceptions, namespaces, inline functions, operator overloading, function name overload-ing, references, free store management operators, and additional library facilities.

    1.2 Normative references [intro.refs]

    1 The following standards contain provisions which, through reference in this text, constitute provisions of this Interna-tional Standard. At the time of publication, the editions indicated were valid. All standards are subject to revision, andparties to agreements based on this International Standard are encouraged to investigate the possibility of applying themost recent editions of the standards indicated below. Members of IEC and ISO maintain registers of currently validInternational Standards.

    — Ecma International, ECMAScript Language Specification, Standard Ecma-262, third edition, 1999.

    — ISO/IEC 2382 (all parts), Information technology — Vocabulary

    — ISO/IEC 9899:1990, Programming languages — C

    — ISO/IEC 9899/Amd.1:1995, Programming languages — C, AMENDMENT 1: C Integrity

    — ISO/IEC 9899:1999, Programming languages — C

    — ISO/IEC 9899:1999/Cor.1:2001, Programming languages — C

    — ISO/IEC 9899:1999/Cor.2:2004, Programming languages — C

    — ISO/IEC 9945:2003, Information Technology — Portable Operating System Interface (POSIX)

    — ISO/IEC 10646-1:1993, Information technology — Universal Multiple-Octet Coded Character Set (UCS) — Part1: Architecture and Basic Multilingual Plane

    — ISO/IEC TR 19769:2004, Information technology — Programming languages, their environments and systemsoftware interfaces — Extensions for the progrmming language C to support new character data types

  • 1.3 Definitions General 2

    2 The library described in clause 7 of ISO/IEC 9899:1990 and clause 7 of ISO/IEC 9899/Amd.1:1995 is hereinafter calledthe Standard C Library.1)

    3 The library described in clause 7 of ISO/IEC 9899:1999 and clause 7 of ISO/IEC 9899:1999/Cor.1:2001 and clause 7 ofISO/IEC 9899:1999/Cor.2:2003 is hereinafter called the Standard C99 Library.

    4 The library described in ISO/IEC TR 19769:2004 is hereinafter called the C Unicode TR.

    5 The operating system interface described in ISO/IEC 9945:2003 is hereinafter called POSIX.

    6 The ECMAScript Language Specification described in Standard Ecma-262 is hereinafter called ECMA-262.

    1.3 Definitions [intro.defs]

    1 For the purposes of this International Standard, the definitions given in ISO/IEC 2382 and the following definitionsapply. 17.1 defines additional terms that are used only in clauses 17 through 27 and Annex D.

    2 Terms that are used only in a small portion of this International Standard are defined where they are used and italicizedwhere they are defined.

    1.3.1 [defns.argument]argumentan expression in the comma-separated list bounded by the parentheses in a function call expression; a sequence ofpreprocessing tokens in the comma-separated list bounded by the parentheses in a function-like macro invocation; theoperand of throw; or an expression, type-id or template-name in the comma-separated list bounded by the angle bracketsin a template instantiation. Also known as an actual argument or actual parameter.

    1.3.2 [defns.cond.supp]conditionally-supporteda program construct that an implementation is not required to support. [ Note: Each implementation documents allconditionally-supported constructs that it does not support. — end note ]

    1.3.3 [defns.diagnostic]diagnostic messagea message belonging to an implementation-defined subset of the implementation’s output messages.

    1.3.4 [defns.dynamic.type]dynamic typethe type of the most derived object (1.8) to which the lvalue denoted by an lvalue expression refers. [ Example: if apointer (8.3.1) p whose static type is “pointer to class B” is pointing to an object of class D, derived from B (clause 10),the dynamic type of the expression *p is “D.” References (8.3.2) are treated similarly. — end example ] The dynamictype of an rvalue expression is its static type.

    1.3.5 [defns.ill.formed]1) With the qualifications noted in clauses 17 through 27, and in C.2, the Standard C library is a subset of the Standard C++ library.

    Draft

  • 3 General 1.3 Definitions

    ill-formed programinput to a C++ implementation that is not a well-formed program.

    1.3.6 [defns.impl.defined]implementation-defined behaviorbehavior, for a well-formed program construct and correct data, that depends on the implementation and that eachimplementation documents.

    1.3.7 [defns.impl.limits]implementation limitsrestrictions imposed upon programs by the implementation.

    1.3.8 [defns.locale.specific]locale-specific behaviorbehavior that depends on local conventions of nationality, culture, and language that each implementation documents.

    1.3.9 [defns.multibyte]multibyte charactera sequence of one or more bytes representing a member of the extended character set of either the source or the executionenvironment. The extended character set is a superset of the basic character set (2.2).

    1.3.10 [defns.parameter]parameteran object or reference declared as part of a function declaration or definition, or in the catch clause of an exceptionhandler, that acquires a value on entry to the function or handler; an identifier from the comma-separated list boundedby the parentheses immediately following the macro name in a function-like macro definition; or a template-parameter.Parameters are also known as formal arguments or formal parameters.

    1.3.11 [defns.signature]signaturethe name and the parameter-type-list (8.3.5) of a function, as well as the class or namespace of which it is a member.If a function or function template is a class member its signature additionally includes the cv-qualifiers (if any) andthe ref-qualifier (if any) on the function or function template itself. The signature of a function template additionallyincludes its return type and its template parameter list. The signature of a function template specialization includesthe signature of the template of which it is a specialization and its template arguments (whether explicitly specified ordeduced). [ Note: Signatures are used as a basis for name mangling and linking. — end note ]

    1.3.12 [defns.static.type]static typethe type of an expression (3.9), which type results from analysis of the program without considering execution semantics.

    Draft

  • 1.4 Implementation compliance General 4

    The static type of an expression depends only on the form of the program in which the expression appears, and does notchange while the program is executing.

    1.3.13 [defns.undefined]undefined behaviorbehavior, such as might arise upon use of an erroneous program construct or erroneous data, imposes no requirements.Undefined behavior may also be expected when this International Standard omits the description of any explicit def-inition of behavior. [ Note: permissible undefined behavior ranges from ignoring the situation completely with un-predictable results, to behaving during translation or program execution in a documented manner characteristic of theenvironment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with theissuance of a diagnostic message). Many erroneous program constructs do not engender undefined behavior; they arerequired to be diagnosed. — end note ]

    1.3.14 [defns.unspecified]unspecified behaviorbehavior, for a well-formed program construct and correct data, that depends on the implementation. The implementa-tion is not required to document which behavior occurs. [ Note: usually, the range of possible behaviors is delineated bythis International Standard. — end note ]

    1.3.15 [defns.well.formed]well-formed programa C++ program constructed according to the syntax rules, diagnosable semantic rules, and the One Definition Rule (3.2).

    1.4 Implementation compliance [intro.compliance]

    1 The set of diagnosable rules consists of all syntactic and semantic rules in this International Standard except for thoserules containing an explicit notation that “no diagnostic is required” or which are described as resulting in “undefinedbehavior.”

    2 Although this International Standard states only requirements on C++ implementations, those requirements are ofteneasier to understand if they are phrased as requirements on programs, parts of programs, or execution of programs. Suchrequirements have the following meaning:

    — If a program contains no violations of the rules in this International Standard, a conforming implementation shall,within its resource limits, accept and correctly execute2) that program.

    — If a program contains a violation of any diagnosable rule or an occurrence of a construct described in this Standardas “conditionally-supported” when the implementation does not support that construct, a conforming implemen-tation shall issue at least one diagnostic message, except that

    — If a program contains a violation of a rule for which no diagnostic is required, this International Standard placesno requirement on implementations with respect to that program.

    3 For classes and class templates, the library clauses specify partial definitions. Private members (clause 11) are notspecified, but each implementation shall supply them to complete the definitions according to the description in thelibrary clauses.

    2) “Correct execution” can include undefined behavior, depending on the data being processed; see 1.3 and 1.9.

    Draft

  • 5 General 1.5 Structure of this International Standard

    4 For functions, function templates, objects, and values, the library clauses specify declarations. Implementations shallsupply definitions consistent with the descriptions in the library clauses.

    5 The names defined in the library have namespace scope (7.3). A C++ translation unit (2.1) obtains access to these namesby including the appropriate standard library header (16.2).

    6 The templates, classes, functions, and objects in the library have external linkage (3.5). The implementation providesdefinitions for standard library entities, as necessary, while combining translation units to form a complete C++ pro-gram (2.1).

    7 Two kinds of implementations are defined: hosted and freestanding. For a hosted implementation, this InternationalStandard defines the set of available libraries. A freestanding implementation is one in which execution may take placewithout the benefit of an operating system, and has an implementation-defined set of libraries that includes certainlanguage-support libraries (17.4.1.3).

    8 A conforming implementation may have extensions (including additional library functions), provided they do not alterthe behavior of any well-formed program. Implementations are required to diagnose programs that use such extensionsthat are ill-formed according to this International Standard. Having done so, however, they can compile and executesuch programs.

    9 Each implementation shall include documentation that identifies all conditionally-supported constructs that it does notsupport and defines all locale-specific characteristics.3)

    1.5 Structure of this International Standard [intro.structure]

    1 Clauses 2 through 16 describe the C++ programming language. That description includes detailed syntactic specifica-tions in a form described in 1.6. For convenience, Annex A repeats all such syntactic specifications.

    2 Clauses 17 through 27 and Annex D (the library clauses) describe the Standard C++ library, which provides definitionsfor the following kinds of entities: macros (16.3), values (clause 3), types (8.1, 8.3), templates (clause 14), classes (clause9), functions (8.3.5), and objects (clause 7).

    3 Annex B recommends lower bounds on the capacity of conforming implementations.

    4 Annex C summarizes the evolution of C++ since its first published description, and explains in detail the differencesbetween C++ and C. Certain features of C++ exist solely for compatibility purposes; Annex D describes those features.

    5 Finally, Annex E says what characters are valid in universal-character names in C++ identifiers (2.10).

    6 Throughout this International Standard, each example is introduced by “[ Example:” and terminated by “ — end exam-ple ]”. Each note is introduced by “[ Note:” and terminated by “ — end note ]”. Examples and notes may be nested.

    1.6 Syntax notation [syntax]

    1 In the syntax notation used in this International Standard, syntactic categories are indicated by italic type, and literalwords and characters in constant width type. Alternatives are listed on separate lines except in a few cases where along set of alternatives is presented on one line, marked by the phrase “one of.” An optional terminal or nonterminalsymbol is indicated by the subscript “opt ”, so

    { expressionopt }

    3)This documentation also defines implementation-defined behavior; see 1.9.

    Draft

  • 1.7 The C++ memory model General 6

    2 Names for syntactic categories have generally been chosen according to the following rules:

    — X-name is a use of an identifier in a context that determines its meaning (e.g. class-name, typedef-name).

    — X-id is an identifier with no context-dependent meaning (e.g. qualified-id).

    — X-seq is one or more X’s without intervening delimiters (e.g. declaration-seq is a sequence of declarations).

    — X-list is one or more X’s separated by intervening commas (e.g. expression-list is a sequence of expressionsseparated by commas).

    1.7 The C++ memory model [intro.memory]

    1 The fundamental storage unit in the C++ memory model is the byte. A byte is at least large enough to contain anymember of the basic execution character set and the eight-bit code units of the Unicode UTF-8 encoding form and iscomposed of a contiguous sequence of bits, the number of which is implementation-defined. The least significant bit iscalled the low-order bit; the most significant bit is called the high-order bit. The memory available to a C++ programconsists of one or more sequences of contiguous bytes. Every byte has a unique address.

    2 [ Note: the representation of types is described in 3.9. — end note ]

    3 A memory location is either an object of scalar type or a maximal sequence of adjacent bit-fields all having non-zerowidth. [ Note: Various features of the language, such as references and virtual functions, might involve additional mem-ory locations that are not accessible to programs but are managed by the implementation. — end note ] Two threads ofexecution can update and access separate memory locations without interfering with each other.

    4 [ Note: Thus a bit-field and an adjacent non-bit-field are in separate memory locations, and therefore can be concurrentlyupdated by two threads of execution without interference. The same applies to two bit-fields, if one is declared inside anested struct declaration and the other is not, or if the two are separated by a zero-length bit-field declaration, or if theyare separated by a non-bit-field declaration. It is not safe to concurrently update two bit-fields in the same struct if allfields between them are also bit-fields, no matter what the sizes of those intervening bit-fields happen to be. — end note ]

    5 [ Example: A structure declared as

    struct {

    char a;

    int b:5,

    c:11,

    :0,

    d:8;

    struct {int ee:8;} e;

    }

    contains four separate memory locations: The field a and bit-fields d and e.ee are each separate memory locations,and can be modified concurrently without interfering with each other. The bit-fields b and c together constitute thefourth memory location. The bit-fields b and c cannot be concurrently modified, but b and a, for example, can be.— end example ]

    1.8 The C++ object model [intro.object]

    1 The constructs in a C++ program create, destroy, refer to, access, and manipulate objects. An object is a region ofstorage. [ Note: A function is not an object, regardless of whether or not it occupies storage in the way that objects do.

    Draft

  • 7 General 1.9 Program execution

    — end note ] An object is created by a definition (3.1), by a new-expression (5.3.4) or by the implementation (12.2) whenneeded. The properties of an object are determined when the object is created. An object can have a name (clause 3). Anobject has a storage duration (3.7) which influences its lifetime (3.8). An object has a type (3.9). The term object typerefers to the type with which the object is created. Some objects are polymorphic (10.3); the implementation generatesinformation associated with each such object that makes it possible to determine that object’s type during programexecution. For other objects, the interpretation of the values found therein is determined by the type of the expression s(clause 5) used to access them.

    2 Objects can contain other objects, called subobjects. A subobject can be a member subobject (9.2), a base class subobject(clause 10), or an array element. An object that is not a subobject of any other object is called a complete object.

    3 For every object x, there is some object called the complete object of x, determined as follows:

    — If x is a complete object, then x is the complete object of x.

    — Otherwise, the complete object of x is the complete object of the (unique) object that contains x.

    4 If a complete object, a data member (9.2), or an array element is of class type, its type is considered the most derivedclass, to distinguish it from the class type of any base class subobject; an object of a most derived class type or of anon-class type is called a most derived object.

    5 Unless it is a bit-field (9.6), a most derived object shall have a non-zero size and shall occupy one or more bytes ofstorage. Base class subobjects may have zero size. An object of trivial or standard-layout type (3.9) shall occupycontiguous bytes of storage.

    6 [ Note: C++ provides a variety of built-in types and several ways of composing new types from existing types (3.9).— end note ]

    1.9 Program execution [intro.execution]

    1 The semantic descriptions in this International Standard define a parameterized nondeterministic abstract machine. ThisInternational Standard places no requirement on the structure of conforming implementations. In particular, they neednot copy or emulate the structure of the abstract machine. Rather, conforming implementations are required to emulate(only) the observable behavior of the abstract machine as explained below.4)

    2 Certain aspects and operations of the abstract machine are described in this International Standard as implementation-defined (for example, sizeof(int)). These constitute the parameters of the abstract machine. Each implementationshall include documentation describing its characteristics and behavior in these respects.5) Such documentation shalldefine the instance of the abstract machine that corresponds to that implementation (referred to as the “correspondinginstance” below).

    3 Certain other aspects and operations of the abstract machine are described in this International Standard as unspecified(for example, order of evaluation of arguments to a function). Where possible, this International Standard defines a setof allowable behaviors. These define the nondeterministic aspects of the abstract machine. An instance of the abstractmachine can thus have more than one possible execution sequence for a given program and a given input.

    4) This provision is sometimes called the “as-if” rule, because an implementation is free to disregard any requirement of this International Standardas long as the result is as if the requirement had been obeyed, as far as can be determined from the observable behavior of the program. For instance,an actual implementation need not evaluate part of an expression if it can deduce that its value is not used and that no side effects affecting theobservable behavior of the program are produced.

    5)This documentation also includes conditonally-supported constructs and locale-specific behavior. See 1.4.

    Draft

  • 1.9 Program execution General 8

    4 Certain other operations are described in this International Standard as undefined (for example, the effect of derefer-encing the null pointer). [ Note: this International Standard imposes no requirements on the behavior of programs thatcontain undefined behavior. — end note ]

    5 A conforming implementation executing a well-formed program shall produce the same observable behavior as oneof the possible execution sequences of the corresponding instance of the abstract machine with the same program andthe same input. However, if any such execution sequence contains an undefined operation, this International Standardplaces no requirement on the implementation executing that program with that input (not even with regard to operationspreceding the first undefined operation).

    6 The observable behavior of the abstract machine is its sequence of reads and writes to volatile data and calls to libraryI/O functions.6)

    7 When the processing of the abstract machine is interrupted by receipt of a signal, the values of objects with type otherthan volatile std::sig_atomic_t are unspecified, and the value of any object not of type volatile std::sig_-atomic_t that is modified by the handler becomes undefined.

    8 An instance of each object with automatic storage duration (3.7.2) is associated with each entry into its block. Such anobject exists and retains its last-stored value during the execution of the block and while the block is suspended (by acall of a function or receipt of a signal).

    9 The least requirements on a conforming implementation are:

    — Access to volatile objects are evaluated strictly according to the rules of the abstract machine.

    — At program termination, all data written into files shall be identical to one of the possible results that execution ofthe program according to the abstract semantics would have produced.

    — The input and output dynamics of interactive devices shall take place in such a fashion that prompting messagesactually appear prior to a program waiting for input. What constitutes an interactive device is implementation-defined.

    [ Note: more stringent correspondences between abstract and actual semantics may be defined by each implementation.— end note ]

    10 [ Note: operators can be regrouped according to the usual mathematical rules only where the operators really are asso-ciative or commutative.7) For example, in the following fragment

    int a, b;

    /∗ ... ∗/a = a + 32760 + b + 5;

    the expression statement behaves exactly the same as

    a = (((a + 32760) + b) + 5);

    due to the associativity and precedence of these operators. Thus, the result of the sum (a + 32760) is next added to b,and that result is then added to 5 which results in the value assigned to a. On a machine in which overflows produce an

    6) An implementation can offer additional library I/O functions as an extension. Implementations that do so should treat calls to those functions as“observable behavior” as well.

    7) Overloaded operators are never assumed to be associative or commutative.

    Draft

  • 9 General 1.9 Program execution

    exception and in which the range of values representable by an int is [-32768,+32767], the implementation cannotrewrite this expression as

    a = ((a + b) + 32765);

    since if the values for a and b were, respectively, -32754 and -15, the sum a + b would produce an exception while theoriginal expression would not; nor can the expression be rewritten either as

    a = ((a + 32765) + b);

    or

    a = (a + (b + 32765));

    since the values for a and b might have been, respectively, 4 and -8 or -17 and 12. However on a machine in which over-flows do not produce an exception and in which the results of overflows are reversible, the above expression statementcan be rewritten by the implementation in any of the above ways because the same result will occur. — end note ]

    11 A full-expression is an expression that is not a subexpression of another expression. If a language construct is defined toproduce an implicit call of a function, a use of the language construct is considered to be an expression for the purposesof this definition. A call to a destructor generated at the end of the lifetime of an object other than a temporary object isan implicit full-expression. Conversions applied to the result of an expression in order to satisfy the requirements of thelanguage construct in which the expression appears are also considered to be part of the full-expression.

    [ Example:

    struct S {

    S(int i): I(i) { }

    int& v() { return I; }

    private:

    int I;

    };

    S s1(1); // full-expression is call of S::S(int)S s2 = 2; // full-expression is call of S::S(int)

    void f() {

    if (S(3).v()) // full-expression includes lvalue-to-rvalue and// int to bool conversions, performed before// temporary is deleted at end of full-expression

    { }

    }

    — end example ]

    12 [ Note: the evaluation of a full-expression can include the evaluation of subexpressions that are not lexically part of thefull-expression. For example, subexpressions involved in evaluating default argument expressions (8.3.6) are consideredto be created in the expression that calls the function, not the expression that defines the default argument. — end note ]

    13 Accessing an object designated by a volatile lvalue (3.10), modifying an object, calling a library I/O function, orcalling a function that does any of those operations are all side effects, which are changes in the state of the execution

    Draft

  • 1.9 Program execution General 10

    environment. Evaluation of an expression (or a sub-expression) in general includes both value computations (includingdetermining the identity of an object for lvalue evaluation and fetching a value previously assigned to an object forrvalue evaluation) and initiation of side effects. When a call to a library I/O function returns or an access to a volatileobject is evaluated the side effect is considered complete, even though some external actions implied by the call (suchas the I/O itself) or by the volatile access may not have completed yet.

    14 Sequenced before is an asymmetric, transitive, pair-wise relation between evaluations executed by a single thread, whichinduces a partial order among those evaluations. Given any two evaluations A and B, if A is sequenced before B, then theexecution of A shall precede the execution of B. If A is not sequenced before B and B is not sequenced before A, then Aand B are unsequenced. [ Note: The execution of unsequenced evaluations can overlap. — end note ] Evaluations A andB are indeterminately sequenced when either A is sequenced before B or B is sequenced before A, but it is unspecifiedwhich. [ Note: Indeterminately sequenced evaluations cannot overlap, but either could be executed first. — end note ]

    15 Every value computation and side effect associated with a full-expression is sequenced before every value computationand side effect associated with the next full-expression to be evaluated.8).

    16 Except where noted, evaluations of operands of individual operators and of subexpressions of individual expressions areunsequenced. [ Note: In an expression that is evaluated more than once during the execution of a program, unsequencedand indeterminately sequenced evaluations of its subexpressions need not be performed consistently in different evalua-tions. — end note ] The value computations of the operands of an operator are sequenced before the value computationof the result of the operator. If a side effect on a scalar object is unsequenced relative to either a different side effect onthe same scalar object or a value computation using the value of the same scalar object, the behavior is undefined.

    [ Example:

    i = v[i++]; // the behavior is undefinedi = 7, i++, i++; // i becomes 9

    i = ++i + 1; // the behavior is undefinedi = i + 1; // the value of i is incremented

    — end example ]

    When calling a function (whether or not the function is inline), every value computation and side effect associated withany argument expression, or with the postfix expression designating the called function, is sequenced before execution ofevery expression or statement in the body of the called function. [ Note: Value computations and side effects associatedwith different argument expressions are unsequenced. — end note ] Every evaluation in the calling function (includingother function calls) that is not otherwise specifically sequenced before or after the execution of the body of the calledfunction is indeterminately sequenced with respect to the execution of the called function.9) Several contexts in C++cause evaluation of a function call, even though no corresponding function call syntax appears in the translation unit.[ Example: Evaluation of a new expression invokes one or more allocation and constructor functions; see 5.3.4. Foranother example, invocation of a conversion function (12.3.2) can arise in contexts in which no function call syntaxappears. — end example ] The sequencing constraints on the execution of the called function (as described above) arefeatures of the function calls as evaluated, whatever the syntax of the expression that calls the function might be.

    8) As specified in 12.2, after a full-expression is evaluated, a sequence of zero or more invocations of destructor functions for temporary objectstakes place, usually in reverse order of the construction of each temporary object.

    9)In other words, function executions do not interleave with each other.

    Draft

  • 11 General 1.10 Multi-threaded executions and data races

    1.10 Multi-threaded executions and data races [intro.multithread]

    1 Under a hosted implementation, a C++ program can have more than one thread of execution (a.k.a. thread) running con-currently. The execution of each thread proceeds as defined by the remainder of this standard. The execution of the entireprogram consists of an execution of all of its threads. [ Note: Usually the execution can be viewed as an interleaving ofall its threads. However, some kinds of atomic operations, for example, allow executions inconsistent with a simple in-terleaving, as described below. — end note ] Under a freestanding implementation, it is implementation-defined whethera program can have more than one thread of execution.

    2 The value of an object visible to a thread T at a particular point might be the initial value of the object, a value assignedto the object by T , or a value assigned to the object by another thread, according to the rules below. [ Note: In some cases,there may instead be undefined behavior. Much of this section is motivated by the desire to support atomic operationswith explicit and detailed visibility constraints. However, it also implicitly supports a simpler view for more restrictedprograms. — end note ]

    3 Two expression evaluations conflict if one of them modifies a memory location and the other one accesses or modifiesthe same memory location.

    4 The library defines a number of atomic operations (clause 29) and operations on locks (clause 30) that are speciallyidentified as synchronization operations. These operations play a special role in making assignments in one thread vis-ible to another. A synchronization operation is either an acquire operation or a release operation, or both, on one ormore memory locations; the semantics of these are described below. In addition, there are relaxed atomic operations,which are not synchronization operations, and atomic read-modify-write operations, which have special characteristics,also described below. [ Note: For example, a call that acquires a lock will perform an acquire operation on the locationscomprising the lock. Correspondingly, a call that releases the same lock will perform a release operation on those samelocations. Informally, performing a release operation on A forces prior side effects on other memory locations to becomevisible to other threads that later perform an acquire operation on A. We do not include “relaxed” atomic operations assynchronization operations although, like synchronization operations, they cannot contribute to data races. — end note ]

    5 All modifications to a particular atomic object M occur in some particular total order, called the modification order ofM. If A and B are modifications of an atomic object M, and A happens before B, then A shall precede B in the modifi-cation order of M, which is defined below. [ Note: This states that the modification orders must respect happens before.— end note ] [ Note: There is a separate order for each scalar object. There is no requirement that these can be com-

    bined into a single total order for all objects. In general this will be impossible since different threads may observemodifications to different variables in inconsistent orders. — end note ]

    6 A release sequence on an atomic object M is a maximal contiguous sub-sequence of side effects in the modificationorder of M, where the first operation is a release, and every subsequent operation

    — is performed by the same thread that performed the release, or

    — is a non-relaxed atomic read-modify-write operation.

    7 An evaluation A that performs a release operation on an object M synchronizes with an evaluation B that performs anacquire operation on M and reads a value written by any side effect in the release sequence headed by A. [ Note: Exceptin the specified cases, reading a later value does not necessarily ensure visibility as described below. Such a requirementwould sometimes interfere with efficient implementation. — end note ] [ Note: The specifications of the synchronizationoperations define when one reads the value written by another. For atomic variables, the definition is clear. All operationson a given lock occur in a single total order. Each lock acquisition “reads the value written” by the last lock release.— end note ]

    Draft

  • 1.10 Multi-threaded executions and data races General 12

    8 An evaluation A happens before an evaluation B if:

    — A is sequenced before B, or

    — A synchronizes with B, or

    — for some evaluation X, A happens before X and X happens before B.

    9 A visible side effect A on an object M with respect to a value computation B of M satisfies the conditions:

    — A happens before B, and

    — there is no other side effect X to M such that A happens before X and X happens before B.

    The value of a non-atomic scalar object M, as determined by evaluation B, shall be the value stored by the visible sideeffect A. [ Note: If there is ambiguity about which side effect to a non-atomic object is visible, then there is a datarace, and the behavior is undefined. — end note ] [ Note: This states that operations on ordinary variables are not visiblyreordered. This is not actually detectable without data races, but it is necessary to ensure that data races, as definedhere, and with suitable restrictions on the use of atomics, correspond to data races in a simple interleaved (sequentiallyconsistent) execution. — end note ]

    10 The visible sequence of side effects on an atomic object M, with respect to a value computation B of M, is a maximalcontiguous sub-sequence of side effects in the modification order of M, where the first side effect is visible with respectto B, and for every subsequent side effect, it is not the case that B happens before it. The value of an atomic object M, asdetermined by evaluation B, shall be the value stored by some operation in the visible sequence of M with respect to B.Furthermore, if a value computation A of an atomic object M happens before a value computation B of M, and the valuecomputed by A corresponds to the value stored by side effect X, then the value computed by B shall either equal the valuecomputed by A, or be the value stored by side effect Y , where Y follows X in the modification order of M. [ Note: Thiseffectively disallows compiler reordering of atomic operations to a single object, even if both operations are “relaxed”loads. By doing so, we effectively make the “cache coherence” guarantee provided by most hardware available to C++atomic operations. — end note ] [ Note: The visible sequence depends on the happens before relation, which depends onthe values observed by loads of atomics, which we are restricting here. The intended reading is that there must exist anassociation of atomic loads with modifications they observe that, together with suitably chosen modification orders andthe happens before relation derived as described above, satisfy the resulting constraints as imposed here. — end note ]

    11 The execution of a program contains a data race if it contains two conflicting actions in different threads, at least one ofwhich is not atomic, and neither happens before the other. Any such data race results in undefined behavior. [ Note: It canbe shown that programs that correctly use simple locks to prevent all data races, and use no other synchronization oper-ations, behave as though the executions of their constituent threads were simply interleaved, with each observed valueof an object being the last value assigned in that interleaving. This is normally referred to as “sequential consistency”.However, this applies only to race-free programs, and race-free programs cannot observe most program transformationsthat do not change single-threaded program semantics. In fact, most single-threaded program transformations continueto be allowed, since any program that behaves differently as a result must perform an undefined operation. — end note ]

    12 [ Note: Compiler transformations that introduce assignments to a potentially shared memory location that would not bemodified by the abstract machine are generally precluded by this standard, since such an assignment might overwriteanother assignment by a different thread in cases in which an abstract machine execution would not have encountereda data race. This includes implementations of data member assignment that overwrite adjacent members in separatememory locations. We also generally preclude reordering of atomic loads in cases in which the atomics in question mayalias, since this may violate the “visible sequence” rules. — end note ]

    Draft

  • 13 General 1.11 Acknowledgments

    13 [ Note: Transformations that introduce a speculative read of a potentially shared memory location may not preserve thesemantics of the C++ program as defined in this standard, since they potentially introduce a data race. However, theyare typically valid in the context of an optimizing compiler that targets a specific machine with well-defined semanticsfor data races. They would be invalid for a hypothetical machine that is not tolerant of races or provides hardware racedetection. — end note ]

    1.11 Acknowledgments [intro.ack]

    1 The C++ programming language as described in this International Standard is based on the language as describedin Chapter R (Reference Manual) of Stroustrup: The C++ Programming Language (second edition, Addison-WesleyPublishing Company, ISBN 0-201-53992-6, copyright c©1991 AT&T). That, in turn, is based on the C programminglanguage as described in Appendix A of Kernighan and Ritchie: The C Programming Language (Prentice-Hall, 1978,ISBN 0-13-110163-3, copyright c©1978 AT&T).

    2 Portions of the library clauses of this International Standard are based on work by P.J. Plauger, which was published asThe Draft Standard C++ Library (Prentice-Hall, ISBN 0-13-117003-1, copyright c©1995 P.J. Plauger).

    3 All rights in these originals are reserved.

    Draft

  • 1.11 Acknowledgments General 14

    Draft

  • Chapter 2 Lexical conventions [lex]

    1 The text of the program is kept in units called source files in this International Standard. A source file together with allthe headers (17.4.1.2) and source files included (16.2) via the preprocessing directive #include, less any source linesskipped by any of the conditional inclusion (16.1) preprocessing directives, is called a translation unit. [ Note: a C++program need not all be translated at the same time. — end note ]

    2 [ Note: previously translated translation units and instantiation units can be preserved individually or in libraries. Theseparate translation units of a program communicate (3.5) by (for example) calls to functions whose identifiers have ex-ternal linkage, manipulation of objects whose identifiers have external linkage, or manipulation of data files. Translationunits can be separately translated and then later linked to produce an executable program (3.5). — end note ]

    2.1 Phases of translation [lex.phases]

    1 The precedence among the syntax rules of translation is specified by the following phases.10)

    1. Physical source file characters are mapped, in an implementation