home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13416 < prev    next >
Encoding:
Text File  |  1992-09-08  |  2.4 KB  |  58 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!uunet.ca!frumious!pat
  3. From: pat@frumious.uucp (Patrick Smith)
  4. Subject: Re: defining cast operators outside classes
  5. Message-ID: <1992Sep9.003435.440@frumious.uucp>
  6. Date: Wed, 9 Sep 1992 00:34:35 GMT
  7. Reply-To: uunet.ca!frumious!pat
  8. References: <TMB.92Sep7162324@arolla.idiap.ch> <1992Sep8.173613.25113@taumet.com>
  9. Organization: None
  10. Lines: 46
  11.  
  12. steve@taumet.com (Steve Clamage) writes:
  13. |The semantics depend on which non-class declarations are visible,
  14. |which is not normally the case in C++.  (There is a somewhat
  15. |parallel case:  You omit one overloaded function declaration and
  16. |an unintended function is called.  Maybe someone can think of a way
  17. |to solve that problem in the language.)
  18.  
  19.  
  20. Here's one expensive, but I think otherwise reasonable, idea.
  21. This doesn't involve any changes to the language; the intent
  22. is for a compiler to produce appropriate warning messages.
  23.  
  24.  
  25. During compilation, the compiler would record the formal parameter
  26. types of every function (including inline functions, static functions,
  27. and functions declared but not defined).  It would also record the
  28. actual argument types for every function call, and which function
  29. each call resolved to (compile-time resolution, so calls to virtual
  30. functions should resolve to the base class versions).  All this
  31. information could perhaps be stored in the .o files or in files
  32. associated with the .o files.
  33.  
  34. At a later point in time, perhaps while linking the executable,
  35. the compiler would scan the list of function calls, and determine
  36. which function each call would resolve to if all the functions
  37. declarations were visible at the point where the call was made.
  38. If the call resolves to a different function than earlier, or if
  39. the call is now ambiguous, then the compiler should issue a warning
  40. message.
  41.  
  42. It is important to list all the functions declared, not just the
  43. ones defined.  If a function is declared in places where it can't
  44. be used, but not declared in places where it could be used, then
  45. the linker might not include the function definition when linking
  46. the final program.
  47.  
  48.  
  49. I guess this is the sort of thing one might expect a C++ lint to do.
  50. As I said, it's probably quite expensive; I don't think I'd want it
  51. done on every compile.  But it might be nice to have a compiler
  52. switch that would allow this checking to be requested occasionally.
  53.  
  54. -- 
  55. Patrick Smith
  56. uunet.ca!frumious!pat
  57. pat%frumious.uucp@uunet.ca
  58.