3.2 - [Basic.def.odr] - [Basic. Definition .odr]

xiaoxiao2021-03-06  108

Please don't reprint this article; please don't re-publish in any form; please delete it within 24 hours of downloading this article; it is forbidden to use this article for commercial purposes.

3 Basic Concepts [Basic] 3.2 One Definition Rule [Basic.def.odr] 3 Basic Concepts [Basic] 3.2 Unique definition principles [Basic. Definition .odr] no translation unit shall contain more Than One definition of any variable, function, class Type, EnuMeration Type or Template. There is only no variable, function, class type, enumeration type, or unique definition of templates.

An expression is potentially evaluated unless either it is the operand of the sizeof operator (5.3.3), or it is the operand of the typeid operator and does not designate an lvalue of polymorphic class type (5.2.8). An object or non -overloaded function is used if its name appears in a potentially-evaluated expression. A virtual member function is used if it is not pure. An overloaded function is used if it is selected by overload resolution where referred to from a potentially-evaluated expression. [NOTE: This Covers Calls to Named Functions (5.2.2), Operator Overloading (Clause 13), User-Defined Conversions (12.3.2), Allocation Function for Placement New (5.3.4), AS Well As Non-Default Initialization (8.5). A copy constructor is used even if the call is actually elided by the implementation.] An allocation or deallocation function for a class is used by a new expression appearing in a potentially-evaluated expression as specified in 5.3.4 and 12.5 . A deallocation function for a class is used by a delete expression appearing in a potentially-evaluated expression as specified in 5.3.5 and 12.5. A copy-assignment function for a class is used by an implicitly-defined copy-assignment function for another class as specified in 12.8. A default constructor for a class is used by default initialization as specified in 8.5. A constructor for a class is used as specified in 8.5. A destructor for a class is used as specified in 12.4. expressions are evaluated valid, unless it is sizeof The operand (5.3.3) operands, or the operand of the TypeID operator, and the specified not the left value of the polymorphic class type (5.2.8). The name of the object or non-overloaded function that appears in the valid evaluation expression is applied. If the virtual member function is not pure, it is applied. When the overload function is selected in the overload parsing, it will be applied in a valid value expression.

