[Bug middle-end/96987] [11 regression] warning 'ptr' may be used uninitialized const pointer parameter

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Sep 16 14:12:18 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96987

--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
A void pointer is usually cast to one to a complete type that's then used to
access the object (e.g., bsearch).  But not every instance of every warning
should be expected to indicate a bug.  Most only suggest that there might be
one.  The documented purpose of GCC warnings is to "report constructions that
are not inherently erroneous but that are risky or suggest there may have been
an error."  This rare use is one such case.  It was considered when the warning
was designed and deemed an acceptable trade-off.  (The attribute was added to
help accommodate  it.)

If adding support for attribute access to the D front end isn't feasible to
mark up the function and avoid the warning that way, I would suggest removing
the const qualifier from the pointer (following the practice of the C++
standard garbage collector APIs) or providing an non-const overload. 
Alternatively, writing into a byte of the allocated memory will prevent the
warning as well.


More information about the Gcc-bugs mailing list