This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Builtins in `std'
Mark Mitchell <mark@codesourcery.com> writes:
| Those are driven by the necessacity of having ::fabs and std::fabs
| referring to the same entity (ideally, the one provided by the C
| library).
|
| I understand. I expected that you would handle this in V3 by doing:
|
| namespace std {
| extern "C" double fabs (double);
| }
|
| Then, since you probably want to take advantage of the builtin
| optimizations:
|
| namespace std {
| extern "C" inline double fabs (double d)
| { return __builtin_fabs (d); }
| }
OK. But since we're violating the ODR here, is there a chance that
a user notices it? (I'm asking because I'm not sure)
| ... Note that there is no `#include <math>' here;
Ok, got it.
| However, we need to ensure that `&::fabs == &std::fabs' evaluates to
| true. On the other hand we have to overload fabs() in std:: only.
|
| Right. Does my trick above work?
Yes, it is fine if can tell me that the definition provided by the C
library won't clash with the above.
| | So, any objections to just not doing the insertion into `std'?
|
| Yes. #include <cmath> puts fabs in std:: only.
|
| I don't think this is relevant -- but I could be wrong. I *think*
| we're talking at cross-purposes.
Yes, I overlooked the <math.h> missing part.
| In particular, I'm trying to fix a regression on code like:
|
| extern "C" double fabs (double) {}
|
| namespace std {
| double fabs (double) {}
| }
|
| (A user is allowed to do this; they might have a different library
| implementation or something.)
The above is not allowed.
| These two functions get the same mangled name. The reason boils down
| to the fact that the compiler implicitly declared `std::fabs', rather
| than leaving that to the (most excellent) V3 headers to do.
|
| To sum up, I think there's a different between C and C++. In C, we
| want to make `fabs' a builtin, because uesrs are allowed to call it
| without including the relevant headers.
100% agreed.
Furthermore, in C++ users are not allowed to add overloads in std::,
and since fabs() may have C-linkage, they are not allowed to do the
trick above.
| ... If we're going to optimize
| it, we need to make it a builtin. However, in C++ you have to include
| the header first, or you're not writing legal C++. And, that means
| that the compiler doesn't need to predeclare the function.
|
| Does that make more sense now?
Yes, I now understand your point. But I don't think users are allowed
to do the example you're trying to fix.
Or am I still talking about a different thing?
-- Gaby