ret = convert_to_pointer (type, e);
goto maybe_fold;
+ case NULLPTR_TYPE:
+ /* A null pointer constant or value of type nullptr_t may be
+ converted to nullptr_t. The latter case has already been
+ handled. build_c_cast will create an additional NOP_EXPR to
+ ensure the result of the conversion is not itself a null
+ pointer constant. */
+ if (null_pointer_constant_p (expr))
+ {
+ ret = build_int_cst (type, 0);
+ goto maybe_fold;
+ }
+ break;
+
case REAL_TYPE:
ret = convert_to_real (type, e);
goto maybe_fold;
}
/* If we are converting to nullptr_t, don't say "non-scalar type" because
- the nullptr_t type is a scalar type. Only nullptr_t shall be converted
- to nullptr_t. */
+ the nullptr_t type is a scalar type. Only nullptr_t or a null pointer
+ constant shall be converted to nullptr_t. */
if (code == NULLPTR_TYPE)
{
error ("conversion from %qT to %qT", TREE_TYPE (e), type);
- inform (input_location, "only %qT can be converted to %qT", type, type);
+ inform (input_location,
+ "only %qT or a null pointer constant can be converted to %qT",
+ type, type);
}
else
error ("conversion to non-scalar type requested");