<table><tr><td style="">rjvbb added a comment.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D15764">View Revision</a></tr></table><br /><div><div><p><tt style="background: #ebebeb; font-size: 13px;">__builtin_unreachable()</tt> does have strange effects:</p>
<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);">#include <stdio.h>
int foo(int doit)
{
switch(doit) {
case 0:
case 1:
case 2:
return doit;
default:
__builtin_unreachable();
}
}
int main(int argc, char *argv[])
{
fprintf(stderr, "foo(0)=%d\n", foo(0));
foo(1);
foo(2);
fprintf(stderr, "unreachable foo(4)=");
fprintf(stderr, "%d\n", foo(4));
return 0;
}</pre></div>
<p>Depending on how and with what compiler I build this, the program either loops (from the <tt style="background: #ebebeb; font-size: 13px;">foo(4)</tt> call back to the start of <tt style="background: #ebebeb; font-size: 13px;">main</tt>) until it SEGVs, or it terminates after printing <tt style="background: #ebebeb; font-size: 13px;">foo(4)=4</tt></p>
<p>IOW, it looks like it just causes UB in release builds when the assert is removed from Q_UNREACHABLE :-/</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R32 KDevelop</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D15764">https://phabricator.kde.org/D15764</a></div></div><br /><div><strong>To: </strong>rjvbb, KDevelop, aaronpuchert<br /><strong>Cc: </strong>aaronpuchert, kdevelop-devel, glebaccon, antismap, iodelay, vbspam, geetamc, Pilzschaf, akshaydeo, surgenight, arrowd<br /></div>