<div dir="rtl"><div dir="ltr">MSVC is confused by the same-named source file!</div><div dir="ltr">If the code is split into t1.cpp:<br></div><div dir="ltr"><div dir="ltr"><br></div><div dir="ltr"><font face="courier new, monospace">#include <typeinfo></font></div>
<div dir="ltr"><font face="courier new, monospace">namespace { struct Foo { int a; }; }</font></div><div dir="ltr"><font face="courier new, monospace">const std::type_info &tu1() { return typeid(Foo); }</font></div><div>
<br></div><div>and t2.cpp:</div><div><br></div><div><div><font face="courier new, monospace">#include <typeinfo></font></div><div><font face="courier new, monospace">namespace { struct Foo { float b; }; }</font></div>
<div><font face="courier new, monospace">const std::type_info &tu1();</font></div><div><font face="courier new, monospace">const std::type_info &tu2() { return typeid(Foo); }</font></div><div><font face="courier new, monospace">extern "C" void printf(const char *, ...);</font></div>
<div><font face="courier new, monospace">int main() {</font></div><div><font face="courier new, monospace"> printf("tu1() == tu2(): %d\n", tu1() == tu2());</font></div><div><font face="courier new, monospace">}</font></div>
</div><div><br></div><div>then (with MSVC 2012) :</div><div><br></div><div><font face="courier new, monospace">sh-3.1$ cl -c t1.cpp && cl -c t2.cpp && cl t1.obj t2.obj && ./t1.exe<br></font></div>
<div><font face="courier new, monospace">tu1() == tu2(): 0<br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">sh-3.1$ cl t1.cpp t2.cpp && ./t1.exe<br>
</font></div><div><div><font face="courier new, monospace">tu1() == tu2(): 0<br></font></div></div><div><font face="courier new, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">(I tested both forms to see it's not related to everything compiled at once)</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div>However, your point IS valid, since when the actual names are printed (names which will be used in the strcmp):</div><div><br></div><div><div><font face="courier new, monospace"> printf("tu1().name: %s\n", tu1().name());</font></div>
<div><font face="courier new, monospace"> printf("tu2().name: %s\n", tu2().name());</font></div></div><div><br></div><div>with MSVC we get</div><div><br></div><div><div><font face="courier new, monospace">tu1() == tu2(): 0</font></div>
<div><font face="courier new, monospace">tu1().name: struct `anonymous namespace'::Foo</font></div><div><font face="courier new, monospace">tu2().name: struct `anonymous namespace'::Foo</font></div></div><div><br>
</div><div>and with gcc:</div><div><br></div><div><div><font face="courier new, monospace">tu1() == tu2(): 0</font></div><div><font face="courier new, monospace">tu1().name: *N12_GLOBAL__N_13FooE</font></div><div><font face="courier new, monospace">tu2().name: *N12_GLOBAL__N_13FooE</font></div>
</div><div><br></div><div>So when comparing type ids only, we'll miss exceptions from DLLs, while if we compare type names as well we may catch a same-named class coming from the same namespace even it's actually something different.</div>
<div><br></div><div>Given only these two options (maybe there is a better solution?), I'd still go with the first, since many C++ DLL libraries throw exceptions which *must* be caught, else the library is not usable. This is a showstopper.</div>
<div><br></div><div>OTOH, same-named classes - in the same namespace - in different TU are probably uncommon and throwing them around where they might be confused is probably even less common.</div><div><br></div><div>Yaron</div>
<div><br></div></div></div><div class="gmail_extra"><div dir="ltr"><br><br><div class="gmail_quote">2013/11/23 Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 .8ex;border-left:1px #ccc solid;border-right:1px #ccc solid;padding-left:1ex;padding-right:1ex">One other thing to think about is: are typeid names of internal types unique? MSVC seems to get it wrong, as in this prints 1:<div>
<br></div><div>$ cat t.cpp</div><div><div><div>#include <typeinfo></div>
<div>#ifdef CONFIG_1</div><div>namespace { struct Foo { int a; }; }</div><div>const std::type_info &tu1() { return typeid(Foo); }</div><div>#else</div><div>namespace { struct Foo { float b; }; }</div><div>const std::type_info &tu1();</div>
<div>const std::type_info &tu2() { return typeid(Foo); }</div><div>extern "C" void printf(const char *, ...);</div><div>int main() {</div><div> printf("tu1() == tu2(): %d\n", tu1() == tu2());</div>
<div>}</div><div>#endif</div></div><div><br></div></div><div><div>$ cl -c t.cpp && cl -c -DCONFIG_1 t.cpp -Fot2.obj && cl t.obj t2.obj && ./t.exe</div></div><div>...</div><div><div>tu1() == tu2(): 1</div>
</div></blockquote></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 22, 2013 at 1:48 PM, Yaron Keren <span dir="ltr"><<a href="mailto:yaron.keren@gmail.com" target="_blank">yaron.keren@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="rtl"><div dir="ltr">OK, fixed.</div><div dir="ltr"><br></div></div><div><div><div class="gmail_extra">
<div dir="ltr"><br><br><div class="gmail_quote">2013/11/22 Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 .8ex;border-left:1px #ccc solid;border-right:1px #ccc solid;padding-left:1ex;padding-right:1ex">Yes, this is just a property of COFF, so it should be _WIN32.</blockquote></div>
<div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On Fri, Nov 22, 2013 at 5:18 AM, Yaron Keren <span dir="ltr"><<a href="mailto:yaron.keren@gmail.com" target="_blank">yaron.keren@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="rtl"><div dir="ltr"><div dir="ltr">On Windows, typeids are different between DLLs and EXEs, so comparing type_info* will work for typeids from the same compiled file but fail for typeids from a DLL and an executable. Among other things, exceptions are not caught by handlers since can_catch() returns false.</div>
<div dir="ltr"><br></div><div dir="ltr">Defining _LIBCXX_DYNAMIC_FALLBACK does not help since can_catch() calls is_equal() with use_strcmp=false so the string names are not compared.</div><div dir="ltr"><br></div><div>This patch compares typeids first (cheap) and only they are different calls strcmp.</div>
<div dir="ltr"><br></div><div dir="ltr">If libcxxabi with Visual C++ has the same problem, __MINGW32__ should be replaced with _WIN32 in both locations.</div><span><font color="#888888"><div dir="ltr"><br>
</div><div>Yaron</div><div><br></div></font></span></div>
</div>
<br></div></div>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div></div></div>
</div></div></blockquote></div><br></div>
</div></div></div></div>