From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 712 invoked by alias); 21 Feb 2012 01:14:24 -0000 Received: (qmail 703 invoked by uid 22791); 21 Feb 2012 01:14:23 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 21 Feb 2012 01:14:11 +0000 From: "igodard at pacbell dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/52321] New: poor diagnostic of invalid cast Date: Tue, 21 Feb 2012 01:36:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: igodard at pacbell dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-02/txt/msg02033.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D52321 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 =3D static_cast(f); return 0; } gets you this: s3:~/ootbc/sim$ g++ foo.cc foo.cc: In function =C3=A2int main()=C3=A2: foo.cc:5:30: error: invalid static_cast from type =C3=A2foo*=C3=A2 to ty= pe =C3=A2bar*=C3=A2 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 =C3=A2int main()=C3=A2: foo.cc:6:3: error: invalid use of incomplete type =C3=A2struct foo=C3=A2 foo.cc:1:7: error: forward declaration of =C3=A2struct foo=C3=A2 (which is what you put out for -> on an undefined) would be *much* better.