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

            Bug ID: 101829
           Summary: problems with inline + __attribute__ ((malloc
                    (deallocator)))
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at cs dot ucla.edu
  Target Milestone: ---

We've recently started using __attribute__ ((malloc (deallocator))) with Gnulib
and ran into the problem that the GCC documentation in doc/extend.texi says
this:

"Since inlining one of the associated functions but not the other could result
in apparent mismatches, this form of attribute @code{malloc} is not accepted on
inline functions."

This has caused problems for us, as many of our functions are naturally inline
and are allocators or deallocators. As Bruno Haible wrote in
<https://lists.gnu.org/r/bug-gnulib/2021-08/msg00092.html>:

"The GCC documentation [1] says that the attribute 'malloc (deallocator, 1)'
does not work on inline functions. IMO, this restriction is not tenable in the
long run (because the semantics of a function don't depend on whether it is
inline or not, and because in C++ the majority of all functions is inline)."


We have resorted to merely adding comments to the functions in question. It
would be better if we could add the attributes, and then GCC can ignore them
when applied to inline functions. Alternatively, GCC could refuse to inline
such functions. Either would be preferable to the current situation.

Reply via email to