https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55791
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |msebor at gcc dot gnu.org --- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> --- The detection does have to happen in the parser; after that, argument expressions like 10 * sizeof (char*) may be folded into constants with no trace of the original subexpressions. Besides malloc (and realloc) the warning should also work for the two-argument calloc as well as for user-defined allocation functions declared with attribute alloc_size. The design will also need to consider how to handle conditional and binary expressions involving multiple sizeof expressions such as malloc(x ? sizeof (A) : sizeof (B)) and malloc(sizeof (A) + sizeof (B)). Both explicit conversions (i.e., casts) and implicit conversions (e.g., when passing the allocation result as an argument to a function) should be considered as well.