[Note: This includes the name function (5.2.2), operator overload (chapter 13), user-defined conversion (12.3.2), place the storage allocation function (5.3.4) of the New, and non-default initialization (8.5) transfer. For the copy constructor, even if the call is actually omitted, it is still applied. 】 In a valid expression, New Expression is applied to a class of storage allocation or storage release functions, see 5.3.4 and 12.5. In a valid expression, the delete expression applies a certain type of storage release function, see 5.3.5 and 12.5. A class of replication constructors are applied in another class implicitly defined replication constructor, see 12.8. A certain type of default constructor is initialized by default, see 8.5. A certain type of constructor is applied in 8.5. A type of destructor is applied in 12.4. Every program shall contain exactly one definition of every non-inline function or object that is used in that program;. No diagnostic required The definition can appear explicitly in the program, it can be found in the standard or a user-defined library, or (when appropriated) IT is Implicitly Defined (See 12.1, 12.4 and 12.8). An Inline Function SHALL Be Defined in Every Translation Unit In Which IT IS Used. Each program must only contain each non-intramid function applied in the program. Or the only definition of objects; no need to diagnose. This definition can explicitly appear in the program, which can be implicitted in a standard or user-defined library, or (see 12.1, 12.4, and 12.8). The inline function should be defined in each of the translation units that apply it. Exactly one definition of a class is required in a translation unit if the class is used in a way that requires the class type to be complete [Example:. The following complete translation unit is well-formed, even though it never defines X: struct X; // Declare X * x1; // use x in Pointer Formation x * x2; // use x in Pointer Formation --END EXAMPLE] [NOTE: The Rules for Declarations and Expressions Describe in Which Contexts Complete Class Types Are Required. a Class Type T Must Be Complete IF:

an object of type T is defined (3.1, 5.3.4), or an lvalue-to-rvalue conversion is applied to an lvalue referring to an object of type T (4.1), or an expression is converted (either implicitly or explicitly) To Type T (Clause 4, 5.2.3, 5.2.7, 5.2.9, 5.4), or an expression That Is Not a Null Pointer Constant, And Has Type Other Than Void *, is Converted to the Type Pointer To T Reference to t useing an implicit conversion (CLAUSE 4), A dynamic_cast (5.2.9) or a static_cast (5.2.9), or a class member access Operator is Applied to an expression of type t (5.2.5), or the Typeid Operator (5.2.8) or the sizeof operator (5.3.3) Is Applied to an Operand of Type T, or a function with a return type or argument type of type t is defined (3.1) Or Called (5.2.2) OR An Lvalue Of Type T IS Assigned To (5.17).] If a class is applied in a manner that requires its full type, the class requires a unique definition. [Example: The complete translation unit is a good form, even if it does not define x: struct x; // declaration X is the structural type Struct x * x1; // Apply X x * x2 in the form of a pointer; // Form Application X - Examples] [Note: Description Declarations and definitions require a complete type of rules that require full types in Hezhu. A type T must be complete, when:

An object of type T is defined (3.1, 5.3.4), or the left value of the right value conversion is applied to an object (4.1) of a reference type T, or an expression (implicit or explicit) Convert to Type T (Chapter 4, 5.2.3, 5.2.7, 5.2.9, 5.4), or is not empty pointer, and does not have type VOID *, use implicit conversion (chapter 4), Dynamic_Cast (5.2.7 ) Or static_cast (5.2.9) is converted into a pointer or T of Type T, or the class member access operator is applied to an expression having type T (5.2.5), or the TypeID operator (5.2.8) ) Or the SIZEOF operator (5.3.3) is applied to a type T operand, or the return type or parameter type is a function of the type T is defined (3.1) or called (5.2.2), or the left of the type T The value is assigned (5.17). 】 There Can Be More Than One Definition of a class Type (Clause 9), Enumeration Type (7.2), Inline Function with External Linkage (7.1.2), Class Template (CLAUSE 14), NON-static function template (14.5.5 ), static data member of a class template (14.5.1.3), member function template (14.5.1.1), or template specialization for which some template parameters are not specified (14.7, 14.5.4) in a program provided that each definition appears In a Different Translation UNIT, AND Provided The Definitions Satisfy The Following Requirements. Given Such An Entity Named D Defined in More Than One Translation Unit, Then

each definition of D shall consist of the same sequence of tokens; and in each definition of D, corresponding names, looked up according to 3.4, shall refer to an entity defined within the definition of D, or shall refer to the same entity, after overload resolution (13.3) and after matching of partial template specialization (14.8.3), except that a name can refer to a const object with internal or no linkage if the object has the same integral or enumeration type in all definitions of D, and the object is initialized with a constant expression (5.19), and the value (but not the address) of the object is used, and the object has the same value in all definitions of D; and in each definition of D, the overloaded operators referred to, the implicit calls to conversion functions, constructors, operator new functions and operator delete functions, shall refer to the same function, or to a function defined within the definition of D; and in each definition of D, a default argument used by a n (implicit or explicit) function call is treated as if its token sequence were present in the definition of D; that is, the default argument is subject to the three requirements described above (and, if the default argument has sub-expressions with default arguments, this requirement applies recursively) .25) if D is a class with an implicitly-declared constructor (12.1), it is as if the constructor was implicitly defined in every translation unit where it is used, and the implicit definition in every translation Unit Shall Call The Same Constructor for A Base Class Member Of D. [EXAMPLE: // Translation Unit 1: struct x {x (int); x (int, int);}; x :: x (int = 0) { } Class D: public x {}; d d2;

// x (int) Called by d () // Translation Unit 2: struct x {x (int); x (int, int);}; x :: x (int = 0, int = 0) {} Class D: public x {}; // x (int, int) Called by d (); // d () 's implicit definition // violates the odr --end example ixed in d is a template, and is defined in more than one translation unit, then the last four requirements from the list above shall apply to names from the template's enclosing scope used in the template definition (14.6.3), and also to dependent names at the point of instantiation (14.6.2) . If the definitions of D satisfy all these requirements, then the program shall behave as if there were a single definition of D. If the definitions of D do not satisfy these requirements, then the behavior is undefined. class type (chapter 9), Enumeration Type (7.2), has an inline function (7.1.2) of external connectivity (7.1.5), non-static function template (14.5.5), template static data member (14.5.1.3), member Function Template (14.5.1.1), or the template transit (14.7, 14.5.4) of certain template parameters (14.7, 14.5.4), can be more than one definition, each definition appears in the program In the same translation unit, and need to meet the following requirements. Given the entity named D D is defined in more than one translation unit.

转载请注明原文地址:https://www.9cbs.com/read-97442.html

New Post(0)