https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122115
Bug ID: 122115
Summary: Add warning to catch implicit type conversions
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: jg at jguk dot org
Target Milestone: ---
It would be useful to have a warning, or several warning options that could be
turned on to warn about implicit conversions. eg -Wimplicit-conversion
It shouldn't be turned on by default. It's for safety critical code, with
functional safety in mind. Some static analysis tools can do things like this.
This came out of a discussion on 80151. I was interested in size_t to bool
implicit conversion when I commented.
There are obviously many different type changes/promotions in C - off the top
of my head:
A) pointer conversions
B) in conditions, for, if, while
C) integer promotions in arithmetic
D) assignments
E) conversions in function calls
F) conversions of returns
G) enum conversions
Probably there are more. I raised (F) in the example on 80151
There are situations where all implicit conversions are useful to be have
information about, I mainly would like A, B, D, E, F. Would be great to have
(C) too.
I know gcc isn't a static analyser. Are any of these possible?
Otherwise can use clang-tidy for this specific case
https://godbolt.org/z/b17Yd4rsr
It's just an example, not real code. I marked as C, as ADA not possible for
this.