[Bug c++/52321] New: poor diagnostic of invalid cast
igodard at pacbell dot net
gcc-bugzilla@gcc.gnu.org
Tue Feb 21 01:36:00 GMT 2012
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.
More information about the Gcc-bugs
mailing list