<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Feb 9, 2014 at 12:33 AM, Tony Kelman <span dir="ltr"><<a href="mailto:kelman@berkeley.edu" target="_blank">kelman@berkeley.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm seeing some strange runtime errors that don't occur when the same code is built with g++. I've tried to cut down the class in question and reduce the error to a small test case, and posted the result at <a href="https://gist.github.com/8875125" target="_blank">https://gist.github.com/<u></u>8875125</a><br>
</blockquote>
<br></div>
Following up here. I've found and figured out how to use the absolutely amazing tool C-Reduce (<a href="http://embed.cs.utah.edu/creduce/" target="_blank">http://embed.cs.utah.edu/<u></u>creduce/</a>) which I imagine this list is familiar with. The result is the following:<br>
<br>
<br>
<br>
class A<br>
{<br>
public:<br>
A (const A &);<br>
~A ();<br>
};<br>
<br>
A::A (const A &)<br>
{<br>
}<br>
<br>
A & fn1 ()<br>
{<br>
}<br>
<br>
A::~A ()<br>
{<br>
}<br>
<br>
A a = fn1 ();<br>
int<br>
main ()<br>
{<br>
}<br>
<br>
<br>
<br>
$ g++ -g -o dmtest-g++ dmtest.cxx && ./dmtest-g++<br>
succeeds silently, while<br>
$ clang++ -g -o dmtest-clang dmtest.cxx && ./dmtest-clang<br>
gives a warning "control reaches end of non-void function" during compilation, and a runtime error "Illegal instruction (core dumped)". This comparison was on Ubuntu 13.10 as it was the easiest platform for me to get C-Reduce running on.<br>
<br>
Is this difference in behavior between the two compilers expected and/or intended, or is this a bug in Clang?</blockquote><div><br></div><div>This behavior is intended. Your program exhibits undefined behavior (control falls off the end of a non-void returning function rather than exiting via a return statement with an appropriate object).<br>
<br>Clang provides no guarantees for this code above -O0 (no code is emitted, execution may fall into the following function, etc - nasal demons, etc), but does generously provide an illegal instruction at -O0 so you can find this bug a bit more easily. The warning is also there to help.<br>
<br>In short: make sure you return things from your non-void returning functions. Don't let them fall off the end.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If the former, does anyone have any suggestions for how to translate this back into a workaround for the purposes of the real code that originally ran into this difference?<br></blockquote></div></div></div>