Article View: gnu.g++.lib.bug
Article #464[djb@babypuss.mitre.org : ]
From: Brendan Kehoe
Date: Wed, 27 Jan 1993 03:25
Date: Wed, 27 Jan 1993 03:25
66 lines
2280 bytes
2280 bytes
------- Start of forwarded message -------
From: djb@babypuss.mitre.org (David J. Braunegg)
To: bug-g++@prep.ai.mit.edu
Cc: djb@babypuss.mitre.org
Date: Fri, 22 Jan 93 17:29:04 -0500
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
------- End of forwarded message -------
--
Brendan Kehoe brendan@cygnus.com
Cygnus Support, Mountain View, CA +1 415 903 1400
``In a cruel and imperfect world,'' says critic Rex Reed,
``[Audrey Hepburn] was living proof that God could still create perfection.''
Technical Details
Message-ID:
<9301262333.AA29619@cygnus.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!ames!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!cygnus.com!brendanShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!ames!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!cygnus.com!brendan From: brendan@cygnus.com (Brendan Kehoe) Newsgroups: gnu.g++.lib.bug Subject: [djb@babypuss.mitre.org : ] Date: 26 Jan 1993 22:25:34 -0500 Organization: GNUs Not Usenet Lines: 67 Sender: daemon@cis.ohio-state.edu Approved: bug-lib-g++@prep.ai.mit.edu Distribution: gnu Message-ID: <9301262333.AA29619@cygnus.com> Reply-To: brendan@cygnus.com (Brendan Kehoe)