Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      Implicit conversions

      From cppreference.com
      <cpp‎ |language
       
       
      C++ language
      General topics
      Flow control
      Conditional execution statements
      Iteration statements (loops)
      Jump statements
      Functions
      Function declaration
      Lambda function expression
      inline specifier
      Dynamic exception specifications(until C++17*)
      noexcept specifier(C++11)
      Exceptions
      Namespaces
      Types
      Specifiers
      constexpr(C++11)
      consteval(C++20)
      constinit(C++20)
      Storage duration specifiers
      Initialization
      Expressions
      Alternative representations
      Literals
      Boolean -Integer -Floating-point
      Character -String -nullptr(C++11)
      User-defined(C++11)
      Utilities
      Attributes(C++11)
      Types
      typedef declaration
      Type alias declaration(C++11)
      Casts
      Implicit conversions
      static_cast
      const_cast
      Memory allocation
      Classes
      Class-specific function properties
      Special member functions
      Templates
      Miscellaneous
       
      Expressions
      General
      Literals
      Operators
      Conversions
       

      Implicit conversions are performed whenever an expression of some typeT1 is used in context that does not accept that type, but accepts some other typeT2; in particular:

      • when the expression is used as the argument when calling a function that is declared withT2 as parameter;
      • when the expression is used as an operand with an operator that expectsT2;
      • when initializing a new object of typeT2, includingreturn statement in a function returningT2;
      • when the expression is used in aswitch statement (T2 is integral type);
      • when the expression is used in anif statement or a loop (T2 isbool).

      The program is well-formed (compiles) only if there exists one unambiguousimplicit conversion sequence fromT1 toT2.

      If there are multiple overloads of the function or operator being called, after the implicit conversion sequence is built fromT1 to each availableT2,overload resolution rules decide which overload is compiled.

      Note: in arithmetic expressions, the destination type for the implicit conversions on the operands to binary operators is determined by a separate set of rules:usual arithmetic conversions.

      Contents

      [edit]Order of the conversions

      Implicit conversion sequence consists of the following, in this order:

      1) zero or onestandard conversion sequence;
      2) zero or oneuser-defined conversion;
      3) zero or onestandard conversion sequence (only if a user-defined conversion is used).

      When considering the argument to a constructor or to a user-defined conversion function, only one standard conversion sequence is allowed (otherwise user-defined conversions could be effectively chained). When converting from one non-class type to another non-class type, only a standard conversion sequence is allowed.

      A standard conversion sequence consists of the following, in this order:

      1) zero or one conversion from the following set:
      • lvalue-to-rvalue conversion,
      • array-to-pointer conversion, and
      • function-to-pointer conversion;
      2) zero or onenumeric promotion ornumeric conversion;
      3) zero or onefunction pointer conversion;
      (since C++17)
      4) zero or onequalification conversion.

      A user-defined conversion consists of zero or one non-explicit single-argumentconverting constructor or non-explicitconversion function call.

      An expressione is said to beimplicitly convertible toT2 if and only ifT2 can becopy-initialized frome, that is the declarationT2 t= e; is well-formed (can be compiled), for some invented temporaryt. Note that this is different fromdirect initialization (T2 t(e)), where explicit constructors and conversion functions would additionally be considered.

      [edit]Contextual conversions

      In the following contexts, the typebool is expected and the implicit conversion is performed if the declarationbool t(e); is well-formed (that is, an explicit conversion function such asexplicit T::operatorbool()const; is considered). Such expressione is said to becontextually converted tobool.

      • the controlling expression ofif,while,for;
      • the operands of the built-in logical operators!,&& and||;
      • the first operand of the conditional operator?:;
      • the predicate in astatic_assert declaration;
      • the expression in anoexcept specifier;
      • the expression in anexplicit specifier;
      (since C++20)
      (since C++11)

      In the following contexts, a context-specific typeT is expected, and the expressione of class typeE is only allowed if

      (until C++14)
      • there is exactly one typeT among the allowable types such thatE has non-explicit conversion functions whose return types are (possibly cv-qualified)T or reference to (possibly cv-qualified)T, and
      • e is implicitly convertible toT.
      (since C++14)

      Such expressione is said to becontextually implicitly converted to the specified typeT.Note that explicit conversion functions are not considered, even though they are considered in contextual conversions tobool.(since C++11)

      • the argument of thedelete-expression (T is any object pointer type);
      • integral constant expression, where a literal class is used (T is any integral or unscoped enumeration type, the selected user-defined conversion function must beconstexpr);
      • the controlling expression of theswitch statement (T is any integral or enumeration type).
      #include <cassert> template<typename T>class zero_init{    T val;public:    zero_init(): val(static_cast<T>(0)){}    zero_init(T val): val(val){}    operator T&(){return val;}    operator T()const{return val;}}; int main(){    zero_init<int> i;assert(i==0);     i=7;assert(i==7); switch(i){}// error until C++14 (more than one conversion function)// OK since C++14 (both functions convert to the same type int)switch(i+0){}// always okay (implicit conversion)}

      [edit]Value transformations

      Value transformations are conversions that change thevalue category of an expression. They take place whenever an expression appears as an operand of an operator that expects an expression of a different value category:

      • Whenever a glvalue appears as an operand of an operator that requires a prvalue for that operand, thelvalue-to-rvalue,array-to-pointer, orfunction-to-pointer standard conversions are applied to convert the expression to a prvalue.
      • Unless otherwise specified, whenever a prvalue appears as an operand of an operator that expects a glvalue for that operand, thetemporary materialization conversion is applied to convert the expression to an xvalue.
      (since C++17)

      [edit]Lvalue-to-rvalue conversion

      Anlvalue(until C++11)Aglvalue(since C++11) of any non-function, non-array typeT can be implicitly converted toanrvalue(until C++11)aprvalue(since C++11):

      • IfT is not a class type, the type of thervalue(until C++11)prvalue(since C++11) is the cv-unqualified version ofT.
      • Otherwise, the type of thervalue(until C++11)prvalue(since C++11) isT.

      If an lvalue-to-rvalue conversion from anincomplete type is required by a program, that program is ill-formed.

      Given the object to which thelvalue(until C++11)glvalue(since C++11) refers asobj:

      • When an lvalue-to-rvalue conversion occurs within the operand ofsizeof, the value contained inobj is not accessed, since that operatordoes not evaluate its operand.
      • The result of the conversion is the value contained inobj. If one ofT and the type ofobj is a signed integer type, and the other is the corresponding unsigned integer type, the result is the value of typeT with the same value representation ofobj.
      (until C++11)
      • When an lvalue-to-rvalue conversion is applied to an expressionE, the value contained inobj is not accessed if:
      • The result of the conversion is determined as follows:
      • IfT is (possibly cv-qualified)std::nullptr_t, the result is anull pointer constant.obj is not accessed by the conversion, so there is no side effect even ifT is volatile-qualified, and the glvalue can refer to an inactive member of a union.
      • Otherwise, ifT is a class type:
      • The conversioncopy-initializes atemporary of typeT from the glvalue, and the result of the conversion is a prvalue for the temporary.
      (until C++17)
      (since C++17)
      • Otherwise, ifobj contains an invalid pointer value, the behavior is implementation-defined.
      • Otherwise, if the bits in thevalue representation ofobj are not valid forobj's type, the behavior is undefined.
      • Otherwise,obj is read, and(since C++20) the result is the value contained inobj. If one ofT and the type ofobj is a signed integer type, and the other is the corresponding unsigned integer type, the result is the value of typeT with the same value representation ofobj.
      (since C++11)

      This conversion models the act of reading a value from a memory location into a CPU register.

      [edit]Array-to-pointer conversion

      Anlvalue orrvalue of type “array ofNT” or “array of unknown bound ofT” can be implicitly converted to aprvalue of type “pointer toT”.If the array is a prvalue,temporary materialization occurs.(since C++17) The resulting pointer refers to the first element of the array (seeArray-to-pointer decay for details).

      [edit]Function-to-pointer conversion

      Anlvalue of function type can be implicitly converted to aprvaluepointer to that function. This does not apply to non-static member functions because lvalues that refer to non-static member functions do not exist.

      Temporary materialization

      Aprvalue of any complete typeT can be converted to an xvalue of the same typeT. This conversion initializes atemporary object of type T from the prvalue by evaluating the prvalue with the temporary object as its result object, and produces an xvalue denoting the temporary object.

      IfT is a class or array of class type, it must have an accessible and non-deleted destructor.

      struct S{int m;};int i= S().m;// member access expects glvalue as of C++17;// S() prvalue is converted to xvalue

      Temporary materialization occurs in the following situations:

      Note that temporary materialization doesnot occur when initializing an object from a prvalue of the same type (bydirect-initialization orcopy-initialization): such object is initialized directly from the initializer. This ensures “guaranteed copy elision”.

      (since C++17)

      [edit]Integral promotion

      prvalues of small integral types (such aschar) and unscoped enumeration types may be converted to prvalues of larger integral types (such asint). In particular,arithmetic operators do not accept types smaller thanint as arguments, and integral promotions are automatically applied after lvalue-to-rvalue conversion, if applicable. This conversion always preserves the value.

      The following implicit conversions in this section are classified asintegral promotions.

      Note that for a given source type, the destination type of integral promotion is unique, And all other conversions are not promotions. For example,overload resolution chooseschar ->int (promotion) overchar ->short (conversion).

      [edit]Promotion from integral types

      A prvalue of typebool can be converted to a prvalue of typeint, withfalse becoming0 andtrue becoming1.

      For a prvalueval of an integral typeT exceptbool:

      1) Ifval is the result of an lvalue-to-rvalue conversion applied to abit-field,
      • val can be converted to a prvalue of typeint ifint can represent all the values of the bit-field;
      • otherwise,val can be converted tounsignedint ifunsignedint can represent all the values of the bit-field;
      • otherwise,val can be converted according to the rules specified in item (3).
      2) Otherwise (val is not converted from a bit-field),
      • ifT ischar8_t,(since C++20)char16_t,char32_t or(since C++11)wchar_t,val can be converted according to the rules specified in item (3);
      • otherwise, if theinteger conversion rank ofT is lower than the rank ofint:
      • val can be converted to a prvalue of typeint ifint can represent all the values ofT;
      • otherwise,val can be converted to a prvalue of typeunsignedint.
      3) In the cases specified by item (1) (a converted bit-field not fittingunsignedint) or item (2) (T is one of the given character types),val can be converted to a prvalue of the first of the following types that can represent all the values of its underlying type:
      • int
      • unsignedint
      • long
      • unsignedlong
      • longlong
      • unsignedlonglong
      • the underlying type ofT
      (since C++11)

      [edit]Promotion from enumeration types

      A prvalue of an unscopedenumeration type whose underlying type is not fixed can be converted to a prvalue of the first type from the following list able to hold their entire value range:

      • int
      • unsignedint
      • long
      • unsignedlong
      • itsinteger conversion rank is greater than the rank oflonglong,
      • its integer conversion rank is the lowest among all extended integer types, and
      • it is signed if there are two types with the lowest integer conversion rank among all extended integer types.
      (since C++11)


      A prvalue of an unscoped enumeration type whose underlying type is fixed can be converted to its underlying type. Moreover, if the underlying type is also subject to integral promotion, to the promoted underlying type. Conversion to the unpromoted underlying type is better for the purposes ofoverload resolution.

      (since C++11)

      [edit]Floating-point promotion

      Aprvalue of typefloat can be converted to a prvalue of typedouble. The value does not change.

      This conversion is calledfloating-point promotion.

      [edit]Numeric conversions

      Unlike the promotions, numeric conversions may change the values, with potential loss of precision.

      [edit]Integral conversions

      Aprvalue of an integer type or of an unscoped enumeration type can be converted to any other integer type. If the conversion is listed under integral promotions, it is a promotion and not a conversion.

      • If the destination type is unsigned, the resulting value is the smallest unsigned value equal to the source valuemodulo2n
        wheren is the number of bits used to represent the destination type.
      • That is, depending on whether the destination type is wider or narrower, signed integers are sign-extended[1] or truncated and unsigned integers are zero-extended or truncated respectively.
      • If the destination type is signed, the value does not change if the source integer can be represented in the destination type. Otherwise the result isimplementation-defined(until C++20)the unique value of the destination type equal to the source value modulo2n
        wheren is the number of bits used to represent the destination type
        (since C++20)
        (note that this is different fromsigned integer arithmetic overflow, which is undefined).
      • If the source type isbool, the valuefalse is converted to zero and the valuetrue is converted to the value one of the destination type (note that if the destination type isint, this is an integer promotion, not an integer conversion).
      • If the destination type isbool, this is aboolean conversion (see below).
      1. This only applies if the arithmetic is two's complement which is only required for theexact-width integer types. Note, however, that at the moment all platforms with a C++ compiler use two's complement arithmetic.

      [edit]Floating-point conversions

      Aprvalue of a floating-point type can be converted to a prvalue of any other floating-point type.

      (until C++23)

      Aprvalue of a floating-point type can be converted to a prvalue of any other floating-point type with a greater or equalfloating-point conversion rank.

      Aprvalue of a standard floating-point type can be converted to a prvalue of any other standard floating-point type.

      static_cast can be used to explicitly convert a prvalue of floating-point type to any other floating-point type.

      (since C++23)

      If the conversion is listed under floating-point promotions, it is a promotion and not a conversion.

      • If the source value can be represented exactly in the destination type, it does not change.
      • If the source value is between two representable values of the destination type, the result is one of those two values (it is implementation-defined which one, although if IEEE arithmetic is supported, rounding defaultsto nearest).
      • Otherwise, the behavior is undefined.

      [edit]Floating–integral conversions

      Aprvalue of floating-point type can be converted to a prvalue of any integer type. The fractional part is truncated, that is, the fractional part is discarded.

      • If the truncated value cannot fit into the destination type, the behavior is undefined (even when the destination type is unsigned, modulo arithmetic does not apply).
      • If the destination type isbool, this is a boolean conversion (seebelow).

      A prvalue of integer or unscoped enumeration type can be converted to a prvalue of any floating-point type. The result is exact if possible.

      • If the value can fit into the destination type but cannot be represented exactly, it is implementation defined whether the closest higher or the closest lower representable value will be selected, although if IEEE arithmetic is supported, rounding defaultsto nearest.
      • If the value cannot fit into the destination type, the behavior is undefined.
      • If the source type isbool, the valuefalse is converted to zero, and the valuetrue is converted to one.

      [edit]Pointer conversions

      Anull pointer constant can be converted to any pointer type, and the result is the null pointer value of that type. Such conversion (known asnull pointer conversion) is allowed to convert to a cv-qualified type as a single conversion, that is, it is not considered a combination of numeric and qualifying conversions.

      Aprvalue pointer to any (optionally cv-qualified) object typeT can be converted to a prvalue pointer to (identically cv-qualified)void. The resulting pointer represents the same location in memory as the original pointer value.

      • If the original pointer is a null pointer value, the result is a null pointer value of the destination type.

      A prvalueptr of type “pointer to (possibly cv-qualified)Derived” can be converted to a prvalue of type “pointer to (possibly cv-qualified)Base”, whereBase is abase class ofDerived, andDerived is acomplete class type. If theBase is inaccessible or ambiguous, the program is ill-formed.

      • Ifptr is a null pointer value, the result is also a null pointer value.
      • Otherwise, ifBase is avirtual base class ofDerived andptr does not point to an object whose type issimilar toDerived and that is within itslifetime or within its period of construction or destruction, the behavior is undefined.
      • Otherwise, the result is a pointer to the base class subobject of the derived class object.

      [edit]Pointer-to-member conversions

      Anull pointer constant can be converted to any pointer-to-member type, and the result is the null member pointer value of that type. Such conversion (known asnull member pointer conversion) is allowed to convert to a cv-qualified type as a single conversion, that is, it is not considered a combination of numeric and qualifying conversions.

      Aprvalue of type “pointer to member ofBase of type (possibly cv-qualified)T” can be converted to a prvalue of type “pointer to member ofDerived of type (identically cv-qualified)T”, whereBase is a base class ofDerived, andDerived is a complete class type. IfBase is inaccessible, ambiguous, or virtual base ofDerived or is a base of some intermediate virtual base ofDerived, the program is ill-formed.

      • IfDerived does not contain the original member and is not a base class of the class containing the original member, the behavior is undefined.
      • Otherwise, the resulting pointer can be dereferenced with aDerived object, and it will access the member within theBase base subobject of thatDerived object.

      [edit]Boolean conversions

      Aprvalue of integral, floating-point, unscoped enumeration, pointer, and pointer-to-member types can be converted to a prvalue of typebool.

      The value zero (for integral, floating-point, and unscoped enumeration) and the null pointer and the null pointer-to-member values becomefalse. All other values becometrue.

      In the context of adirect-initialization, abool object may be initialized from a prvalue of typestd::nullptr_t, includingnullptr. The resulting value isfalse. However, this is not considered to be an implicit conversion.

      (since C++11)

      [edit]Qualification conversions

      Generally speaking:

      • Aprvalue of type pointer tocv-qualified typeT can be converted to a prvalue pointer to a more cv-qualified same typeT (in other words, constness and volatility can be added).
      • A prvalue of type pointer to member of cv-qualified typeT in classX can be converted to a prvalue pointer to member ofmore cv-qualified typeT in classX.

      The formal definition of “qualification conversion” is givenbelow.

      [edit]Similar types

      Informally, two types aresimilar if, ignoring top-level cv-qualification:

      • they are the same type; or
      • they are both pointers, and the pointed-to types are similar; or
      • they are both pointers to member of the same class, and the types of the pointed-to members are similar; or
      • they are both arrays and the array element types are similar.

      For example:

      • constint*const* andint** are similar;
      • int(*)(int*) andint(*)(constint*) are not similar;
      • constint(*)(int*) andint(*)(int*) are not similar;
      • int(*)(int*const) andint(*)(int*) are similar (they are the same type);
      • std::pair<int,int> andstd::pair<constint,int> are not similar.

      Formally, type similarity is defined in terms of qualification-decomposition.

      Aqualification-decomposition of a typeT is a sequence of componentscv_i andP_i such thatT is “cv_0 P_0 cv_1 P_1 ... cv_n−1 P_n−1 cv_n U” for non-negativen, where

      • eachcv_i is a set ofconst andvolatile, and
      • eachP_i is
      • “pointer to”,
      • “pointer to member of classC_i of type”,
      • “array ofN_i”, or
      • “array of unknown bound of”.

      IfP_i designates an array, the cv-qualifierscv_i+1 on the element type are also taken as the cv-qualifierscv_i of the array.

      // T is “pointer to pointer to const int”, it has 3 qualification-decompositions:// n = 0 -> cv_0 is empty, U is “pointer to pointer to const int”// n = 1 -> cv_0 is empty, P_0 is “pointer to”,//          cv_1 is empty, U is “pointer to const int”// n = 2 -> cv_0 is empty, P_0 is “pointer to”,//          cv_1 is empty, P_1 is “pointer to”,//          cv_2 is “const", U is “int”using T=constint**; // substitute any of the following type to U gives one of the decompositions:// U = U0 -> the decomposition with n = 0: U0// U = U1 -> the decomposition with n = 1: pointer to [U1]// U = U2 -> the decomposition with n = 2: pointer to [pointer to [const U2]]using U2=int;using U1=const U2*;using U0= U1*;

      Two typesT1 andT2 aresimilar if there exists a qualification-decomposition for each of them, where all following conditions are satisfied for the two qualification-decompositions:

      • They have the samen.
      • The types denoted byU are the same.
      • The correspondingP_i components are the sameor one is “array ofN_i” and the other is “array of unknown bound of”(since C++20) for alli.
      // the qualification-decomposition with n = 2:// pointer to [volatile pointer to [const int]]using T1=constint*volatile*; // the qualification-decomposition with n = 2:// const pointer to [pointer to [int]]using T2=int**const; // For the two qualification-decompositions above// although cv_0, cv_1 and cv_2 are all different,// they have the same n, U, P_0 and P_1,// therefore types T1 and T2 are similar.

      [edit]Combining cv-qualifications

      In the description below, the longest qualification-decomposition of typeTn is denoted asDn, and its components are denoted ascvn_i andPn_i.

      A prvalue expression of typeT1 can be converted to typeT2 if all following conditions are satisfied:

      • T1 andT2 are similar.
      • For every non-zeroi, ifconst is incv1_i, thenconst is also incv2_i, and similarly forvolatile.
      • For every non-zeroi, ifcv1_i andcv2_i are different, thenconst is incv2_k for everyk in[1i).

      Thequalification-combined type of two typesT1 andT2 is a typeT3 similar toT1 such that

      • cv3_0 is empty,
      • for every non-zeroi,cv3_i is the union ofcv1_i andcv2_i, and
      • ifcv3_i is different fromcv1_i orc2_i, thenconst is added tocv3_k for everyk in[1i).
      (until C++20)

      Thequalification-combined type of two typesT1 andT2 is a typeT3 similar toT1, whereD3 satisfies all following conditions:

      • cv3_0 is empty.
      • For every non-zeroi,cv3_i is the union ofcv1_i andcv2_i.
      • IfP1_i orP2_i is “array of unknown bound of”,P3_i is “array of unknown bound of”, otherwise it isP1_i.
      • Ifcv3_i is different fromcv1_i orcv2_i, orP3_i is different fromP1_i orP2_i, thenconst is added tocv3_k for everyk in[1i).

      A prvalue of typeT1 can be converted to typeT2 if the qualification-combined type ofT1 andT2 is cv-unqualifiedT2.

      (since C++20)
      // longest qualification-decomposition of T1 (n = 2):// pointer to [pointer to [char]]using T1=char**; // longest qualification-decomposition of T2 (n = 2):// pointer to [pointer to [const char]]using T2=constchar**; // Determining the cv3_i and T_i components of D3 (n = 2):// cv3_1 = empty (union of empty cv1_1 and empty cv2_1)// cv3_2 = “const” (union of empty cv1_2 and “const” cv2_2)// P3_0 = “pointer to” (no array of unknown bound, use P1_0)// P3_1 = “pointer to” (no array of unknown bound, use P1_1)// All components except cv_2 are the same, cv3_2 is different from cv1_2,// therefore add “const” to cv3_k for each k in [1, 2): cv3_1 becomes “const”.// T3 is “pointer to const pointer to const char”, i.e., const char* const *.using T3=/* the qualification-combined type of T1 and T2 */; int main(){constchar c='c';char* pc;    T1 ppc=&pc;    T2 pcc= ppc;// Error: T3 is not the same as cv-unqualified T2,//        no implicit conversion. *pcc=&c;*pc='C';// If the erroneous assignment above is allowed,// the const object “c” may be modified.}

      Note that in the C programming language,const/volatile can be added to the first level only:

      char** p=0;char*const* p1= p;// OK in C and C++constchar*const* p2= p;// error in C, OK in C++

      Function pointer conversions

      • Aprvalue of type pointer to non-throwing function can be converted to a prvalue pointer to potentially-throwing function.
      • A prvalue of type pointer to non-throwing member function can be converted to a prvalue pointer to potentially-throwing member function.
      void(*p)();void(**pp)()noexcept=&p;// error: cannot convert to pointer to noexcept function struct S{typedefvoid(*p)();    operator p();};void(*q)()noexcept= S();// error: cannot convert to pointer to noexcept function
      (since C++17)

      [edit]The safe bool problem

      Until C++11, designing a class that should be usable in boolean contexts (e.g.if(obj){ ...}) presented a problem: given a user-defined conversion function, such asT::operatorbool()const;, the implicit conversion sequence allowed one additional standard conversion sequence after that function call, which means the resultantbool could be converted toint, allowing such code asobj<<1; orint i= obj;.

      One early solution for this can be seen instd::basic_ios, which initially definesoperatorvoid*, so that the code such asif(std::cin){...} compiles becausevoid* is convertible tobool, butint n=std::cout; does not compile becausevoid* is not convertible toint. This still allows nonsense code such asdeletestd::cout; to compile.

      Many pre-C++11 third party libraries were designed with a more elaborate solution, known as theSafe Bool idiom.std::basic_ios also allowed this idiom viaLWG issue 468, andoperatorvoid* was replaced (seenotes).

      Since C++11,explicit bool conversion can also be used to resolve the safe bool problem.

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      CWG 170C++98the behavior of pointer-to-member conversions was unclear
      if the derived class does not have the original member
      made clear
      CWG 172C++98enumeration type was promoted based on its underlying typebased on its value range instead
      CWG 330
      (N4261)
      C++98the conversion fromdouble*const(*p)[3]
      todoubleconst*const(*p)[3] was invalid
      made valid
      CWG 519C++98null pointer values were not guaranteed to be
      preserved when converting to another pointer type
      always preserved
      CWG 616C++98the behavior of lvalue to rvalue conversion of
      any uninitialized object and pointer objects
      of invalid values was always undefined
      indeterminateunsignedchar
      is allowed; use of invalid pointers
      is implementation-defined
      CWG 685C++98the underlying type of an enumeration type was
      not prioritized in integral promotion if it is fixed
      prioritized
      CWG 707C++98integer to floating point conversion
      had defined behavior in all cases
      the behavior is undefined if
      the value being converted is
      out of the destination range
      CWG 1423C++11std::nullptr_t was convertible tobool
      in both direct- and copy-initialization
      direct-initialization only
      CWG 1773C++11a name expression that appears in a potentially-evaluated
      expression such that the object named is not odr-used might
      still be evaluated during an lvalue-to-rvalue conversion
      not evaluated
      CWG 1781C++11std::nullptr_t tobool was considered an implicit
      conversion even though it is only valid for direct-initialization
      no longer considered
      an implicit conversion
      CWG 1787C++98the behavior of reading from an indeterminate
      unsignedchar cached in a register was undefined
      made well-defined
      CWG 1981C++11contextual conversions considered explicit conversion functionsnot considered
      CWG 2140C++11it was unclear whether lvalue-to-rvalue conversions from
      std::nullptr_t lvalues fetch these lvalues from memory
      not fetched
      CWG 2310C++98for derived-to-base pointer conversions and
      base-to-derived pointer-to-member conversions,
      the derived class type could be incomplete
      must be complete
      CWG 2484C++20char8_t andchar16_t had different integral
      promotion strategies, but they can fit both of them
      char8_t should be promoted
      in the same way aschar16_t
      CWG 2485C++98integral promotions involving bit-fields were not specified wellimproved the specification
      CWG 2813C++23temporary materialization would occur when an explicit
      object member function of a class prvalue is invoked
      will not occur
      in this case
      CWG 2861C++98a pointer to a type-inaccessible object could be
      converted a pointer to a base class subobject
      the behavior is
      undefined in this case
      CWG 2879C++17temporary materialization conversion was applied on prvalue
      as an operand of an operator that expects glvalue
      not applied in some cases
      CWG 2899C++98lvalue-to-rvalue conversions could be applied to lvalues
      designating objects with invalid value representations
      the behavior is
      undefined in this case
      CWG 2901C++98the result of lvalue-to-rvalue conversion from anunsignedint
      lvalue referring to anint object with value-1 was unclear
      made clear

      [edit]See also

      C documentation forImplicit conversions
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/language/implicit_conversion&oldid=179768"

      [8]ページ先頭

      ©2009-2025 Movatter.jp