Thread View: gnu.gcc.bug
2 messages
2 total messages
Started by Randy Smith
Tue, 10 Dec 1996 00:00
Bug in gcc 2.7.2 on platform alpha-dec-osf3.2
Author: Randy Smith
Date: Tue, 10 Dec 1996 00:00
Date: Tue, 10 Dec 1996 00:00
64 lines
1896 bytes
1896 bytes
Compiling the following file:
----------
class A {
public:
A();
int y;
char c;
};
class B {
public:
B();
char a, b;
};
main(int argc, char **argv)
{
A a;
B &b = static_cast<B&>(a);
}
----------
with the command line:
g++ -c test.cc
for gcc 2.7.2 on platform alpha-dec-osf3.2:
$ g++ -v
gcc -v
Reading specs from /usr/local/gnu/lib/gcc-lib/alpha-dec-osf3.2/2.7.2/specs
gcc version 2.7.2
does *not* produce any error messages, where I believe that it
should. Quoting from Ellis&Stroustrup, _The Annotated C++ Reference
Manual_, page 414, ANSI/ISO Resolutions section $5.2.4:
static_cast<T>(e) casts e to a T exactly as (T)e would have done
provided there is an implicit conversion from T to the type of e of
an implicit conversion from the type of e to T. Otherwise,
static_cast<T>(e) is an error.
This looks like a bug to me, but I would also welcome someone
explaining to me why it isn't. I replaced the static cast with a
direct assignment, and that produced errors, implying that there is
at least no implicit conversion from A-->B.
This problem has also been noted (in a substantantially more
complicated example) in a gcc 2.7.1 cross compiler from
alpha->i386. In that more complicated example, I verified that
there was also no implict conversion from B-->A.
-- Randy
Re: Bug in gcc 2.7.2 on platform alpha-dec-osf3.2
Author: Alexandre Oliva
Date: Wed, 11 Dec 1996 00:00
Date: Wed, 11 Dec 1996 00:00
30 lines
1523 bytes
1523 bytes
Randy Smith writes:
> main(int argc, char **argv)
> {
> A a;
> B &b = static_cast<B&>(a);
> }
> does *not* produce any error messages, where I believe that it
> should.
That's right.
> This looks like a bug to me, but I would also welcome someone
> explaining to me why it isn't.
This is a bug, indeed, but it is a bug in g++ frontend, not in gcc, so
it should have been submitted to bug-g++. Anyway, you need not bother
submitting it again, because the current development snapshot does
produce an error message, so the bug should be fixed when gcc/g++
2.8.0 is released. It should produce the following error message:
test.cc: In function `int main(int, char **)':
test.cc:23: cannot convert type `A' to type `B &'
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br
Universidade Estadual de Campinas, SP, Brasil
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