Sujet : Re: constexpr keyword is unnecessary
De : thiago.adams (at) *nospam* gmail.com (Thiago Adams)
Groupes : comp.lang.cDate : 29. Oct 2024, 18:48:29
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vfr75e$1l8b8$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
User-Agent : Mozilla Thunderbird
On 29/10/2024 14:26, Richard Harnden wrote:
On 28/10/2024 11:58, Thiago Adams wrote:
>
For instance,
>
const unsigned char ch = 1234;
>
GCC:
warning: unsigned conversion from 'int' to 'unsigned char' changes value from '1234' to '210' [-Woverflow]
>
The programmer might intend this behavior; in that case, the "alarm" should be acknowledged.
If that is what you want, then why not simply say:
const unsigned char ch = 210;
Or change it to the char to a short (or int, long, etc).
?
It's a good and helpful warning. I cannot see why you'd want to ignore it.
Do you expect to remember that 1234 really equals 210 in five years time?
When I use a concrete example, people often assume I’m discussing a specific case, even if I explicitly state that it’s just an example (and this happens all the time).
Here’s the main idea: Sometimes, we have warnings in our code. I’m proposing a feature that identifies warnings that necessary exists.
The issue with disabling warnings in specific code regions is that, if the code is changed to remove the warning, the disable command often isn’t removed. Additionally, with code modifications, we might unintentionally end up disabling more warnings than originally intended.
I also presented a sample with cast.
For the *specific sample* of course there is an alternative of just wring the final number.
Another sample:
In GCC
const int i = 1231231231231*123123123123123;
This is a warning about overflow. If the overflow is intentional, for instance, to observe the final result, the programmer can choose to dismiss the warning.