This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52321] poor diagnostic of invalid cast
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 21 Feb 2012 11:08:07 +0000
- Subject: [Bug c++/52321] poor diagnostic of invalid cast
- Auto-submitted: auto-generated
- References: <bug-52321-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52321
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
Severity|normal |enhancement
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-02-21 11:08:07 UTC ---
Comeau online gives:
"ComeauTest.c", line 5: error: invalid type conversion
Clang gives:
l.cc:5:17: error: static_cast from 'foo *' to 'bar *' is not allowed
So G++ is no worse at least.
It wouldn't be as simple as just checking if the operand is a pointer/reference
to incomplete type when a static_cast fails, e.g. this fails because of casting
away const, not because the type is incomplete:
class foo;
int main() {
const foo* f;
static_cast<void*>(f);
}
There are lots of reasons a static_cast could be invalid (inaccessible bases,
virtual bases, casting away const etc. and that's just for casting Class1* to
Class2*) so if the diagnostic is improved it should cover more than just
casting from a pointer/reference to (possibly cv-qualified) incomplete type.