[Bug c++/78667] nonsensical attribute alloc_size silently accepted

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Dec 4 00:27:00 GMT 2016


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

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
In addition to the problem described in comment #0 GCC also accepts (though
with a warning) declarations of attribute alloc_size whose argument is a string
(even though it should be an integer).  GCC should reject such invalid
arguments with an error analogously to other similar attributes such as
aligned.  The following test case shows the difference between handling this
user error with the two attributes.

$ cat a.c && gcc -S -Wall -Wextra a.c
void f (void) __attribute__ ((aligned ("foo")));
void g (void) __attribute__ ((alloc_size ("bar")));

a.c:1:1: error: requested alignment is not an integer constant
 void f (void) __attribute__ ((aligned ("foo")));
 ^~~~
a.c:2:1: warning: alloc_size parameter outside range [-Wattributes]
 void g (void) __attribute__ ((alloc_size ("bar")));
 ^~~~


More information about the Gcc-bugs mailing list