One of the common use-cases for the overloadable attribute is to create small
wrapper functions around an existing function that was previously not
overloadable. For example:
// C Library v1 void foo(int i); // C Library v2 // Note the __asm__("foo"); it ensures that foo isn't mangled. Our docs state // that the mangling isn't stable, so we encourage users to either use __asm__ // to force a stable name, or to only use overloads with internal linkage __attribute__((overloadable)) int foo(int i) __asm__("foo"); __attribute__((overloadable)) static inline int foo(long l) { assert(l <= INT_MAX && l >= INT_MIN && "Out of bounds number!"); return foo(l); }
"Library v2" is suboptimal for a few reasons:
- It can break existing code; if users added int foo(int); declarations to their code, upgrading to library v2 requires that the users either remove these declarations or add __attribute__((overloadable)) to them.
- The __asm__ name is both redundant and easy to typo (or forget to update, or ...).
- The __asm__ name also makes it quite a bit more difficult to hide all of this behind a macro, since we need a different name for each function.
This patch aims to fix these usability challenges with the idea of transparent
function overloads.
For any overloadable function in C, one of the overloads is allowed to be
transparent. Transparency means that the name will not be mangled, and later
redeclarations of that particular overload don't require
__attribute__((overloadable)).
Users can make an overload transparent by using the transparently_overloadable
spelling of overloadable.
This also includes a bugfix for how we handled overloadable functions declared
inside functions. I can factor that out if that would make life easier. :)