https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|malloc attribute vs extern |malloc and cleanup |"C" in a namespace and |attributes vs extern "C" in |global and using of one in |a namespace and global and |the namespace in the global |using of one in the |one and the builtin free |namespace in the global one | |and the builtin free --- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Here is another example of the same issue but with cleanup attribute instead: ``` namespace std { extern "C" int printf (const char*, ...); } using std::printf; extern "C" int printf (const char*, ...); void foo (const char *) { printf ("%s\n", __PRETTY_FUNCTION__); } void bar () { const char a __attribute__ ((cleanup (printf))) = 0; printf ("%s calling ", __PRETTY_FUNCTION__); foo (&a); printf ("cleanup calling "); } int main () { bar (); } ``` Note if you order swap the order of declarations of printf it works. Same with free in the original testcase for malloc.