Given the following situation:
char const a = (i == 0) ? 0 : copy[i - 1][j];
and
char const a = (i == 0) ? '\0' : copy[i - 1][j];
Why does the first example produce the following: warning: conversion to ‘char’ from ‘int’ may alter its value [-Wconversion], and yet the second does not.
FWIW, copy is a char**.
This behaviour is not limited to char, the same can be seen for other integer sizes, so it appears it is a matter of promotion.
When one result argument to
?:is0(anint), the other result argument gets promoted to the same type — C++ requires that both possible results have the same type. Once the promotion is processed, the compiler discards the information about the original type, so at the time the warning is issued, the compiler no longer knows that what it’s warning about had been acharall along. It doesn’t complain about the second argument being demoted tocharbecause it knows the literal0is a validcharvalue.