This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52321] New: poor diagnostic of invalid cast
- From: "igodard at pacbell dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 21 Feb 2012 01:14:09 +0000
- Subject: [Bug c++/52321] New: poor diagnostic of invalid cast
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52321
Bug #: 52321
Summary: poor diagnostic of invalid cast
Classification: Unclassified
Product: gcc
Version: 4.6.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: igodard@pacbell.net
This code:
class foo;
class bar {};
int main() {
foo* f;
bar* b = static_cast<bar*>(f);
return 0;
}
gets you this:
s3:~/ootbc/sim$ g++ foo.cc
foo.cc: In function Ãint main()Ã:
foo.cc:5:30: error: invalid static_cast from type Ãfoo*Ã to type Ãbar*Ã
The issued diagnostic is correct but not very helpful. The real bug is that
class foo is defined (somewhere else) as class foo : public bar {...}, but the
definitions wasn't imported. A diagnostic like:
foo.cc: In function Ãint main()Ã:
foo.cc:6:3: error: invalid use of incomplete type Ãstruct fooÃ
foo.cc:1:7: error: forward declaration of Ãstruct fooÃ
(which is what you put out for -> on an undefined) would be *much* better.