[Bug middle-end/62029] New: Requesting new warning: missing const-qualifier
mi+gcc at aldan dot algebra.com
gcc-bugzilla@gcc.gnu.org
Tue Aug 5 23:56:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62029
Bug ID: 62029
Summary: Requesting new warning: missing const-qualifier
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: mi+gcc at aldan dot algebra.com
To help facilitate "const-poisoning" of the entire body of C (and C++) code out
there, I'd like to see a new warning, that would fire, when a pointer to any
object in any scope, that could've been marked as "const", is not.
For example:
size_t
mylen(char *string)
{
if (string == NULL)
return 0;
else
return strlen(string);
}
void
example(struct object *o)
{
char *text = get_text(o);
size_t len = mylen(text);
....
}
The above code would warn in mylen, because the function's parameter could be
made const. As the developer fixes the low-level function to address the
warning, the higher level callers of these functions (such as example()) will
start warning -- and that will be a beautiful thing...
Some day the warning may even become part of -Wall.
More information about the Gcc-bugs
mailing list