https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106850
Bug ID: 106850 Summary: restrict type qualifier ignored on function return type Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: colomar.6.4.3 at gmail dot com Target Milestone: --- Related: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87313> The description of the restrict qualifier would lead one to think that it can be used as a standard way of describing a function that returns a unique pointer, as the [[gnu::malloc]] attribute does in GNU C. GCC currently ignores the qualifier, so it can't use it for the optimizations that [[gnu::malloc]] allows, but if GCC didn't ignore the qualifier, it could be used for that. ```c #include <err.h> #include <stddef.h> #include <stdlib.h> #include <stdio.h> [[gnu::malloc(free)]] void *restrict my_malloc(size_t size) { void *p; p = malloc(size); if (!p) err(EXIT_FAILURE, "malloc(2)"); return p; } ``` ```sh $ cc -Wall -Wextra my_malloc.c -S my_malloc.c:8:1: warning: type qualifiers ignored on function return type [-Wignored-qualifiers] 8 | my_malloc(size_t size) | ^~~~~~~~~ ``` Could you please not ignore the qualifier, and treat it as synonym of [[gnu::malloc]]?