https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88737
Bug ID: 88737 Summary: RFE: Track ownership moves Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: neal at walfield dot org Target Milestone: --- I would like an attribute to indicate that ownership of an argument is moved to the function. That is, any subsequent accesses to the variable should be considered invalid, and gcc should emit a warning, if possible. Consider the following example: ``` #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]) { int *a = malloc(sizeof(int)); *a = 1; printf("%d\n", *a); free(a); printf("%d\n", *a); return 0; } ``` Compiling this with -Wall (using gcc 6.3.0-18+deb9u1 from Debian) does not emit a warning even though there is a use-after-free bug. Although freeing a variable is the most obvious example of this pattern, this pattern often arises when dealing with pointers. This RFE is based on my experience using Rust's lifetimes, which prevent this type of error in Rust.