<div dir="ltr">I do agree that asserts are sometimes used improperly.  But who's to say that the bug was the assert, and not the surrounding code?  For example, consider this code:<div><br></div><div>assert(p);</div><div>int x = *p;<br><div><br></div><div>Should this assert also not be here in library code?  I mean it's obvious that the program is about to crash if p is invalid.  Asserts should mean "you're about to invoke undefined behavior", and a crash is *better* than undefined behavior.  It surfaces the problem so that you can't let it slip under the radar, and it also alerts you to the point that the UB is invoked, rather than later.</div></div><div><br></div><div>What about this assert?</div><div><br></div><div>assert(ptr);</div><div>int x = strlen(ptr);</div><div><br></div><div>Surely that assert is ok right?  Do we need to check whether ptr is valid EVERY SINGLE TIME we invoke strlen, or any other function for that matter?  The code would be a disastrous mess.</div><div><br></div><div>If you think you've found an improper assert, the thing to do is raise it on the proper mailing list and present your case of why you think it's an improper assert.  asserting is not inherently wrong, but like anything, you have to use it right.</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Sep 20, 2016 at 1:37 PM Ted Woodward <<a href="mailto:ted.woodward@codeaurora.org">ted.woodward@codeaurora.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br class="gmail_msg">
From: lldb-dev [mailto:<a href="mailto:lldb-dev-bounces@lists.llvm.org" class="gmail_msg" target="_blank">lldb-dev-bounces@lists.llvm.org</a>] On Behalf Of Zachary Turner via lldb-dev<br class="gmail_msg">
Sent: Tuesday, September 20, 2016 12:47 PM<br class="gmail_msg">
<br class="gmail_msg">
> This kind of philisophical debate is probably worthy of a separate thread :)  That being said, I think asserts are typically used in places where the assert firing means "You're going to crash *anyway*"<br class="gmail_msg">
<br class="gmail_msg">
This is emphatically NOT the case.<br class="gmail_msg">
<br class="gmail_msg">
One of the first tasks I was given when I started at Qualcomm was to fix the disassembler for Hexagon. It was a mess - it would assert if the disassembly tables couldn't identify an opcode. Maybe that's fine for an assembler, assert if you can't generate an opcode, but an unidentified opcode should print a warning and move on. It's not a fatal error to disassemble data!<br class="gmail_msg">
<br class="gmail_msg">
There are other instances of this in llvm. I agree with Greg - libraries shouldn't assert.  Send an error back to the caller, and let the caller handle it. A typo in my expression that lldb sends to clang shouldn't crash my debug session.<br class="gmail_msg">
<br class="gmail_msg">
--<br class="gmail_msg">
Qualcomm Innovation Center, Inc.<br class="gmail_msg">
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
</blockquote></div>