Thread View: gnu.g++.bug
1 messages
1 total messages
Started by David J. Braunegg
Sat, 23 Jan 1993 02:49
(none)
Author: David J. Braunegg
Date: Sat, 23 Jan 1993 02:49
Date: Sat, 23 Jan 1993 02:49
52 lines
1667 bytes
1667 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads