Is there a compiler flag that makes g++ warn on promotion? I am aware of g++ compiler flags for warning on conversion (such as -Wconversion
, -Wsign-conversion
), which makes sense as conversions are potentially quite dangerous, but I do not know of a similar flag for warning on promotion. I know (think?) that promotion should be harmless in general, but still, there may be some cases where I would like to be warned when unexpected promotions arise. I have been googling for that but with no success so far.
Asked
Active
Viewed 333 times
1

Zorglub29
- 6,979
- 6
- 20
- 37
-
2There is no reason whatsoever to "Google" for a list of g++ compiler flags. They are all documented in gcc's manual page. `man gcc` gives you a complete list of all compiler flags. If it's not there it doesn't exist. – Sam Varshavchik Nov 28 '20 at 17:13
-
Thanks, indeed the manpage was much more useful than google. I guess I am born with google as my main source of information for best and worst and it is my default go to, good to get a bloody nose now and then to remember to seach manpages first ^^ . – Zorglub29 Nov 28 '20 at 17:26
-
1Remember that google is not your friend. It's purpose is to make you keep using it to farm you for data and ad revenue. – user4581301 Nov 28 '20 at 17:28
-
I know and I completely agree. The problem is, it is very convenient for answering very many "mainstream" questions and helping find information in general. – Zorglub29 Nov 28 '20 at 17:34
1 Answers
1
You can always search in GNU warning options.
-Wdouble-promotion
Give a warning when a value of type float is implicitly promoted to double.

Tony Tannous
- 14,154
- 10
- 50
- 86
-
Thanks, that's nice. Any idea how to warn when promoting in other cases, such as short to int or long, or other similar? I do not think I can find these in manpage either. I suppose it may mean they do not exist? – Zorglub29 Nov 28 '20 at 17:33
-
@Zorglub29 I can't find in the documentation anything related to integer promotion warning. And you should not either, it's well defined. – Tony Tannous Nov 28 '20 at 18:09
-
I agree that it is well defined, but this is the kind of things that may happen without always being aware of it, and may have some consequences I think. The same as 'in theory, float to double should be fine'. Except it is not when the hardware in question is much faster with 16 or 32 or 64 bits floating point (I think this is the reason for this double promotion flag, right?). Same for int in the case of 8-bit microcontrollers, I think 8 vs 16 vs 32 vs 64 bits can make a quite big difference then. – Zorglub29 Nov 28 '20 at 19:13