[cfe-dev] Proposed change to __builtin_overload
Howard Hinnant
hhinnant at apple.com
Mon Feb 9 07:50:53 PST 2009
On Feb 9, 2009, at 10:21 AM, Douglas Gregor wrote:
> On Feb 9, 2009, at 6:56 AM, Howard Hinnant wrote:
>> The C++ <cmath> has to implement this same logic, but gets to use C++
>> to do it. :-) I'm not suggesting that clang's <tgmath.h> be
>> implemented in C++. Only that seeing a C++ implementation may spark
>> an idea for a more flexible __builtin_overload.
>
> This is a valid question, though, and one I would have asked if I
> thought the answer might be "yes" :)
>
> Should we use C++ function overloading for <tgmath.h>? We could
> expose the ability to declare overloaded functions in C (say,
> through some function attribute __overloaded__) and relax a few of
> our if (getLangOptions().CPlusPlus) conditions to let C take the
> function-overloading path.
Fwiw the CodeWarrior compiler has/had the ability to switch into C++-
mode (and back to C) in the middle of a translation unit. The
CodeWarrior <tgmath.h> used this capability and was implemented in C+
+, using only C++ overloading (plus __typeof__), not templates, as I
recall. I.e. it was very close to Doug's suggestion above. It worked
well. I don't know if it had any advantages or disadvantages compared
to the __builtin_overload approach. It was used because we already
had the compiler tools (switching pragma) to do it, and did not
already have a __builtin_overload intrinsic, and so it was a quick and
easy path that worked.
-Howard
More information about the cfe-dev
mailing list