This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/52321] poor diagnostic of invalid cast


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]