<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Nov 22, 2013 at 3:08 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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><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></blockquote><div><br></div><div>Oh, right, I discovered that yesterday.  It's really annoying, considering that my standard testing methodology is to use the same file compiled twice.  :(</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="rtl"><div dir="ltr"><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></div></blockquote>
<div><br></div><div>MSDN says MSVC lets you get at the mangled/decorated name with .raw_name(), and this should be good enough, barring people like me recompiling the same source file with different macros.  :)</div><div>
<br></div><div>I don't see how to fix this for gcc, though, if they don't surface a unique mangled name for types in anonymous namespaces.</div></div></div></div>