This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Builtins in `std'



  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)

I can't think of any way that they could.  But, it's hard to convince
yourself 100% of these things.

  | 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.

Because the user is not allowed to put things in `std', or for some
other reason?

If that is the reason, remember that the "user" might be some other
library implementor.

Anyhow, even if it is not pedantically correct, we should not silently
accept it, and then issue messages in the assembler that indicate that
there are two functions with the same name.  That's wicked confusing
in this case.  :-)

  | 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.

Good, that makes two of us.  Nathan, Jason, Benjamin?

  | ... 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?

Now we're on the same page.  

I'm trying to solve two problems at once: fix the bizarre error for
the code above, and also simplify the compiler.  There's a lot of
(partially wrong) logic in the compiler to deal with users redeclaring
builtins; it would be simpler if we could just avoid that hapenning by
not sticking builtins in `std'.

Thanks for working through it with me.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]