Reputation: 2836
Under Lvalue-to-rvalue conversion the C++23 standard says ([conv.lval]#1, emphasis mine):
A glvalue of a non-function, non-array type
T
can be converted to a prvalue.44 IfT
is an incomplete type, a program that necessitates this conversion is ill-formed. IfT
is a non-class type, the type of the prvalue is the cv-unqualified version ofT
. Otherwise, the type of the prvalue isT
.45
Could you give an example, where this happens?
i.e:
T
which is a non-class,std::remove_cvref_t<T>
Upvotes: 0
Views: 125
Reputation: 76688
For example:
const int i = 0;
/*const*/ int j = i;
i
is a non-class type const
-qualified glvalue. In order to initialize j
, a standard conversion sequence from this glvalue to a prvalue of type int
is required. The lvalue-to-rvalue conversion is chosen and your particular case applies.
The same applies e.g. when using the built-in arithmetic operators on i
, etc. Whether there is a qualifier on j
doesn't matter. They are ignored and the target of the conversion sequence is the unqualified type.
Also note that non-class type prvalues are never cv-qualified, so it wouldn't make sense for the conversion to not strip the qualifier.
Upvotes: 2