[Bug c++/38484] New: dynamic_cast fails to respect private base when cross casting
Here is the code: #include struct Reader { virtual ~Reader() {} }; struct Writer: virtual Reader {}; void func(Reader *r) { std::cout << dynamic_cast(r) << std::endl; } struct AccessorReader: virtual Reader {}; struct Accessor: AccessorReader, private Writer {}; int main() { Accessor a; func(static_cast(&a)); return 0; } What happens is that the dynamic_cast in "func" succeeds to convert the Reader * to a Writer *. This is unexpected due to the private inheritance of Writer in Accessor. If the virtual inheritance of Reader is changed to ordinary inheritance in both places, the problem goes away, i.e. the dynamic_cast returns 0. I am not entirely sure this is a bug, but I do know that dynamic_cast is supposed to respect privacy, and as far as I can see, there is no way, in the above code, that "func" can know that the Reader is also a Writer without violating the privacy specification. I'd be happy if someone could clarify this matter for me. Version: gcc (GCC) 4.3.0 20080428 (Red Hat 4.3.0-8) -- Summary: dynamic_cast fails to respect private base when cross casting Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: kristian dot spangsege at gmail dot com GCC build triplet: x86_64-redhat-linux GCC host triplet: x86_64-redhat-linux GCC target triplet: x86_64-redhat-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38484
[Bug c++/38484] dynamic_cast fails to respect private base when cross casting
--- Comment #1 from kristian dot spangsege at gmail dot com 2008-12-11 11:27 --- Totally BOGUS - sorry! -- kristian dot spangsege at gmail dot com changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution||INVALID http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38484
[Bug c++/27775] incorrect "ambiguous" error message with multiple inheritance and nested class.
--- Comment #2 from kristian dot spangsege at gmail dot com 2008-08-10 09:49 --- I just confirmed this bug in GCC 4.3.0. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27775
[Bug c++/34824] New: ICE with explicit copy constructor
The following small test case causes GCC to ICE: struct A; struct B { B(A const &); explicit B(B const &); }; struct A { A(B) {} }; B f(A const &a) { return B(a); } Same result (ICE) on the following two systems: gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) gcc (GCC) 4.1.1 20070105 (Red Hat 4.1.1-51) If the "explicit" keyword is dropped the ICE disappears. The same is true if the argument to A's constructor is changed to an reference. -- Summary: ICE with explicit copy constructor Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: kristian dot spangsege at gmail dot com GCC build triplet: 4.1.2 GCC host triplet: 4.1.2 GCC target triplet: 4.1.2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34824
[Bug c++/34824] ICE with explicit copy constructor
--- Comment #1 from kristian dot spangsege at gmail dot com 2008-01-17 07:37 --- Just tested it on the latest release 4.2.2 build from source with no patches and the ICE is still there. System: g++ (GCC) 4.2.2 Linux localhost.localdomain 2.6.20-1.2952.fc6 #1 SMP Wed May 16 18:59:18 EDT 2007 i686 i686 i386 GNU/Linux Fedora Core release 6 (Zod) -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34824