1S01EC14882:2003(曰 Foreword ISO (the Intemational Organization for Standardzation)and IEC (the Intemational Electrotechnical Commission)fomm the specialzed system for worldwide standardization,National bodies that are members of ISO or IEC participate in the development of Intemational Standards through technical committees established by the respective organization to deal with particular fields of technical activity.ISO and IEC technical committees collaborate in fields of mutual interest Other international organizations.govemmental and non-governmental,in iaison with ISO and IEC.also take part in the work.In the field of information echnology.ISO and IEC have established a joint lechnical committee,ISO/IEC JTC 1. Intemational Standards are drafted in accordance with the rules ghen in the ISO/IEC Directives.Part 2. The main task of the joint technical committee is to prepare Intemational Standards.Draft International Standards adopted by the joint technical committee are circulated to nabional bodies for voting Publication as an Intemational Standard requires approval by at least 75%of the member bodies casting a vote. Attention is drawn to the possibility that some of the elements of this document may be the subject of patent rights.ISO and IEC shall not be held responsible for identifying ary or all such patent rights. ISOMEC 14882 was prepared by Joint Technical Commttee ISO/IEC JTC 1.Anformation fechnalogy. Subcommittee SC 22.Programming languages.their environments and system sofware interfaces. This second edition cancels and replaces the first edtion (ISOVIEC 14882:1998).which has been technically revised. ISOnEC 2003-All rights reserved XXVI
ISO/IEC 14882:2003(E) © ISO/IEC 2003 — All rights reserved xxvii Foreword ISO (the International Organization for Standardization) and IEC (the International Electrotechnical Commission) form the specialized system for worldwide standardization. National bodies that are members of ISO or IEC participate in the development of International Standards through technical committees established by the respective organization to deal with particular fields of technical activity. ISO and IEC technical committees collaborate in fields of mutual interest. Other international organizations, governmental and non-governmental, in liaison with ISO and IEC, also take part in the work. In the field of information technology, ISO and IEC have established a joint technical committee, ISO/IEC JTC 1. International Standards are drafted in accordance with the rules given in the ISO/IEC Directives, Part 2. The main task of the joint technical committee is to prepare International Standards. Draft International Standards adopted by the joint technical committee are circulated to national bodies for voting. Publication as an International Standard requires approval by at least 75 % of the member bodies casting a vote. Attention is drawn to the possibility that some of the elements of this document may be the subject of patent rights. ISO and IEC shall not be held responsible for identifying any or all such patent rights. ISO/IEC 14882 was prepared by Joint Technical Committee ISO/IEC JTC 1, Information technology, Subcommittee SC 22, Programming languages, their environments and system software interfaces. This second edition cancels and replaces the first edition (ISO/IEC 14882:1998), which has been technically revised
INTERNATIONAL STANDARD CISOIEC IS0/1EC14882:2003E) Programming languages-CH 1 General [intro] 1.1 Scope lintro.scopel This Inemnationsl Standard specifies requirements for implementations of the CH prugramming language. The first such requrirement is that they implement the language,and so this Internatonal Standard also detines C++Ccher requirements and relmcstions of the first requurement appenr at various plnces within this International Standard. C+is a general purpose programming language hased on the C programming languuge as described in ISO/IEC 9899:1990 Progrmmming iatguages C(1.2).In addition to the faxilities provided by C.CH provides additiceal data types,classes.templates,exceptioes,namespaces,inline finctions,operator over- loading.firction rame overlouding,refererces,free sore manxgement operators,and additional library facilities. 1.2 Normative referenees intro.reB The fullowing refererxed documents are indispenssble for the application of this document For dated refererces,only the edition cited applies.For undated refererces,the latest edition of the referenced document (including any amendments)applies. ISO/IEC 2382 (all parts),hgfarmimton feciuology-Pocabuiary ISOMEC9syW.I9网,P'gromming languages-C ISO/TEC 10646-1:2000,informanon recimology -Untversal Mulriple-Oerer Coded Character Set (Part I:Arclineelure and Razie Mulrilingonl Piare 2 The library descnbed in clause 7of ISO/IEC 9899:1990 and clause 7 of ISO/IEC 9899/Amd 1:1995 is here. irafter called the SandardCLbrary. 1.3 Terms et definitions lintro.defs] For the purposes of this documem,the definitions given in ISOVIEC 2382 and the following apply. 17.I defines additional terms that are used only in clauses 17 through 27. Terms that are used only in a small portion of this Irpernational Standard are defined where they are used and italicized where they are defined. 1.3.1 argument [defns.argument an expression in the comma separated list bonded by the parentheses in a furction call expression,a sequerce of'preprocessing tokens in the comma-separaled list bounded by the parentheses in a function-like mnero invocation.the operand of throv.or an expression,lype-id or fempxae-mme in the comma- separaed list bonded by the angle beuckets in a templale instantiation.Also known as an acm/argnmenr of cctof purroeler. Twlnd7nCCliuySuCy. 1
_ ______________________________________________________________________________________ INTERNATIONAL STANDARD ISO/IEC ISO/IEC 14882:2003(E) _ ______________________________________________________________________________________ Programming languages – C+ + 1 General [intro] 1.1 Scope [intro.scope] 1 This International Standard specifies requirements for implementations of the C + + programming language. The first such requirement is that they implement the language, and so this International Standard also defines C+ +. Other requirements 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/IEC 9899:1990 Programming languages – C (1.2). In addition to the facilities provided by C, C + + provides additional data types, classes, templates, exceptions, namespaces, inline functions, operator overloading, function name overloading, references, free store management operators, and additional library facilities. 1.2 Normative references [intro.refs] 1 ISO/IEC 2382 (all parts), Information technology – Vocabulary ISO/IEC 9899:1999, Programming languages – C ISO/IEC 10646-1:2000, Information technology – Universal Multiple-Octet Coded Character Set (UCS) – Part 1: Architecture and Basic Multilingual Plane 2 The library described in clause 7 of ISO/IEC 9899:1990 and clause 7 of ISO/IEC 9899/Amd.1:1995 is hereinafter called the Standard C Library. 1) 1.3 Terms et definitions [intro.defs] 2 Terms that are used only in a small portion of this International Standard are defined where they are used and italicized where they are defined. 1.3.1 argument [defns.argument] an expression in the comma-separated list bounded by the parentheses in a function call expression, a sequence of preprocessing tokens in the comma-separated list bounded by the parentheses in a function-like macro invocation, the operand of throw, or an expression, type-id or template-name in the commaseparated list bounded by the angle brackets in a template instantiation. Also known as an actual argument or actual parameter. __________________ 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. 1 The following referenced documents are indispensable for the application of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies. For the purposes of this document, the definitions given in ISO/IEC 2382 and the following apply. 17.1 defines additional terms that are used only in clauses 17 through 27
1S01EC14882:2003HE) ISOIEC 1.3.2 digneslic mesaagr 1 Genrral 1.3.2 diagnostic message lefs.压ag6sicl a message belonging to an implementarion-defined subset of the implementation's output messages 13.3 dynamic fype [defns.dynamic.typel the type of the most derived ohject (1 8)to which the hvalue denceed hy an Ivalue expression refers [Erow- ple:if a pointer (83.1)p whose static type is"pointer to class "is puinting to nobject of class D,derived frum B(clause 10).the dyramic type of the expression "p is"D."References (8.3.2)are treated similarly. The dynamic type of an rvalue expression is its stutic type. 1.3.4 ill-formed program [defms.ill.formed] input to a C++implementation that is not a well-fommed program (1.314). 1.3.5 implementation-defined behavior [defns.impl.defined] hehavior.for a well-formed propram construet and correct data,that depends on the implementation and that each implementation shall document. 1.3.6 implementation limits defns.impl.limits restrictions impused upon progrums hy the implementation. 1.3.7 locale-specific behavior [defns.locale.specificl behavior that depends on loenl conventions of nstionality,culture.nnd Inngunge that cach implemerention shall document 1.3.8 multibyte character defus.multibyte a sequence of one or more bytes representingg a member of the extended character set of either the source or the execution environment.The extended character set is a supenset of the basic character st(2.2) 1.3.9 parameter [defns.purumeter an object or reference declared as part of a function deckaration or definition.or in the catch clause of an exeeption hondler.that nequires n value on entry to the funetion or liandler:an idemtifier from the comm- separmed list bounded by the parentheses immediately following the macro name in a function-like macro definition,ar a templare-parmerer.Parameers are also knon as formal argents or fovmal paramerers. 1.3.10 signature [defnx signature the information abou.a fiurxction that participates in overluad resoluiun (13.3):the types of its parameters and,if the functon is a class member.the er-qualifiers (if amy)on the function itself and the class in which the member functon is declaredThe signnture ofn function template spcializmion includes the types of its template arguments (14.5.5.1). 1支.11 statie type Isf线itie.pe the type of an expression(3.9)which type results from analysis of the peogram without coesidering execu- tiun semamies.The static type of an expression depends only on the form of the program in which the expression appears,and does not change while the program is executing 1.3.12 undefined behavior [defns.undefined ochavior.such as might arise upon use of'an erronoous program construet or emroneous data.for which this Intemational Standard imposes no requirements Undefined behavior may also be expected when this International Standard omits the description of ary explicit definition of'behavior.INore:permissible unde- fined behavor manges from ignoring the situstion completcly with unpredictable results.to behaving during translation or program execution in a documented manner chamcteristic of the envrironment (with or with- out the issuance of a diagnostic message)to terminating a translation or execution (with the issuae ofa diagnostic message).Many erroneous prugram constructs do not engender undefined behavior.they are ome porticipan 2
ISO/IEC 14882:2003(E) ISO/IEC 1.3.2 diagnostic message 1 General 1.3.2 diagnostic message [defns.diagnostic] a message belonging to an implementation-defined subset of the implementation’s output messages. 1.3.3 dynamic type [defns.dynamic.type] the type of the most derived object (1.8) to which the lvalue denoted by an lvalue expression refers. [Example: if a pointer (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. ] The dynamic type of an rvalue expression is its static type. 1.3.4 ill-formed program [defns.ill.formed] input to a C + + implementation that is not a well-formed program (1.3.14). 1.3.5 implementation-defined behavior [defns.impl.defined] behavior, for a well-formed program construct and correct data, that depends on the implementation and that each implementation shall document. 1.3.6 implementation limits [defns.impl.limits] restrictions imposed upon programs by the implementation. 1.3.7 locale-specific behavior [defns.locale.specific] behavior that depends on local conventions of nationality, culture, and language that each implementation shall document. 1.3.8 multibyte character [defns.multibyte] a sequence of one or more bytes representing a member of the extended character set of either the source or the execution environment. The extended character set is a superset of the basic character set (2.2). 1.3.9 parameter [defns.parameter] an object or reference declared as part of a function declaration or definition, or in the catch clause of an exception handler, that acquires a value on entry to the function or handler; an identifier from the commaseparated list bounded by 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.10 signature [defns.signature] the information about a function that participates in overload resolution (13.3): the types of its parameters and, if the function is a class member, the cv- qualifiers (if any) on the function itself and the class in which the member function is declared.2) The signature of a function template specialization includes the types of its template arguments (14.5.5.1). 1.3.11 static type [defns.static.type] the type of an expression (3.9), which type results from analysis of the program without considering execution semantics. The static type of an expression depends only on the form of the program in which the expression appears, and does not change while the program is executing. 1.3.12 undefined behavior [defns.undefined] behavior, such as might arise upon use of an erroneous program construct or erroneous data, for which this International Standard imposes no requirements. Undefined behavior may also be expected when this International Standard omits the description of any explicit definition of behavior. [Note: permissible undefined behavior ranges from ignoring the situation completely with unpredictable results, to behaving during translation or program execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message). Many erroneous program constructs do not engender undefined behavior; they are __________________ 2) Function signatures do not include return type, because that does not participate in overload resolution. 2
ISOVTE IS01EC14882-2003E 1Gnrl 8 13时
ISO/IEC ISO/IEC 14882:2003(E) 1 General 1.3.12 undefined behavior required to be diagnosed. ] 1.3.13 unspecified behavior [defns.unspecified] behavior, for a well-formed program construct and correct data, that depends on the implementation. The implementation is not required to document which behavior occurs. [Note: usually, the range of possible behaviors is delineated by this International Standard. ] 1.3.14 well-formed program [defns.well.formed] a 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 those rules containing an explicit notation that “no diagnostic is required” or which are described as resulting in “undefined behavior.” 2 Although this International Standard states only requirements on C + + implementations, those requirements are often easier to understand if they are phrased as requirements on programs, parts of programs, or execution of programs. Such requirements 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 execute3) that program. — If a program contains a violation of any diagnosable rule, a conforming implementation 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 places no 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 not specified, but each implementation shall supply them to complete the definitions according to the description in the library clauses. 4 For functions, function templates, objects, and values, the library clauses specify declarations. Implementations shall supply 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 names by 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 provides definitions for standard library entities, as necessary, while combining translation units to form a complete C + + program (2.1). 7 Two kinds of implementations are defined: hosted and freestanding. For a hosted implementation, this International Standard defines the set of available libraries. A freestanding implementation is one in which execution may take place without the benefit of an operating system, and has an implementation-defined set of libraries that includes certain language-support libraries (17.4.1.3). 8 A conforming implementation may have extensions (including additional library functions), provided they do not alter the behavior of any well-formed program. Implementations are required to diagnose programs that use such extensions that are ill-formed according to this International Standard. Having done so, however, they can compile and execute such programs. __________________ 3) “Correct execution” can include undefined behavior, depending on the data being processed; see 1.3 and 1.9. 3