home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!paladin.american.edu!howland.reston.ans.net!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!babypuss.mitre.org!djb
- From: djb@babypuss.mitre.org (David J. Braunegg)
- Newsgroups: gnu.g++.bug
- Subject: (none)
- Date: 22 Jan 1993 21:49:39 -0500
- Organization: GNUs Not Usenet
- Lines: 53
- Sender: daemon@cis.ohio-state.edu
- Approved: bug-g++@prep.ai.mit.edu
- Distribution: gnu
- Message-ID: <9301222229.AA06362@bambam.mitre.org>
-
- This is a bug report for g++ (gcc) version 2.3.3, running on a Sun
- Sparcstation, OS 4.1.
-
-
- Your declaration of
-
- ostream& operator<<(void *p);
-
- in iostream.h is in error. Unless you have truly defined operator<<
- on void* pointers so that it modifies the pointer, the declaration
- should instead be
-
- ostream& operator<<(const void *p);
-
-
-
- For example, the following program should *not* issue the const
- violation warning that it does.
-
-
-
- #include <iostream.h>
-
- int main()
- {
- const char *foo = "stuff";
-
- cout << (const void *)foo << endl;
-
- return 0;
- }
-
-
-
-
- djb@bambam>g++ -g -Wall test.cc
- test.cc: In function `int main ()':
- test.cc:7: warning: argument passing of non-`const *' pointer from `const *'
- test.cc:7: warning: argument passing of non-`const *' pointer from `const *'
-
-
-
- I have encountered this warning frequently, because in my code I am
- often writing out the address of an object to help identify it. If
- foo is `const <class> *', then I must cast it to `const void *' and
- *not* to `void *' when printing its address in order to avoid a const
- violation.
-
-
- Please contact me if you have any further questions.
-
- Dave
-
-