This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Reference-to-pointer argument bug?
- From: jsalz-gcc at mail dot jsalz dot net
- To: gcc at gcc dot gnu dot org
- Date: Tue, 16 Sep 2003 14:38:44 -0400 (EDT)
- Subject: Reference-to-pointer argument bug?
Thought I'd see if I'm thinking straight before I file a bug report...
Shouldn't the following be illegal? (It compiles fine under g++ 3.3.1.)
void func(void *&c) {
c = new char[8];
}
int main() {
char *v = 0;
func((void *)v); // ILLEGAL: non-const reference to temporary void*
cout << "v is " << (void*)v << endl;
void *w = 0;
func(w);
cout << "w is " << w << endl;
}
The call to func is implicitly creating a temporary void* and passing a
*non-const* reference to it. The assignment "c = new char[8]" appears to
set the value of the temporary rather than v; the program prints out "v is
0." If the signature of func were "void func(void * const &c)" this would
be permissible, but not for a non-const ref (I think); the compiler should
report an error.
Am I misunderstanding something or is the compiler failing to report an
error?
- Jon