Boost C++ Libraries: Ticket #1828: is_class maybe triggering a VC8 compiler bug https://svn.boost.org/trac10/ticket/1828 <p> The following code compiles with an error. However there shouldn't be an error. Basically, the line in main() fails to compile because the compiler thinks sizeof(&amp;Der::foo) is 16, which just can't be so. This case is very intricate, and any modifications to the code compile cleanly. For example, if instead of is_class, we use is_void, the code compiles; if hasher is not partially specialized for pointers, it compiles; if 'base' doesn't use CRTP, it compiles; if hasher&lt;T&gt; isn't a member variable, it compiles; if hasher is parametrized by T* or something else, it compiles. </p> <blockquote> <p> #include &lt;boost/type_traits/is_class.hpp&gt; template &lt;class T&gt; struct hasher {}; template &lt;class T&gt; struct hasher&lt;T*&gt; </p> <blockquote> <p> : boost::is_class&lt;T&gt; </p> </blockquote> <p> {}; template &lt;class T&gt; struct hash_set { </p> <blockquote> <p> hasher&lt;T&gt; hash; </p> </blockquote> <p> }; template &lt;class D&gt; struct base { </p> <blockquote> <p> hash_set&lt;D*&gt; set; </p> </blockquote> <p> }; struct Der </p> <blockquote> <p> : public base&lt;Der&gt; </p> </blockquote> <p> { </p> <blockquote> <p> void foo(); </p> </blockquote> <p> }; int main() { </p> <blockquote> <p> char x[sizeof(&amp;Der::foo) == 16 ? -1 : 1]; </p> </blockquote> <p> } </p> </blockquote> <p> I don't think this is a boost bug - the failing conditions look too much like a compiler-specific bug. Also, this code compiles cleanly on gcc 3.4.2 </p> <p> I'd like to hear your opinion, and forward the bug to Microsoft if it's really their bug. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1828 Trac 1.4.3 anonymous Tue, 15 Apr 2008 08:22:18 GMT <link>https://svn.boost.org/trac10/ticket/1828#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1828#comment:1</guid> <description> <p> Update: the following simple code produces the same bug on VC8. </p> <p> It seems that using this form of SFINAE on an incomplete type makes the compiler remember an inappropriate size for member function pointers. Methinks that implementing is_class in terms of the intrinsic <span class="underline">is_class would solve this problem. </span></p> <blockquote> <p> #include &lt;boost/type_traits/is_class.hpp&gt; struct base; boost::is_class&lt;base&gt; stub; struct base { </p> <blockquote> <p> void foo(); </p> </blockquote> <p> }; int main() { </p> <blockquote> <p> char x[sizeof(&amp;base::foo) == 16 ? -1 : 1]; </p> </blockquote> <p> } </p> </blockquote> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Tue, 15 Apr 2008 08:38:33 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1828#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1828#comment:2</guid> <description> <p> That's strange: builds OK for me with VC8 (and SVN Trunk), what am I missing? </p> <p> Ah... now I see... is_class in trunk has been changed to use the <span class="underline">is_class intrinsic. The code fails as you mention with 1.35.0. </span></p> <p> But... why can't a pointer to member be 16-bytes? If instead of your assert I add: </p> <blockquote> <p> std::cout &lt;&lt; sizeof(&amp;Der::foo) &lt;&lt; std::endl; void (Der::*mp)(); std::cout &lt;&lt; sizeof(mp) &lt;&lt; std::endl; </p> </blockquote> <p> Then both output 16 - really though this should be reserved for pointers to (possibly) virtual functions - I'm not sure why the compiler thinks that might be the case here though... I don't think there's anything in is_class that would trigger that, and is_polymorphic answers false for that type so that's all right. Why does it matter what size the member function pointer is? </p> <p> Ah.. just got your update when trying to post, SVN Trunk already uses <span class="underline">is_class, does this fix things for you? </span></p> <p> John. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Mon, 21 Apr 2008 08:49:01 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/1828#comment:3 https://svn.boost.org/trac10/ticket/1828#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> I'm assuming that this is fixed in Trunk, please reopen if problems re-occur. </p> Ticket