1、 INCITS/ISO/IEC 14882:2017 (2018) (ISO/IEC 14882:2017, IDT) Programming languages - C+ INCITS/ISO/IEC 14882:2017 (2018) PDF disclaimer This PDF file may contain embedded typefaces. In accordance with Adobes licensing policy, this file may be printed or viewed but shall not be edited unless the typef
2、aces which are embedded are licensed to and installed on the computer performing the editing. In downloading this file, parties accept therein the responsibility of not infringing Adobes licensing policy. The ISO Central Secretariat accepts no liability in this area. Adobe is a trademark of Adobe Sy
3、stems Incorporated. Details of the software products used to create this PDF file can be found in the General Info relative to the file; the PDF-creation parameters were optimized for printing. Every care has been taken to ensure that the file is suitable for use by ISO member bodies. In the unlikel
4、y event that a problem relating to it is found, please inform the Central Secretariat at the address given below. Adopted by INCITS (InterNational Committee for Information Technology Standards) as an American National Standard. Date of ANSI Approval: 6/29/2018 Published by American National Standar
5、ds Institute, 25 West 43rd Street, New York, New York 10036 Copyright 2018 by Information Technology Industry Council (ITI). All rights reserved. These materials are subject to copyright claims of International Standardization Organization (ISO), International Electrotechnical Commission (IEC), Amer
6、ican National Standards Institute (ANSI), and Information Technology Industry Council (ITI). Not for resale. No part of this publication may be reproduced in any form, including an electronic retrieval system, without the prior written permission of ITI. All requests pertaining to this standard shou
7、ld be submitted to ITI, 1101 K Street NW, Suite 610, Washington DC 20005. Printed in the United States of America ii ITIC 2018 All rights reserved Programming languages C+Langages de programmation C+INTERNATIONAL STANDARDISO/IEC14882Reference numberISO/IEC 14882:2017(E)Fifth edition2017-12 ISO/IEC 2
8、017ii ISO/IEC 2017 All rights reservedCOPYRIGHT PROTECTED DOCUMENT ISO/IEC 2017, Published in SwitzerlandAll rights reserved. Unless otherwise specified, no part of this publication may be reproduced or utilized otherwise in any form or by any means, electronic or mechanical, including photocopying,
9、 or posting on the internet or an intranet, without prior written permission. Permission can be requested from either ISO at the address below or ISOs member body in the country of the requester.ISO copyright officeCh. de Blandonnet 8 CP 401CH-1214 Vernier, Geneva, SwitzerlandTel. +41 22 749 01 11Fa
10、x +41 22 749 09 47copyrightiso.orgwww.iso.orgISO/IEC 14882:2017(E)ISO/IEC 14882:2017(E)ContentsForeword xi1 Scope 12 Normative references 23 Terms and definitions 34 General principles 74.1 Implementation compliance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74.2 Structure
11、 of this document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84.3 Syntax notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84.4 The C+ memory model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84.5 T
12、he C+ object model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94.6 Program execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.7 Multi-threaded executions and data races . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
13、54.8 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 Lexical conventions 225.1 Separate translation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225.2 Phases of translation . . . . . . . . . . . . . . . . . . . .
14、. . . . . . . . . . . . . . . . . . . 225.3 Character sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235.4 Preprocessing tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245.5 Alternative tokens . . . . . . . . . . . . .
15、 . . . . . . . . . . . . . . . . . . . . . . . . . . . 255.6 Tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255.7 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265.8 Header names . . . . . . .
16、. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265.9 Preprocessing numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265.10 Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275.11 Keywords
17、 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285.12 Operators and punctuators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295.13 Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
18、. 296 Basic concepts 396.1 Declarations and definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396.2 One-definition rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416.3 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . .
19、. . . . . . . . . . . . . . . . . . . 446.4 Name lookup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506.5 Program and linkage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636.6 Start and termination . . . . . . . . . . . . .
20、. . . . . . . . . . . . . . . . . . . . . . . . . 666.7 Storage duration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 706.8 Object lifetime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 746.9 Types . . . . . . . . . . . . . .
21、 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 776.10 Lvalues and rvalues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 836.11 Alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84Contents ISO/IEC
22、2017 All rights reserved iiiISO/IEC 14882:2017(E)7 Standard conversions 867.1 Lvalue-to-rvalue conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 877.2 Array-to-pointer conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 877.3 Function-to-po
23、inter conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 887.4 Temporary materialization conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 887.5 Qualification conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 887.6 In
24、tegral promotions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897.7 Floating-point promotion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897.8 Integral conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
25、. . . . 897.9 Floating-point conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 907.10 Floating-integral conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 907.11 Pointer conversions . . . . . . . . . . . . . . . . . . . . . . . . . . .
26、 . . . . . . . . . . . . . 907.12 Pointer to member conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 907.13 Function pointer conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 917.14 Boolean conversions . . . . . . . . . . . . . . . . . . .
27、 . . . . . . . . . . . . . . . . . . . . 917.15 Integer conversion rank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 918 Expressions 938.1 Primary expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 968.2 Postfix expressions . . .
28、. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1098.3 Unary expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1208.4 Explicit type conversion (cast notation) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1298.5 Pointer-
29、to-member operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1308.6 Multiplicative operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1318.7 Additive operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
30、1318.8 Shift operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1328.9 Relational operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1338.10 Equality operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
31、. . . . . . . . . . 1338.11 Bitwise AND operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1358.12 Bitwise exclusive OR operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1358.13 Bitwise inclusive OR operator . . . . . . . . . . . . . . . .
32、 . . . . . . . . . . . . . . . . . . 1358.14 Logical AND operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1358.15 Logical OR operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1358.16 Conditional operator . . . . . . . . . . . .
33、 . . . . . . . . . . . . . . . . . . . . . . . . . . . 1368.17 Throwing an exception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1378.18 Assignment and compound assignment operators . . . . . . . . . . . . . . . . . . . . . . . 1378.19 Comma operator . . . . . . . . .
34、 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1388.20 Constant expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1399 Statements 1449.1 Labeled statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1459.2
35、Expression statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1459.3 Compound statement or block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1459.4 Selection statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
36、. . . . 1459.5 Iteration statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1489.6 Jump statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1509.7 Declaration statement . . . . . . . . . . . . . . . . . . . . . . . . . .
37、. . . . . . . . . . . . 1529.8 Ambiguity resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153Contents ISO/IEC 2017 All rights reserved ivISO/IEC 14882:2017(E)10 Declarations 15510.1 Specifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
38、 . . . . . . . . . . . 15710.2 Enumeration declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17410.3 Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17810.4 The asm declaration . . . . . . . . . . . . . . . . . . .
39、 . . . . . . . . . . . . . . . . . . . . 19110.5 Linkage specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19110.6 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19411 Declarators 20111.1 Type names . . .
40、. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20211.2 Ambiguity resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20311.3 Meaning of declarators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2041
41、1.4 Function definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21611.5 Structured binding declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21911.6 Initializers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
42、. . . . . . . . . . . 22012 Classes 23712.1 Class names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23912.2 Class members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24112.3 Unions . . . . . . . . . . . . . . . . . .
43、 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25112.4 Local class declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25413 Derived classes 25513.1 Multiple base classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2561
44、3.2 Member name lookup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25813.3 Virtual functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26113.4 Abstract classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
45、. . . . . . . . 26514 Member access control 26714.1 Access specifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26814.2 Accessibility of base classes and base class members . . . . . . . . . . . . . . . . . . . . . . 26914.3 Friends . . . . . . . . . . . . .
46、 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27214.4 Protected member access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27514.5 Access to virtual functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27614.6 Multiple
47、access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27614.7 Nested classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27615 Special member functions 27815.1 Constructors . . . . . . . . . . . . . . . . . . . . . . . .
48、. . . . . . . . . . . . . . . . . . . 27815.2 Temporary objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28115.3 Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28315.4 Destructors . . . . . . . . . . . . . .
49、. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28615.5 Free store . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28915.6 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29115.7 Construction and destruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29815.8 Copying and moving class objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .