[Bug libstdc++/20647] Wrong typeid for incomplete types
--- Comment #6 from frederic dot riss at gmail dot com 2005-11-06 16:33 --- I nearly forgot that I submitted this bug report... I got myself a version of the C++ standard since I submitted that, and I just had a look at the part describing typeid : 5.2.8.4 reads : "When typeid is applied to a type-id, [...]. If the type of the type-id is a class type or a reference to a class type, the class shall be completely-defined." I believe A* in 2.C qualifies a a reference to a not-completely defined class type, and thus shouldn't be passed to std::typeid. I'm not an expert in standard reading, but it seems to me that the current behaviour isn't really a bug. If possible, I would be glad to see a warning emited by GCC in that case, because I hit that problem in real-world code (generic callback system using boost::any behind the scenes) and I spent hours finding out what was happening. Maybe I should suggest adding a concept check to the boost code if it is possible to detect it. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20647
[Bug libstdc++/20647] Wrong typeid for incomplete types
--- Comment #12 from frederic dot riss at gmail dot com 2005-11-06 18:35 --- When I read the standard, I thought that 'reference to a class type' was used in a sort of general way covering pointers and C++ references. I interpreted this that way because I don't see what difference it could make to a compiler and/or a developper that typeid(A*) is valid while typeid(A&) isn't. So just for my personal knowledge, what could be the rationale behind this special casing ? -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20647
[Bug c++/20647] New: Wrong typeid for incomplete types
On linux x86, using the following 2 little sources files : -- 1.C #include class A { public: A() {} }; extern void foo(const std::type_info&); int main() { foo(typeid(A*)); return 0; } --- -- 2.C #include #include class A; void foo(const std::type_info& t) { if (t == typeid(A*)) { std::cout << "OK\n"; } else { std::cout << "KO\n"; } } --- and compiling with "g++ 1.C 2.C" gives me KO output. This means that the comparison of the type_info passed to foo and the one computed by typeid(A*) where A* is an incomplete type failed. In the binary there are 2 type_info symbols for A* : % nm a.out| grep TIP1A 0804884c r _ZTIP1A 0804882c V _ZTIP1A I tried this test with many compilers and it worked with g++ 3.2 and failed with g++ 3.3, 3.4 and pre4.0 (with the same binutils). Precise versions : % gcc-3.2 --version gcc-3.2 (GCC) 3.2.3 (Debian) % gcc-3.3 --version gcc-3.3 (GCC) 3.3.5 (Debian 1:3.3.5-8ubuntu2) % gcc-3.4 --version gcc-3.4 (GCC) 3.4.4 20050209 (prerelease) (Debian 3.4.3-9ubuntu3) % gcc-4.0 --version gcc-4.0 (GCC) 4.0.0 20050301 (prerelease) (Debian 4.0-0pre6ubuntu6) -- Summary: Wrong typeid for incomplete types Product: gcc Version: 3.4.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: frederic dot riss at gmail dot com CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20647
[Bug c++/20647] Wrong typeid for incomplete types
--- Additional Comments From frederic dot riss at gmail dot com 2005-04-01 21:45 --- Andrew, I don't fully get what you mean and seeing no activity on this bug makes me wonder if you expect some feedback from me... Experimenting based on your comment I tried using -fno-weak, but it doesn't work nor seems recommended. So I wonder if what I see is a real bug, me misusing C++ or maybe a bug in the packages I use. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20647